Or if you require random access to the lines, you should read the lines into
an ArrayList and then access them using an index.
ArrayList lines = new ArrayList();
string line;
while ((line = reader.ReadLine()) != null)
lines.Add(line);
string wishedLine = (string) lines[3];
HTH,
Stefan
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Tim Bücker <ti*************@web.de> wrote:
Is there a way to read a specified line in a textfile?
Something like TextReader.ReadTextLine(4);
It seems very odd to use
reader.ReadLine();
reader.ReadLine();
reader.ReadLine();
string wishedLine = reader.ReadLine();
Is there a better way?
Well, you could write:
void SkipLines (TextReader reader, int lines)
{
for (int i=0; i < lines; i++)
{
reader.ReadLine();
}
}
and then do:
SkipLines (reader, 3);
string line = reader.ReadLine();
There's no other way to do it.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too