The Compare Contract [Kim Hamilton]

A breaking change? We recently heard from a customer who observed different sorting behavior in .NET FX 3.5 SP1 compared to 3.5 RTM. The different behavior was demonstrated with the following code. The class StringWrapper provided a custom sort in which nulls (null StringWrapper references) were moved to the end of the array. To achieve…


BCL Refresher: List<T> Predicates [Inbar Gazit]

This time I’m going to focus on one class in this blog post. System.Collections.Generic.List<T> contains some special methods that exist on this type. Those methods take a System.Predicate which is essentially a delegate that allows us to filter based on a certain criteria. This means we can selectively carry out operations only on those member…


Non-Generic Collections to be Removed from Silverlight [Inbar Gazit]

Those of you who are already using Silverlight 1.1 Alpha may have seen that the familiar non-generic collections were all marked as obsolete. This includes almost everything under the System.Collections namespace. You shouldn’t be too surprised. We’ve been telling you for a while that you should not be using these anymore and to instead use…


BCL Refresher: Converting the Non-Generic Collections [Inbar Gazit]

As you know generics were only introduced to the .NET Framework in version 2.0. Originally we had a lot of collections in the System.Collections namespace that can store objects. In version 2.0 we added the System.Collections.Generic namespace to support generic collections that can store any specific type. If you have legacy code or even if…


Introducing HashSet<T> [Kim Hamilton]

HashSet<T> is in our latest CTP, and you can find it in the System.Collections.Generic namespace. The naming discussion over the last month has motivated me to recap some naming highlights for HashSet, so hang in til the end if you’re interested. HashSet is an unordered collection containing unique elements. It has the standard collection operations…


Why are NameValueCollection lookups slower than Hashtable? [Kim Hamilton]

An internal discussion came up recently on the performance difference of lookups in Hashtable versus NameValueCollection. Benchmarks revealed that NVC lookups were ~2-8 times slower than Hashtable. For example, when doing 40,000 lookups on a collection size of 100,000, NameValueCollection is about 2.6x worse: NameValueCollection time: 0.050 sec Hashtable time: 0.019 sec This leads to…


Set Collection [Ryan Byington]

So the BCL thinking of implementing a set collection for a future release and we would like to get you our blog reading public opinion on what scenarios are important to you for a Set collection. The collection will likely have the standard ICollection<T> APIs like Add, Remove, Clear, and Count and we would likely…


PowerCollections MSDN TV Broadcast [Krzysztof Cwalina]

Have you heard about PowerCollections? It’s an extension library to the new generic collection classes in the System.Collections.Generic namespace. It contains many advanced collections and a ton of algorithms. You can also watch an MSDN TV broadcast where Peter Golde describes the project details.


Avoiding Boxing in Classes Implementing Generic Interfaces through Reflection [Dave Fetterman]

Krzysztof Cwalina showed me this cool trick to avoid boxing value types when working with generics and interfaces.This may be a bit dense but the trick is rarely seen and illustrative.  Note before proceeding: This technique is only available in VS.NET Whidbey.  For the sake of illustration, suppose in .NET there were a notion of…