When to Use Generic Collections
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Using generic collections is generally recommended, because you gain the immediate benefit of type safety without having to derive from a base collection type and implement type-specific members. Generic collection types also generally perform better than the corresponding nongeneric collection types (and better than types that are derived from nongeneric base collection types) when the collection elements are value types, because with generics there is no need to box the elements.
The following list is a summary of key generic types to use:
Collection<T> is the generic class that can be used as a base class.
The ReadOnlyCollection<T> class is not abstract and has a constructor that makes it easy to expose an existing List<T> as a read-only collection.
The List<T> class allows you to specify your own IComparer<T> generic interface implementations for sorting and searching the list.
LinkedList<T> is a general-purpose linked list that provides O(1) insertion and removal operations.
KeyedCollection<TKey, TItem> is a hybrid between a list and a dictionary, which provides a way to store objects that contain their own keys.
The Dictionary<TKey, TValue> and KeyedCollection<TKey, TItem> classes allow you to specify your own equality comparers.