Search code examples
c#streamreaderreadblock

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


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.


Solution

  • while(!streamReader.EndOfStream)
    {
        string line = streamReader.ReadLine();
        Console.WriteLine(line);
    }
    Console.WriteLine("End of File");