If you put both checking together, code will escape looping even if ReadLine()
is null before reaching EndOfStream
. Following is a breakdown version but will go through the whole stream.
while (!sr.EndOfStream)
{
if ((line = sr.ReadLine()) != null)
{
//do your work here
}
}