I\'ve written a class that implements IEnumerable :
public class MyEnumerable : IEnumerable
{
IEnumerator IEnumerable.GetEnumerator()
{
Sure - just add a Where
method to MyEnumerable
. The Linq Where
method is an extension method, so it's not technically an override. you're "hiding" the linq method.
public class MyEnumerable : IEnumerable
{
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
public IEnumerator GetEnumerator()
{
//Enumerate
}
public MyEnumerable Where()
{
// implement `Where`
}
}
There are some caveats, though:
MyEnumerable
- it will not be called on variables of type IEnumerable
(or any collection that implements it, like List
Where
that will need to be implemented as well if you want to maintain consistently with Linq.