List of All C# Collections. Use the right one.

There are a lot of types of built-in collections in C#:

Array, ArrayList, BitArray, BitVector32, Dictionary<K,V>, HashTable, HybridDictionary, List<T>, NameValueCollection, OrderedDictionary, Queue, Queue<T>, SortedList, Stack, Stack<T>, StringCollection, StringDictionary.

Consider what collection will be the optimal for the specific case. It will likely result in better performance and less room for error. For example if you want to store items as key/value pairs for quick look-up by key, so the best choice will be Generic.Dictionary<TKey, TValue>.  If you want to use items first-in-first-out (FIFO), go on Generic.Queue<T>. If you going to access elements by index frequently, go on System.Array if it’s non-generic Elements, but the best option will be Generic.List<T>, if you store elements of type T only. If you frequent action is access items sequentially, better choose Generic.LinkedList<T>.  There are a lot more considerations. More information can be found here:

My 3 recommendations. Don’t start to write your own collection class, .NET provide a large variety of existing classes, which you can you use or extend. Think about what actions will be applied on Collection more often. And Generic collections are always preferable than  non-generic.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s