.NET 2.0 Generic Collections to 1.0 and 1.1 Collections
22 October 2007I am always looking around for the Generic equivalents for the non-generic collections. Especially when converting 1.1 code over to 2.0
| Non-Generic (1.x) | Generic Replacements (2.0+) |
| ArrayList | List<T> |
| CollectionBase | Collection<T> |
| Comparer | Comparer<T> |
| CompatibleComparer | Comparer<T> |
| DictionaryBase | KeyedCollection<TKey,TItem> |
| Hashtable | Dictionary<TKey,TValue> |
| ICollection | ICollection<T> |
| IDictionary | IDictionary<TKey,TValue> |
| IList | IList<T> |
| Queue | Queue<T> |
| ReadOnlyCollectionBase | ReadOnlyCollection<T> |
| SortedList | SortedList<TKey, TValue> |
| Stack | Stack<T> |
Performance
List<T> : a List<T> uses an underlying array that maintains order, thus inserting and removing from this object can take a variable amount of time.
Dictionary<TKey,TValue> : a Dictionary<TKey,TValue> is generally average with add, remove, and contains, even when it contains a large set of data.
SortedDictionary<Tkey,TValue> : SortedDictionary<Tkey,TValue> uses a balanced tree as the underlying implementation. This can provide you with fast lookups, but inserting will more than likely be slower.
SortedList<TKey,TValue> : SortedList<TKey,TValue> uses two separate arrays to store the data, both in order.
No comments yet
Leave a Reply
You must be logged in to post a comment.
