Array.ConvertAll and List<T>.ConvertAll but nothing that works with IEnumerable<T&g

It appears there's an oversight in the design of System.Collections.Generic. Given an instance of an implementation of IList<T>, one cannot use generic algorithms because there is no static class which implements the generic algorithms (things like ForEach, RemoveAll, ConvertAll, etc.) for downlevel generic interfaces.

For example, ForEach could be implemented on an IEnumerable<T>. Similarly, different levels of support for ConvertAll could be implemented for IEnumerable<T> (returning an IEnumerable<U>Wink, ICollection<T> (returning U[] or List<U>, doesn't really matter).

Am I missing something? Should I log this as a bug / suggestion?

[750 byte] By [Barry.Kelly] at [2008-2-15]
# 1
Barry.Kelly wrote:

It appears there's an oversight in the design of System.Collections.Generic. Given an instance of an implementation of IList<T>, one cannot use generic algorithms because there is no static class which implements the generic algorithms (things like ForEach, RemoveAll, ConvertAll, etc.) for downlevel generic interfaces.

For example, ForEach could be implemented on an IEnumerable<T>. Similarly, different levels of support for ConvertAll could be implemented for IEnumerable<T> (returning an IEnumerable<U>Wink, ICollection<T> (returning U[] or List<U>, doesn't really matter).

Am I missing something? Should I log this as a bug / suggestion?


Barry,

It wasn't an oversight, I believe. Usually, for things like this, they leave that to the developer, or third parties (since it is easy to do).

You might want to take a look at the Power Collections for .NET, as it has a much richer collection model (generic), as well as operations on those collections. You can find it at:

http://www.wintellect.com/powercollections/

Hope this helps.

- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

casperOne at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified