C# Collections
Last Updated on June 13, 2022C# Collections
In C# the collections can include specialized classes that can store a series of an object and values.
Basically, there are two types of collections in C#:
- Generic Collections: using System.Collections.Generic namespace to include the Generic Collection.
- Non-Generic Collections: using System.Collections namespace to include the Non-Generic Collections.
Non-Generic Collections:
Non-Generic Collection | Short Description |
---|---|
ArrayList | ArrayList can store an object of any type as an array. |
SortedList | SortedList stores key and value pairs. |
Stack | Stack stores the values in LIFO style (Last In First Out). |
Queue | Queue stores the values in FIFO style (First In First Out). |
Hashtable | Hashtable also can store key and value pairs. |
BitArray | BitArray manages a compact array of bit values which is represented like booleans type of value. |
Generic Collections:
Generic Collection | Short Description |
---|---|
List |
Generic List |
Dictionary<TKey, TValue> | Dictionary<TKey,TValue> that contains key-value pairs. |
SortedList<TKey, TValue> | SortedList also can stores key and value pairs which can automatically add the elements in ascending order of key by default. |
Queue |
Queue |
Stack |
Stack |
Hashset |
Hashset |