November 04, 2004

Often overlooked specialized collections

The lost treasures of .net class library, part I: The System.Collections.Specialized namespace has a few excellent classes that can help you (at least until you get generics, that is). Too bad many coders have never even heard of them. Here's a short introduction:

HybridDictionary and ListDictionary are just perf-tweaked Hashtable implementations. Fine, but not earth-shattering. But it gets better: StringCollection is essentially an typed arraylist, or an flexible-size string array, if you will. StringDictionary is an Hashtable with the key strongly typed as a string. NameValueCollection is excellent for configurations and some other situations (by the way, it's actually used for this purpose by .net).

For some do-it-yourself-spirit, there's also NameObjectCollectionBase, a base class for your own string-keyed typed Hashtables. See the help for an example. And last but not least, CollectionsUtil with static method shortcuts for creating case-insensitive SortedLists and Hashtables.

Posted by Jouni Heikniemi at November 4, 2004 08:25 PM
.net
Comments
Post a comment









Remember personal info?