Search code examples
c#.netlinqskip

LINQ, Excluding Some Items


I have the following IEnumerable:

var lines = File.ReadLines(this.FileToExtract); // IEnumerable<string>

Now I want to exclude the first 3 lines using linq, What should I do? Thanks.


Solution

  • Use Skip.

    var linesTest = lines.Skip(3);
    

    To take all but last:

    var allButLast = linesTest.Take(linesTest.Count() - 1);