score:13

Accepted answer

this is an interesting question, i think you can use a workaround like this, instead of using linq get the enumerator and use it:

private void readcsv(ienumerable<string> records)
{
     var enumerator = records.getenumerator();
     enumerator.movenext();
     var headerrecord = enumerator.current;
     var datarecords = getremainingrecords(enumerator);
}

public ienumerable<string> getremainingrecords(ienumerator<string> enumerator)
{
    while (enumerator.movenext())
    {
       if (enumerator.current != null)
            yield return enumerator.current;
    }
}

update: according to your comment here is more extended way of doing this:

public static class customenumerator
{
    private static int _counter = 0;
    private static ienumerator enumerator;
    public static ienumerable<t> getrecords<t>(this ienumerable<t> source)
    {
        if (enumerator == null) enumerator = source.getenumerator();

        if (_counter == 0)
        {
            enumerator.movenext();
            _counter++;
            yield return (t)enumerator.current;
        }
        else
        {
            while (enumerator.movenext())
            {
                yield return (t)enumerator.current;
            }
            _counter = 0;
            enumerator = null;
        }
    } 
}

usage:

private static void readcsv(ienumerable<string> records)
{
     var headerrecord = records.getrecords();
     var datarecords = records.getrecords();
}

score:3

yes, use the ienumerator from the ienumerable, and you can maintain the position across method calls;

a simple example;

public class program
{
    static void main(string[] args)
    {
        int[] arr = new [] {1, 2, 3};
        ienumerator enumerator = arr.getenumerator();
        enumerator.movenext();
        console.writeline(enumerator.current);
        dorest(enumerator);
    }

    static void dorest(ienumerator enumerator)
    {
        while (enumerator.movenext())
            console.writeline(enumerator.current);
    }
}

Related Query

More Query from same tag