IEnumerable<> and IEnumerable
I've answered this 2x in the past week, so I think it's a worthy point to bring up. When implementing generic interface IEnumerable<>, you'll need to implement both IEnumerable<>.GetEnumerator() and IEnumerable.GetEnumerator() as IEnumerable<> inherits IEnumerable. Otherwise, you'll get the below error message:
'xxx' does not implement interface member 'System.Collections.IEnumerable.GetEnumberator()'. 'xxx' is either static, not public, or has the wrong return type.
As for why IEnumerable<> inherits IEnumerable, the best answer I could come up with is because it can.
So, to sum things up:
using
System.Collections;
using
System.Collections.Generic;
public
class
MyClass
:
IEnumerable
{
public
IEnumerable
GetEnumerator()
{
// Code here
}
public
IEnumerable
GetEnumerator()
{
// Code here
}
}