Tip: Hashtable vs SortedList
I wrote this short tip based in a question made from a workmate about a functionality that he wanted that appears in a Hashtable class.
Remember that a Hashtable represents a collection of key/value pairs that are organized based on the hash code of the key, and when a element is added to the Hashtable it's stored based on the hash code of the key, and the elements don't preserves the order based in their insertion to the Hashtable's "bag". If I want to retrieve the elements in the same order that they were placed, there's no way to retrieve them (normally).
And, if I want a collection class which can add key/value elements, and it maintains all the items sorted based in the insertion order? This class exists and their name is SortedList.
A SortedList is a collection of key/value pairs that is sorted by the keys and are accessible by key and by index.
If you want that the items contained in a collection always be "sorted" you need to use a SortedList instead a HashTable. If you don need the items sorted then use a HashTable, beacuse it's more faster than a SortedList obtaining a value from their "bag".
Updated 01-08-2008
An interesting performance test to compare four different implementations of the IDictionary interface posted by Vladimir Bodurov (IDictionary options - performance test - SortedList vs. SortedDictionary vs. Dictionary vs. Hashtable).