konrad konrad - 17 days ago 8
C# Question

reset enumerator to start for Lumenworks CSV Reader

I am using the CSV Reader from Lumenworks and its great but the

CurrentRecordIndex
value is set only so when I get to the end of the file, and I want to read it again I can't since the current record is set to last item. Is there a way to reset that?

List<object> output = new List<object>();

var col = this.InternalCsv.GetFieldIndex(header);
var e = this.InternalCsv.GetEnumerator();
while (e.MoveNext())
{
output.Add(e.Current[col]);
}

Answer

Did you try IEnumerator.Reset

e.Reset();

Sets the enumerator to its initial position, which is before the first element in the collection.

Or just Get the enumerator again.

var secondEnumerator = this.InternalCsv.GetEnumerator();

Also why you need to enumerate it again when you have the data in the List<object> output = new List<object>(); , use the data in the list !