IEnumerator<T> Implementation
.net, ienumerable
Solution
This:
public List<SomeClass<T>> MyList = new List<SomeClass<T>>();
Needs to be this:
public List<T> MyList = new List<T>();
then, this should work:
public IEnumerator<T> Getenumerator ()
{
foreach (var item in MyList){
yield return item;}
}
You can't have a
List<SomeClass<T>>
that you pull the enumerator for, because you have specified in the interface that the enumerator will return an enumerable item of `<T>`. You can also change `IEnumerable<T>` to be
IEnumerable<SomeClass<T>>
and change the Enumerator to be
public IEnumerator<SomeClass<T>> Getenumerator ()
{
foreach (var item in MyList){
yield return item;}
}
Problem
I have a this code ``` public class SomeClass<T>: IEnumerable<T> { public List<SomeClass<T>> MyList = new List<SomeClass<T>>(); public IEnumerator<T> GetEnumerator() { throw new NotImplementedException(); } } ``` How can I Extract a IEnumerator from MyList ? Thanks StackoverFlower....