In all the examples I see on the CsvReader(link), after reading a record, it is possible to index the CsvReader object itself to retrieve a field's value. For example:
using (CsvReader csv =
new CsvReader(new StreamReader("data.csv"), true))
{
int fieldCount = csv.FieldCount; //Line X
while (csv.ReadNextRecord())
{
for (int i = 0; i < fieldCount; i++)
Console.WriteLine(csv[i])); //Line Y
}
}
Clearly csv is an instance of CsvReader, whatever type that is.
At Line X, if I try to reference csv[i] I get a System.ArgumentOutOfRangeException.
At Line Y, I can access csv[0] etc. What does the [] mean? Is it not indexing an array?
How can I find out the upper bound of csv[i] dynamically as it does not have a Length property?
There is an indexer implemented
This is where the exception comes from
And it is thrown because without calling
ReadNextRecord _fieldCountis equal to 0.