CsvRow Class
Represents a row in a CSV file with access to values by column index or name.
public class CsvRow : IEnumerable<KeyValuePair<string, string?>>, IReadOnlyCollection<KeyValuePair<string, string?>>, IReadOnlyDictionary<string, string?>, IEnumerableExample
using var reader = new StringReader("Name,Age\nJohn,30");
var csvReader = new CsvReader(reader) { HasHeaderRow = true };
var row = await csvReader.ReadRowAsync();
// Access by column name
Assert.Equal("John", row!["Name"]);
// Access by column index
Assert.Equal("30", row[1]);- Implements
Constructors
| Name | Description |
|---|---|
| CsvRow(IReadOnlyList<CsvColumn>?, IReadOnlyList<string>) | Initializes a new instance of the CsvRow class. |
CsvRow(IReadOnlyList<CsvColumn>?, IReadOnlyList<string>)
CsvRow.csInitializes a new instance of the CsvRow class.
protected internal CsvRow(IReadOnlyList<CsvColumn>? columns, IReadOnlyList<string> values)Parameters
columnsIReadOnlyList<CsvColumn>?- The columns of the row, or
nullif the CSV file has no header row. valuesIReadOnlyList<string>- The values of the row.
Properties
| Name | Description |
|---|---|
| Columns | Gets the columns of the row, or null if the CSV file has no header row. |
| System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<System.String,System.String>>.Count | |
| System.Collections.Generic.IReadOnlyDictionary<System.String,System.String>.Keys | |
| System.Collections.Generic.IReadOnlyDictionary<System.String,System.String>.Values | |
| Values | Gets the values of the row. |
Columns
CsvRow.csGets the columns of the row, or null if the CSV file has no header row.
public IReadOnlyList<CsvColumn>? Columns { get; }Property value
System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<System.String,System.String>>.Count
CsvRow.csint IReadOnlyCollection<KeyValuePair<string, string>>.Count { get; }Property value
No documentation is available.
System.Collections.Generic.IReadOnlyDictionary<System.String,System.String>.Keys
CsvRow.csIEnumerable<string> IReadOnlyDictionary<string, string>.Keys { get; }Property value
No documentation is available.
System.Collections.Generic.IReadOnlyDictionary<System.String,System.String>.Values
CsvRow.csIEnumerable<string> IReadOnlyDictionary<string, string>.Values { get; }Property value
No documentation is available.
Values
CsvRow.csIndexers
| Name | Description |
|---|---|
| this[CsvColumn] | Gets the value of the specified column, or null if the row has no value at the column's index. |
| this[int] | Gets the value at the specified column index. |
| this[string] | Gets the value of the column with the specified name. |
| this[string] |
Item overloads
this[CsvColumn]
CsvRow.csGets the value of the specified column, or null if the row has no value at the column's index.
this[int]
CsvRow.csGets the value at the specified column index.
Parameters
indexint- The zero-based index of the column.
Property value
Exceptions
ArgumentOutOfRangeExceptionindexis less than 0 or greater than or equal to the number of values.
this[string]
CsvRow.csGets the value of the column with the specified name.
Parameters
columnNamestring- The name of the column.
Property value
Exceptions
ArgumentNullExceptioncolumnNameisnull.InvalidOperationException- The CSV file has no header row.
this[string]
CsvRow.csMethods
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.String,System.String>>.GetEnumerator()
CsvRow.csIEnumerator<KeyValuePair<string, string?>> IEnumerable<KeyValuePair<string, string>>.GetEnumerator()No documentation is available.