I'm trying to write my own (simple) implementation of List. This is what I did so far:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace provaIEnum
{
class MyList<T> : IEnumerable<T>
{
private T[] _array;
public int Count { get; private set; }
public MyList() { /* ... */ }
public void Add(T element) { /* ... */ }
// ...
public IEnumerator<T> GetEnumerator()
{
for (int i = 0; i < Count; i++)
yield return _array[i];
}
}
I'm getting an error about GetEnumerator though:
'provaIEnum.Lista' does not implement interface member
'System.Collections.IEnumerable.GetEnumerator()'.
'provaIEnum.Lista.GetEnumerator()' cannot implement
'System.Collections.IEnumerable.GetEnumerator()' because it does not
have the matching return type of 'System.Collections.IEnumerator'.
I'm not sure if I understand what VS's trying to tell me and I have no idea how to fix it.
Thanks for your time
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…