Is there shorter/nicer way to read input in console as enumerable using standard features of C#/.Net 4.0? I don’t think there is any practical usage of it, more as excercise.
This is what I quickly come up as an answer to homework question about “read array/filter it“. Basically I tried to write console equialent of File.ReadAllLines.
var completeConsoleInput = Enumerable.Repeat(0, int.MaxValue)
.Select(i => Console.ReadLine())
.TakeWhile(s => s != null);
I especially don’t like Enumerable.Repeat(0, int.MaxValue) that I tried to use as “forever” iterator, but I don’t remember seeing other option.
Here is a solution :