Implémentation de IEnumerator<T>
Bonjour je n'arrive pas a implémenter IEnumerator et je ne comprend pas l'erreur
exemple de msdn
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| public class BoxEnumerator : IEnumerator<Box>
{
private List<Box> _collection;
private int curIndex;
private Box curBox;
public BoxEnumerator(List<Box> collection)
{
_collection = collection;
curIndex = -1;
curBox = default(Box);
}
public bool MoveNext()
{
//Avoids going beyond the end of the collection.
if (++curIndex >= _collection.Count)
{
return false;
}
else
{
// Set current box to next item in collection.
curBox = _collection[curIndex];
}
return true;
}
public void Reset() { curIndex = -1; }
void IDisposable.Dispose() { }
public Box Current
{
get { return curBox; }
}
object IEnumerator.Current
{
get { return Current; }
}
} |
J'ai comme message d'erreur :
Citation:
BoxEnumerator' does not implement interface member 'System.Collections.IEnumerator.Current'. BoxEnumerator.Current' cannot implement 'System.Collections.IEnumerator.Current' because it does not have the matching return type of 'object'.
Citation:
Using the generic type 'System.Collections.Generic.IEnumerator<T>' requires 1 type arguments