Hello!
In this example I don't have to implement the three method that
GetEnumerator returns. Do you mean that this is the most common situation
that you don't have to implement these three methods?
I didn't fully understood what you meant in the previous answer.
Person[] array =
{
new Person("532513-1234", "Olle", 34),
new Person("123456-4321", "Pelle", 12),
new Person("987654-5678", "Stina", 44)
};
public Form1()
{
IEnumerator iter = array.GetEnumerator();
while (iter.MoveNext())
Console.WriteLine(iter.Current);
...
}
//Tony
"Marc Gravell" <ma**********@gmail.comskrev i meddelandet
news:O3**************@TK2MSFTNGP05.phx.gbl...
I mean in this case I don't have to implement these three methods
because
they are already accessible in the object that is returned from
GetEnumerator.
If you are writing your own iterator, then yes - they must be implemented
(either explicit or implicit implementation is fine).
However, in C# 2 and above, a lot of this is done for you via "yield
return"; this makes creating iterators very painless.
Marc