Check if a StreamReader can read another line

.net, c#, streamreader

Solution

Try using the `Peek` method:

while (reader.Peek() >= 0)
{
    array[i] = reader.ReadLine();
}

Docs: http://msdn.microsoft.com/en-us/library/system.io.streamreader.readline.aspx and http://msdn.microsoft.com/en-us/library/system.io.streamreader.peek.aspx

Problem

I need to check if a line contains a string before I read it, I want to do this using a while loop something like this ``` while(reader.ReadLine() != null) { array[i] = reader.ReadLine(); } ``` This obviously doesen't work, so how can I do this selection?

Original source