Information Technology Reference
In-Depth Information
Console .WriteLine( "projecting an element: {0}" , input);
return string .Format( "Delivered {0} at {1}" ,
input.ToString(),
DateTime .Now.ToLongTimeString());
}
Finally, instead of a simple foreach loop, I iterated the results using the
IEnumerator<string> members so that you can see when different actions
take place. This is so that I can more clearly show exactly how the sequence
is generated (in parallel) and enumerated (in this enumeration loop). In
production code, I prefer a different implementation.
var iter = answers.GetEnumerator();
Console .WriteLine( "About to start iterating" );
while (iter.MoveNext())
{
Console .WriteLine( "called MoveNext" );
Console .WriteLine(iter.Current);
}
Using the standard LINQ to Objects implementation, you'll see output
that looks like this:
About to start iterating
testing element: 0
projecting an element: 0
called MoveNext
Delivered 0 at 1:46:08 PM
testing element: 1
testing element: 2
testing element: 3
testing element: 4
testing element: 5
testing element: 6
testing element: 7
testing element: 8
testing element: 9
testing element: 10
projecting an element: 10
called MoveNext
Delivered 10 at 1:46:08 PM
 
Search WWH ::




Custom Search