Jon Skeet [C# MVP] wrote:
On Nov 5, 10:04 am, cody <deutron...@gmx.dewrote:
>Hi! It's great that Arrays and List<Tsupport functions that use
predicates like TrueForAll(), ConvertAll(), Foreach() and so on.
But why are there no such methods for IEnumerable<T>?
The guidelines say that we should not work with implementations like
List<Tbut instead only with interfaces like IList<Tso theoretically
we never could use this handy methods..
If you defined them in IEnumerable<Tthen *every* implementation
would have to provide code to do this - which would be pretty dire.
Instead, use a static method which takes an IEnumerable<Tand a
predicate, and returns true or false. This is exactly what LINQ does -
except that it provides extension methods to make it *look* like the
method is actually provided by IEnumerable<T>.
Jon
Yes that is what I would have suggested, that for all these predicate
helper methods extension methods should be provided, instead of binding
them to a special implementation like List<Tclass, although *every*
possible collection should be able to benefit of them.
Who do I have to beat to get this cool stuff included into .NET
framework 4.0 :)
public static class EnumerableExtensions
{
public static bool TrueforAll(this IEnumerable<Tenumerable)
{
..
}
..
}