Total Page Preview: 000000031633
What is Collections in C#(sharp) ?
C#(sharp) Collections are data structures that holds data in different ways for flexible operations. C# Collection classes are defined as part of the System.Collections or System.Collections.Generic namespace
Type of Collection:
1. System.Collections.Generic classes
2. System.Collections.Concurrent classes
3. System.Collections classes
1: System.Collections.Generic Classes:
We can create a generic collection by using one of the classes in the System.Collections.Generic namespace. A generic collection is useful when every item in the collection has the same data type.A generic collection enforces strong typing by allowing only the desired data type to be added.
Type of Generic Class
1. Dictionary<TKey, TValue> :- Represents a collection of key/value pairs that are organized based on the key.
2. List<T>:- Represents a list of objects that can be accessed by index. Provides methods to search, sort, and modify lists.
3. Queue<T> : - Represents a first in, first out (FIFO) collection of objects.
4. SortedList<TKey, TValue> :- Represents a collection of key/value pairs that are sorted by key based on the associated IComparer<T> implementation.
5. Stack<T> : - Represents a last in, first out (LIFO) collection of objects.
2: System.Collections.Concurrent Classes :
Concurrent collections in .NET Framework 4.0 allow the developers to create type safe as well as thread safe collections. These collection classes form an essential part of the parallel programming feature and are available under the namespace System.Collections.Concurrent. Below are the different types of concurrent collections
Type of Concurrent Class
1. ConcurrentDictionary< Key , Value>: Thread safe dictionary in key value pairs
2. ConcurrentQueue<T>: Thread safe FIFO data structure
3. ConcurrentStack<T>: Thread safe LIFO data structure
4. ConcurrentBag<T>: Thread safe implementation of an unordered collection
5. BlockingCollection<T>: Provides a Classical Producer Consumer pattern
3: System.Collections classes :
The classes in the System.Collections namespace do not store elements as specifically typed objects, but as objects of type Object.
Type of Collections Class
1. ArrayList : Represents an array of objects whose size is dynamically increased as required.
2. Hashtable: Represents a collection of key/value pairs that are organized based on the hash code of the key.
3. Queue : Represents a first in, first out (FIFO) collection of objects.
4. Stack : Represents a last in, first out (LIFO) collection of objects.
Thanks!
Thank You
About Author
Brijesh Kumar
Database Developer
I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL
Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall
and Database Migration On-Premise to Azure Cloud.
LinkedIn : https://www.linkedin.com