DCSIMG
PowerCollections - Doron's .NET Space

Browse by Tags

All Tags » PowerCollections (RSS)

C# 3.0 New Feature for the Week #4: Extension Methods (and a PowerCollections Bonus!)

Consider the following. You need to sort an IEnumerable<T>. By default, Sort is only available for T[] (arrays) and List<T> (generic list). So you write something like this (probably not the most efficient implementation, this is just an example): namespace Utils { public static class CollectionUtils { public static IEnumerable < T > Sort < T > (IEnumerable < T > collection) { List < T > toSort = new List < T > (collection); toSort.Sort(); return toSort;...

Upgrading to .NET 2.0? PowerCollections to your Aid.

The .NET 2.0 framework has been here a while, but if you're like my team, you're still using a lot of code that you wrote back at the .NET 1.1 days. It's likely that many of these methods are using non-generic collections. This poses an annoying issue. Check out this method: public IList GetAllUsers(IList userCodes) { IList list = new ArrayList(); // Add the users here... // ... return list; } On the one hand, you don't want to touch the older code. It is working, it doesn't have unit-tests, and...