The reason why Collection, ReadOnlyCollection, and KeyedCollection were moved to System.Collections.ObjectModel namespace

Several people asked me why Collection<T>, ReadOnlyCollection<T>, and KeyedCollection<TKey,TValue> were moved to System.Collections.ObjectModel namespace. Here are the two main reasons: 1.      Microsoft.VisualBasic namespace contains a non-generic type called Collection. The namespace is imported by default by the VB project template and we were afraid that it would confuse developers who import System.Collections.Generic namespace as well…

32

The reason why IEnumerator extens IDisposable

Lot’s of people asked me why IEnumerator<T> extends IDisposable. We did this to support some obscure, yet important scenarios where an enumerator enumerates database rows, or files in a directory, etc. In such cases, the enumerator usually opens some connection or a handle, which then needs to be closed at the end of the enumeration….

7

Power Collections on GotDotNet Featured Sites

I just noticed that the Power Collections project made it to the “Featured Sites” on GotDotNet. See http://www.gotdotnet.com/content/featuredsite/powercollections/default.aspx   For those who don’t know, Power Collections is a community open source library of advanced collection classes and algorithms. The project is co-sponsored by Microsoft. It has generated lots of good APIs (you can download a…

1

IComaprer & IComparable Refactoring Proposal

We are exploring the possiblility of changing the design of IComparer<T> and IComparable<T> interfaces that will ship with Whidbey. This post describes some more detail on the issues we are trying to address with the design change and we are looking for feedback on the proposal. Background The first version of the .NET Framework had…

23

System.Collections.Generic Dictionary Capacity, Hashing, and Collisions.

Somebody asked me a question how to set the initial capacity of System.Collections.Generic.Dictionary<K,V> if one knows that the Dictionary will contain 1000 entries.   The short answer   Dictionary<int,string> numbers = new Dictionary<int,string>(1000);   The long answer   Dictionary<K,V> is a generic type almost identical to the non-generic System.Collections.Hashtable. Both types are implemented as hashtables,…

7

Delegate-Based APIs

Generics and Anonymous Methods/Delegates make up a powerful pair that can be used to create elegant query APIs. Here are some that we just added to the .NET Framework’s Collection libraries. I used List<T> to illustrate the APIs but most of those were also added to System.Array. API Design Delegates namespace System {    public…

39