Search code examples
c#.nettextreader

How to loop over each line from a TextReader?


Possible Duplicate:
C# Reading a File Line By Line
How to loop over lines from a TextReader?

I am given a .NET TextReader (a class that can read a sequential series of characters). How can I loop over its content by line?


Solution

  • Do you mean something like this?

    string line = null;
    while((line = reader.ReadLine()) != null) 
    {
        // do something with line
    }