How can I access IEnumerable<T> extension methods on my custom subclass of BindingList<T>?

Posted by Dan on Stack Overflow See other posts from Stack Overflow or by Dan
Published on 2010-12-31T16:41:02Z Indexed on 2010/12/31 16:54 UTC
Read the original article Hit count: 294

Filed under:
|
|

I have a custom subclass of BindingList<T> that I want to execute a LINQ query over using the handy extension methods. For example:

public int GetSum(MyList<T> list)
{
   return list.Sum(x => x.Value);
}

But the compiler complains that it can't resolve Sum because it doesn't recognize list as an IEnumerable<T>, which it obviously is, because this works:

public int GetSum(MyList<T> list)
{
   return ((IEnumerable<T>)list).Sum(x => x.Value);
}

Anyone have a clever way I can avoid the ugly and unecessary cast?

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ