That's neat. You could do:
foreach (string line in
File.ReadLines(fileName).Skip(3000).Take(2000))
However, it still has to read the lines up to 3000, it can't actually
skip anything.
Technically, I would assume you are correct. It will still have to read
through, but it could still be more efficient, as it rips through bytes
looking for return chars rather than turning them into text as it would
with ReadLine(). From my experience, the longer you stay in the binary
world, the faster most operations are.
NOTE: I have not reflected up the .NET 4.0 base classes from IL so I am
not sure what is actually going on. It is just my assumption that the
conversion to actual strings would be deferred for perf.
From the standpoint of the OP, it would be more maintainable and easier
to read code, so there is still a benefit, even if it has to read
through the large file.
Peace and Grace,
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
Twitter: @gbworld
Blog:
http://gregorybeamer.spaces.live.com
*******************************************
| Think outside the box! |
*******************************************