FieldCount
public int FieldCount { get; }The number of fields of the record.
Class in CsvHelper
A record read without a record type, by GetRecords<dynamic>(): its fields are members named after the header (record.Name), or Field1, Field2 and so on without a header. It is also a read-only dictionary of the values by name, and parses them with Parse.
net10.0, netstandard2.1, netstandard2.0
public sealed class CsvDynamicRecord : IDynamicMetaObjectProvider, IReadOnlyDictionary<string, string?>, IEnumerable<KeyValuePair<string, string?>>, IEnumerable, IReadOnlyCollection<KeyValuePair<string, string?>>net47
public sealed class CsvDynamicRecord : IDynamicMetaObjectProvider, IReadOnlyDictionary<string, string?>, IReadOnlyCollection<KeyValuePair<string, string?>>, IEnumerable<KeyValuePair<string, string?>>, IEnumerableCsvHelperCsvHelper.dllA record holds the bytes of its fields, not strings: a value becomes a string when it is read, each time it is read, so the fields you never read cost nothing more. The values are strings (null for one of the reader's CsvReaderOptions.NullValues); Parse, such as record.Parse<int>("Count"), parses them as the reader's CsvReader.Parse<T>(int) does.
The records of a reader share its schema, so record.Name is bound once to the column's index, and later reads of it, on any record of the same header, go straight to the field. A column takes precedence over a member of this class with the same name: with a column FieldCount, record.FieldCount is its value.
Records keep their bytes in blocks shared with the records read after them (or, for input in a byte array, in the input itself), so keeping one record keeps its block in memory; Detach makes a copy that holds only its own bytes. Records do not change, so they can be used on any thread.
public int FieldCount { get; }The number of fields of the record.
public IReadOnlyList<string> Names { get; }The names of the columns: the header names, or Field1, Field2 and so on for each field of the record when the input has no header.
public string? this[int index] { get; }Gets field index as a string, or null when it is one of the reader's CsvReaderOptions.NullValues. A field past the end of the record reads as empty, unless the reader's CsvReaderOptions.MissingField is CsvMissingFieldHandling.Throw.
indexintindex is negative.public string? this[string name] { get; }Gets the field of the column called name. See this[int].
namestringname is null.public bool ContainsKey(string name)Whether the record has a column called name.
namestringtrue when the header has the column (without a header, when the record has the field).name is null.public CsvDynamicRecord Detach()Makes a copy of the record that holds only its own bytes, for a record that you keep while dropping the others: a record read from a stream or a file keeps its whole block of records in memory, and one read from a byte array keeps the array.
public IEnumerator<KeyValuePair<string, string?>> GetEnumerator()The names and values of the columns, in column order: each name once, with its first column.
public ReadOnlySpan<byte> GetSpan(int index)Gets field index as UTF-8 bytes, decoded (without quotes or escape characters).
indexintindex is negative.net10.0
public T Parse<T>(string name) where T : ISpanParsable<T>Parses the field of the column called name as T, with the reader's format provider and its CsvReaderOptions.TrueValues and CsvReaderOptions.FalseValues, as CsvReader.Parse<T>(int) does.
Tnamestringname is null.T.T.T is not one of the built-in types of CsvReader.Parse<T>(int).netstandard2.1, netstandard2.0, net47
public T Parse<T>(string name)Parses the field of the column called name as T, with the reader's format provider and its CsvReaderOptions.TrueValues and CsvReaderOptions.FalseValues, as CsvReader.Parse<T>(int) does.
Tnamestringname is null.T.T.T is not one of the built-in types of CsvReader.Parse<T>(int).public Dictionary<string, string?> ToDictionary()Copies the values into a new dictionary, which you can change, keyed by column name.
public override string ToString()The names and values of the record, such as Name: Ann, Count: 3, for debugging.
public bool TryGetValue(string name, out string? value)Gets the field of the column called name, if there is one. See this[int].
namestringvaluestring?null when there is no such column.name is null.