Introduction :
In this blog we can see what is generic collections in c#.
What is Generic Collection in C#?
A generic collection is highly typed (it can only hold one type of object) to reduce runtime type mismatches and to increase speed by avoiding boxing and unboxing.
Generic collections in C# require strong typing for all of the elements that are stored in the collection. Here are a few typical C# generic collections:
- List<T>
- Stack<T>
- Queue<T>
- Dictionary<TKey, TValue>
- SortedDictionary<TKey, TValue>
- HashSet<T>
- LinkedList<T>
List<T>:
It is a dynamic array with capabilities comparable to those of the non-generic ArrayList class.List<T> automatically resizes as elements are added or removed, making it an efficient collection for changing data sets.
Stack<T>:
It has functionality akin to that of the non-generic Stack class and is a first-in, last-out list.A stack can be used to reverse the order of elements, or to implement undo functionality in a program.
Queue<T> :
A stack can be used in a programme to implement undo functionality or to change the order of items.A queue can be used to implement a task queue or to implement a breadth-first search algorithm.
Dictionary<TKey, TValue> :
Similar functionality to that of the non-generic Hashtable class is provided, and it holds key-value pairs.Dictionary<TKey, TValue> is ideal for lookups where the key is used to index the data.
SortedDictionary<TKey, TValue> :
It has comparable functionality to the non-generic SortedList class and is a sorted list of key/value pairs.SortedDictionary<TKey, TValue> can be used to implement a dictionary with a defined sort order, or to sort elements by key.
HashSet<T> :
It is an unorganised grouping of the distinctive components. It prevents the addition of duplicate items to the collection.HashSet<T> can be used to implement a set of elements, or to eliminate duplicates from a collection.
LinkedList<T> :
It enables quick element insertion and removal. It employs the conventional linked list.
For any Help or Queries Contact us on info@crmonce.com or +918096556344