|
Listing 14-44 extracted from chapter Unsafe code, exceptions, anonymous methods, iterators
Listing 14-43< > Listing 14-45
This listing can be compiled with the command line: csc.exe /target:exe Example_14_44.cs Errors: 0 Warnings: 0
Example_14_44.cs
class Foo {
public System.Collections.Generic.IEnumerable<int> AnIterator() {
for ( int i = 0; i < 5; i++ ) {
if( i == 3 ) yield break;
yield return i;
}
}
}
class Program {
static void Main() {
Foo collec = new Foo();
foreach ( int i in collec.AnIterator() )
System.Console.WriteLine( i );
}
}
Copyright Patrick Smacchia 2006 2007
|