I don't think I understand IEnumerable
and have done several google search.
I'm supposed to make an Container of some objects, where the class Container
should handle the updating of the collection the Container represent (add, remove).
the collection Container
should be and instance of IEnumerable<element>
.
namespace ....
{
public class Container : Ienumerable<Elements>
{
List<Elements> _elm = new List<Elements>();
List<Elements> _add = new List<Elements>();
List<Elements> _rem = new List<Elements>();
public voic PendAdd(Element elm)
{
_add.Add(elm);
}
public voic Pendrem(Element elm)
{
_rem.remove(elm);
}
...
public IEnumerator<Element> GetEnumerator()
{
return _elm.GetEnumerator();
}
}
}
My problem is that IEnumerable<Elements>
is an abstract type and if i make _elm
this type i can't handle the state of the Container
even if i make it
IEnumerable<Element> _elm = new List<Element> ();
VS complains about the error:
'Container' does not implement interface member 'IEnumerable.GetEnumerator()'. 'Container.GetEnumerator()' cannot implement 'IEnumerable.GetEnumerator()' because it does not have the matching return of 'IEnumerator'.
I know that there are several answers about IEnumerable but they do not help me.