1
I’m creating an iterator class - has support for foreach
- implementing the interface IEnumerable<T>
package System.Collections.Generic
, as in the code below:
public class MyList<T> : IEnumerable<T> {
private T[] list;
// Código...
public IEnumerator<T> GetEnumerator() {
for (int index = 0; index < this.list.Length; i++) {
yield return this.list[index];
}
}
}
The problem is that the compiler is generating the following error:
error CS0738: "MyList<T>" não implementa membro de interface "IEnumerable.GetEnumerator()
". "MyList<T>.GetEnumerator()" não pode implementar "IEnumerable.GetEnumerator()" porqu não tem o tipo de retorno correspondente de "IEnumerator".
What’s wrong with the code? What am I doing wrong? I have revised the code several times and apparently the implementation is in accordance with the documentation.
https://stackoverflow.com/questions/8760322/troubles-implementing-ienumerablet
– Raizant
Related: https://answall.com/q/479755/69296
– Luiz Felipe