3

I've Googled and looked at several answers but I haven't found a solution for this: I have a .txt file that is comprised of more than int.max number of lines. How do I read a specific line whose number is > int.max? I found this question which has an answer listed as being able to

string line = File.ReadLines(FileName).Skip(14).Take(1).First();

But unfortunately the .Skip() extension method does not accept Long (or in my needed case ULong) parameters.

So I started looking to overload the .Skip extension (or more accurately make my own) to accept a ULong and found this Which didn't help me either as it pertains to Linq to entities.

Please can someone help me understand how to read a specific line from a text file where the line number is > int32.Max

Thanks

Community
  • 1
  • 1
MegaMark
  • 600
  • 8
  • 26
  • How much larger are we talking? Can you split the file in to chunks that are < int.max and do some math to get where you need to be in the 2nd, 3rd etc chunk? – mjw Aug 13 '15 at 19:57
  • @mjw yes I'm sure I could do that... I was hoping not to have to. – MegaMark Aug 13 '15 at 20:00

1 Answers1

6

You can write your own Skip as an extension method

public static IEnumerable<T> MySkip<T>(this IEnumerable<T> list, ulong n)
{
    ulong i = 0;
    foreach(var item in list)
    {
        if (i++ < n) continue;
        yield return item;
    }
}
L.B
  • 114,136
  • 19
  • 178
  • 224
Eser
  • 12,346
  • 1
  • 22
  • 32