Skip the foreach and manually use the enumerable and enumerator for a 'yield' IEnumerable
using System;
using System.Collections.Generic;
class LetterCollection
{
string[] letters ={ "A", "B", "C"};
public IEnumerable<string> Forward()
{
for (int i = 0; i < letters.Length; i++)
yield return letters[i];
}
}
class MainClass
{
static void Main()
{
LetterCollection cc = new LetterCollection();
IEnumerable<string> ieable = cc.Forward();
IEnumerator<string> ieator = ieable.GetEnumerator();
while (ieator.MoveNext())
Console.Write("{0} ", ieator.Current);
}
}
Output A B C
|
HTML code for linking to this page:
Related in same category :
-
-
-
|