C# Collection Types
- Non-Generic (System.Collections)
- Generic (System.Collections.Generic)
- Concurrent (System.Collections.Concurrent)
Non-Generic Collection
In C#, non-generic collection classes are useful to store heterogeneous elements, these are provided by System. Collections namespace. This collection presents some classes
ArrayList -> its represent the array, its length is automatically increase
Queue -> its is based on FIFO ( first in first out )
Stack -> its is based on LIFO (Last in first out )
Hashtable -> it is based on the key, value pair
Syntax
Stack stack=new Stack();
it is store value in LIFO order but for any datatype value.
Generic Collection
In C#, generic collection can store only the elements with the same data type, and these are provided by System.Collection.Generic namespace.
List
Stack
Queue
SortedList<K, V>
Dictionary<K, V>
Syntax
List<T> lst = new List<T>();
in this syntax <T>, T represents any datatype
List<int> lst = new List<int>();
int the example list is an integer type, in another word this list is always taken integer value no any other datatype value.
Concurrent Collection
If we are using multiple threads to access a collection concurrently, then we need to use the concurrent collection class,