Implement IEnumerator <T>
5 answers
It:
public List<SomeClass<T>> MyList = new List<SomeClass<T>>();
The following is required:
public List<T> MyList = new List<T>();
then this should work:
public IEnumerator<T> Getenumerator ()
{
foreach (var item in MyList){
yield return item;}
}
You cannot have
List<SomeClass<T>>
to which you pull the enumerator, because you specified in the interface that the enumerator will return an enumerated element <T>. You can also change IEnumerable<T>to
IEnumerable<SomeClass<T>>
and change the Enumerator to
public IEnumerator<SomeClass<T>> Getenumerator ()
{
foreach (var item in MyList){
yield return item;}
}
+8
,
MyNamespace.MyClass<T>' does not implement interface
member 'System.Collections.IEnumerable.GetEnumerator()'.
'WindowsFormsApplication1.SomeClass<T>.GetEnumerator()' cannot implement
'System.Collections.IEnumerable.GetEnumerator()' because it does not have
the matching return type of 'System.Collections.IEnumerator'.
GetEnumerator():
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
IEnumerable<T> IEnumerable, GetEnumerator().
0