Introduction
This article explains collections and their various types with their benefits. We know that a collection is a group of objects and these groups of objects are handled by our programmers. Some of them are ArrayList, HashTable, Stack and Queue. All these collections are designed around a set of defined Interface. Several built-in implementations of these interface, such as ArrayList, HashTable and Queue are provided, that we can use as it is. We can also implement our own collection. The .NET Framework supports the following five types of collections in C#:
- Non-Generic
- Specialized
- Bit-Based
- Generic, and
- Concurrent

Non-Generic Collections
The non-generic collection implements several fundamental data structures, including a dynamic array, stack and queue. They also include dictionaries, in which we can store key/value pairs. This collection operates on data of type object and it can be used to store any type of data, because it stores a reference. These collections are not type safe. The non-generic collection classes and interface are in system.Collections.
Specialized Collections
The specialized collections operate on a specific type of data or operate in a unique way. Like specialized collections for strings. There are also specialized collections that use a single link list. The specialized collection are declared in system.Collections.Specialized.
Bit-based Collections
The collection API defines one bit-based collection called BitArray. BitArray supports bitwise operations on bits, such as AND and XOR. BitArray is declared in system.Collections.
Generic Collections
Generic collections provide us a generic implementation of several standard data structures, such as linked list, stack, queue and dictionary. These collections are generic, they are type-safe. This means that only items are type-compatible with the type of collection can be stored in a generic collection. Generic collections are declared in system.Collections.Generic.
Concurrent Collection
The concurrent collections supports multi-threaded access to a collection. This collection is defined in system.Collections.Concurrent.
Note: There are also several classes in the system.Collections.ObjectModel namespace that supports programmers creating their own generic collections.
All collections support an enumerator including the non-generic interfaces IEnumerator and IEnumerable and the generic interface IEnumerator<T> and IEnumerable<T>. An enumerator provides a standardized way of accessing the element within a collection, one at a time. Because each collection must implement either a generic or non-generic from IEnumerable, the elements of any collection class can be accessed through the method defined by IEnumerator or IEnumerator<T>.
Non-Generic Collections
We have seen the definition and some details about non-generic collections. Now we will see a non-generic interface defined by a set of interfaces and the classes that implement those interfaces. Each of them are described in the following table.
- Non-Generic Interfaces
Interface
Description
ICollection Defines the elements that all non-generic collections must have IComparer Defines the Compare() method that does a comparison on objects stored in a collection IDictionary Defines a collection that consists of key/value pairs IDictionaryEnumerator Defines the enumerator for a collection that implements IDictionary IEnumerable Defines the GetEnumerator() method, that supplies the enumerator for a collection class IEnumerator Provides methods that enable the content of a collection to be obtained one at a time. IEqualityComparer Compares two objects for equality IHashCodeProvider Declared obsolete. Use IEqualityComparer instead. IList Defines a collection that can be accessed via an indexer IStruturalComparable Defines the compareTo() method that is used for structural comparisons IStructuralEquatable Defines the equal() method that is used to determine structural equality. It also defines the GetHashCode() method
- Non-Generic Classes
Class
Description
ArrayList This is a dynamic Array. This array gets resize( grow, shrink) Hashtable A hash table for key/ value pairs Queue First-in-first-out list SortedList A sorted list of key/value pair Stack First-in,last-out list
Bit-based Collections
The BitArray class supports a collection of bits. It stores bits rather then objects, BitArray is different from other collections and supports the basic collection implementing ICollection and IEnumerable. It also implemnts ICloneable.
Specialized Collections
This collection is helpful in the optimization of our work.
|
Specialized Collection |
Description |
| CollectionUtil | Conatains a factory method that creates a collection that stores strings, but ignores case differences |
| HybridDictionary | A collection that uses a ListDictionary to store key/value pairs when there are a few elements in the collection. When the collection grows beyond a certain size, a HashTable is automatically used to store elements |
| ListDictionary | A collection that stores key/value pairs in a linked list. This is recommend only for small collections |
| NamedValueCollection | A sorted collection of key/value pairs in which both the key and value are of type string |
| OrderdDictionary | A collection of key/value pairs that can be indexed |
| StringCollection | A collection optimized for storing a string |
| StringDictionary | A hash table of key/value pairs in which both the key and the value are of type string |
Generic Collections
Generic collections are defined by a set of interfaces and the classes that implement those interfaces.
- Generic Interface
Generic Interface
Description
ICollection<T> Defines the functional features for the generic collections IComparer<T> Defines the generic Compare() method that does a comparison on objects stored in a collection IDictionary<Tkey,Tvalue> Defines a generic collection that consists of key/value pairs IEnumerable<T> Defines the generic GetEnumerator() method, that supplies the enumerator for a collection class IEnumerator<T> Provides methods that enable the content of a collection to be obtained one at a time IEqualityComparer<T> Compares two objects for equality IList<T> Defines a generic collection that can be accessed via an indexer ISet<T> Defines a generic collection that represents a set
- Generic Class
Generic Class
Description
Dictionary<Tkey,Tvalue> Stores key/value pairs, the same as a non-generic HashTable class HashSet<T> Stores a set of unique vlaues using a hash table LinkedList<T> Stores elements in a doubly linked list List<T> Dynamic array, the same as the non-generic ArrayList class Queue<T> A first-in, first-out list, the same as the non-generic Queue class SortedDictionary<Tkey,TValue> Sorted list of key/value pairs SortedList<TKey,TValue> A sorted list of key/value pairs, this is also the same as the non generic SortedList class SortedSet<T> A sorted set Stack<T> A first-in, last-out list, It is the same as the non-generic stack class
Concurrent Collections
This was added in .NET framework 4.0 and have a new namespace called system.Collection.Concurrent. It contains collections that are thread-safe and designed to be used for parallel programming, It means that it is safe to use in a multi-threaded program in which two or more concurrently executing threads might access a collection simultaneously.
|
Concurrent Collection |
Description |
| BlockingCollection<T> | Provides a wrapper for blocking implementation of the IProducerConsumerCollection<T> interface |
| ConcurrentBag<T> | An unordered implementation of the IProducerConsumerCollection<T> interface that works best when a single thread produces and consume the information |
| ConcurrentDictionary<TKey,TValue> | Store a key/value pair, it implements a concurrent dictionary |
| ConcurrentQueue<T> | Implements a concurrent queue, also implements IProducerConsumerCollection<T> |
| ConcurrentStack<T> | Implements a concurrent stack. Implements IProducerConsumerCollection<T> |
Summary
In this article we have covered various types of collections in C#. We have also covered the various types of classes and interface used in collections, with their descriptions.

AUROBINDA TRIPATHYPosted Aug 17, 2023, 2:46 PM
Informative. Well Documented.
IMAD AYOUBPosted Feb 28, 2023, 12:22 PM
Great simple article. Thanks a lot.
Mo BahgatPosted Sep 17, 2020, 5:30 PM
I need help for how to save selected values from listbox (winforms c#) to database using entity framework
Edward AymamiPosted Jul 9, 2019, 2:01 PM
Very helpful but would be really much better if values of ArrayList output example were shown be consumed by a variable rather than printed to a screen. However this is great as it is and I should be able to figure it out as it is, for what I need to do.
Yogesh MhadgutPosted Jun 8, 2019, 12:47 AM
Nice very helpful
Hemalatha SunnapuPosted Nov 17, 2018, 2:26 AM
Is List is similar to ArrayList except specifying type....
Hitanshi MehtaPosted Sep 28, 2018, 3:11 PM
Really nice article
umesh palPosted Sep 20, 2018, 2:07 AM
Spelling is incorrect on above
umesh palPosted Sep 20, 2018, 2:06 AM
DictonaryEntry
Anusree BurmanPosted Aug 21, 2018, 3:04 AM
How to use non-generic queues? Say we want to have both integer and char values in the queue? How do we access them? I tried using object but it doesn't work.
Dharmendra Kumar PanditPosted Aug 9, 2018, 12:46 PM
Very good explanation .......
ajit singhPosted Jun 17, 2018, 9:18 AM
Hi, you have mentioned for Hashtable , DictionaryEntry is a class but it's a Structure.which is as follows-
R Eshwar ReddyPosted May 9, 2018, 5:01 PM
SUPERB...After so many years now concept is very clear .Thanks a lot mate.
Archana.Shagun SrivastavaPosted Apr 20, 2018, 1:48 AM
Concept of collection is clear to me within 15 minute.very helpful artical.thank you very much.Great job sir.
Viral PatvaPosted Feb 4, 2018, 12:12 AM
Thanks for this tutorial..
Salma CmpPosted Aug 6, 2017, 9:15 AM
Thanks a lot , great tutorial
Bhagwant SinghPosted Apr 19, 2017, 12:34 PM
Very nice article that the thing I am looking for
Praveen KumarPosted Dec 18, 2014, 7:58 AM
Very nice Kiranteja Jallepalli !
Manish Kumar ChoudharyPosted Dec 18, 2014, 7:13 AM
Nice one..
Prasanna Kumar MuduliPosted Dec 18, 2014, 1:15 AM
Nice Article...
Dinesh BeniwalPosted Dec 18, 2014, 12:53 AM
Good start kiranteja, Welcome to C# Corner.
Chao HuPosted Dec 18, 2014, 12:26 AM
well down
Jitendra KumarPosted Dec 17, 2014, 11:41 AM
Nice Article..
Deepak VermaPosted Dec 17, 2014, 7:44 AM
Stunning start Kiranteja.