Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to loop over lines from a TextReader?

How do I loop over lines from a TextReader source?

I tried

foreach (var line in source)

But got the error

foreach statement cannot operate on variables of type 'System.IO.TextReader' because 'System.IO.TextReader' does not contain a public definition for 'GetEnumerator'

like image 580
Colonel Panic Avatar asked Oct 02 '12 09:10

Colonel Panic


1 Answers

string line;
while ((line = myTextReader.ReadLine()) != null)
{
    DoSomethingWith(line);
}
like image 90
Rawling Avatar answered Sep 28 '22 04:09

Rawling