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'
You can use
File.ReadLines
which is deferred execution method, then loop thru lines:More information:
http://msdn.microsoft.com/en-us/library/dd383503.aspx
You can try with this code - based on
ReadLine method