Like Sergey said, you'll have to read all of the lines, at least until you've read what you wanted.
However, you can use Linq to make it pretty easy:
List<int> myLineNumbers = new List<int>{26, 30};
IEnumerable<string> justMyLines = File.ReadLines("pathFileName").Where((text, lineNum) => myLineNumbers.Contains(lineNum));
If you have a large number of values in
myLineNumbers
, then, instead of
List<int>
, using a
HashSet<int>
or
BitArray
would be more efficient.