Collections standardize the way of which the objects are handled by your program. In other words, it contains a set of classes to contain elements in a generalized manner. With the help of collections, the user can perform several operations on objects like the store, update, delete, retrieve, search, sort etc.
C# divide collection in several classes, some of the common classes are shown below:
Generic collection in C# is defined in
System.Collection.Generic namespace. It provides a generic implementation of standard data structure like linked lists, stacks, queues, and dictionaries. These collections are type-safe because they are generic means only those items that are type-compatible with the type of the collection can be stored in a generic collection, it eliminates accidental type mismatches. Generic collections are defined by the set of interfaces and classes. Below table contains the frequently used classes of the
|Dictionary<TKey,TValue>||It stores key/value pairs and provides functionality similar to that found in the non-generic Hashtable class.|
|List<T>||It is a dynamic array that provides functionality similar to that found in the non-generic ArrayList class.|
|Queue<T>||A first-in, first-out list and provides functionality similar to that found in the non-generic Queue class.|
|SortedList<T>||It is a sorted list of key/value pairs and provides functionality similar to that found in the non-generic SortedList class.|
|Stack<T>||It is a first-in, last-out list and provides functionality similar to that found in the non-generic Stack class.|
|HashSet<T>||It is an unordered collection of the unique elements. It prevent duplicates from being inserted in the collection.|
|LinkedList<T>||It allows fast inserting and removing of elements. It implements a classic linked list.|
15 18 21 24 27
Non-Generic collection in C# is defined in
System.Collections namespace. It is a general-purpose data structure that works on object references, so it can handle any type of object, but not in a safe-type manner. Non-generic collections are defined by the set of interfaces and classes. Below table contains the frequently used classes of the
|ArrayList||It is a dynamic array means the size of the array is not fixed, it can increase and decrease at runtime.|
|Hashtable||It represents a collection of key-and-value pairs that are organized based on the hash code of the key.|
|Queue||It represents a first-in, first out collection of objects. It is used when you need a first-in, first-out access of items.|
|Stack||It is a linear data structure. It follows LIFO(Last In, First Out) pattern for Input/output.|
|ArrayList||It represents an ordered collection of an object that can be indexed individually.|
Total number of elements present in the Queue are: 5 Beginning Item is: C#
Note: C# also provides some specialized collection that is optimized to work on a specific type of data type and the specialized collection are found in
It came in
.NET Framework Version 4 and onwards. It provides various threads-safe collection classes that are used in the place of the corresponding types in the
System.Collections.Generic namespaces, when multiple threads are accessing the collection simultaneously. The classes present in this collection are:
|BlockingCollection||It provides blocking and bounding capabilities for thread-safe collections that implement
|ConcurrentBag||It represents a thread-safe, an unordered collection of objects.|
|ConcurrentDictionary||It represents a thread-safe collection of key/value pairs that can be accessed by multiple threads concurrently.|
|ConcurrentQueue||It represents a thread-safe first in-first out (FIFO) collection.|
|ConcurrentStack||It represents a thread-safe last in-first out (LIFO) collection.|
|OrderablePartitioner||It represents a particular manner of splitting an orderable data source into multiple partitions.|
|Partitioner||It provides common partitioning strategies for arrays, lists, and enumerables.|
|Partitioner||It represents a particular manner of splitting a data source into multiple partitions.|
- How to set the Size of the FlowLayoutPanel in C#?
- How to set the Auto Size Mode of FlowLayoutPanel in C#?
- How to set Font in FlowLayoutPanel in C#?
- How to set the Location of the FlowLayoutPanel in C#?
- How to set a Check Box in the DateTimePicker in C#?
- How to style the Border of the FlowLayoutPanel in C#?
- How to set the Name of FlowLayoutPanel in C#?
- How to Style the Border of the RichTextBox in C#?
- How to set the Visibility of the FlowLayoutPanel in C#?
- How to set the Flow Direction of FlowLayoutPanel in C#?
- How to set the Size of the RichTextBox in C#?
- How to set Up and Down Button in DateTimePicker in C#?
- How to set Foreground Color of FlowLayoutPanel in C#?
- How to set Background Color of the FlowLayoutPanel in C#?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.