I have a code:
public sealed class Sequence : IEnumerable<MyClass>
{
List<MyClass> _elements;
public IEnumerator<MyClass> Getenumerator()
{
foreach (var item in _elements)
{
yield return item;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return this._elements.GetEnumerator();
}
}
// ....
Sequence s = new Sequence();
// ...
// filling s with some data
// ...
foreach(MyClass c in s)
{
// some action
}
That code doesn't want to compile. It DOESNT want to compile. Using the generic type 'System.Collections.Generic.IEnumerator' requires '1' type arguments
Help me to rewrite MyClass to support enumeration.
I tried several combinations, used Google. Everywhere examples of Enumerable and IEnumerator without generics.