How can I tell when I've reached the end of the file when using the ReadBlock method in C#?

abw333 picture abw333 · Jun 23, 2011 · Viewed 52.5k times · Source

I noticed that it will keep returning the same read characters over and over, but I was wondering if there was a more elegant way.

Answer

harryovers picture harryovers · Jun 23, 2011
while(!streamReader.EndOfStream)
{
    string line = streamReader.ReadLine();
    Console.WriteLine(line);
}
Console.WriteLine("End of File");