C# Collections Tutorial with Examples
C# Collections Tutorial with Examples
Posted By Manisha Gupta
In our previous tutorial, we have learned about how we can use arrays in C#. Let's have a quick overview of it, Arrays in programming are used to group a set of related objects. So one could create an array or a set of Integers, which could be accessed via one variable name.
What is Collections in C#?
Collections are similar to Arrays, it provides a more flexible way of working with a group of objects.
In arrays, you would have noticed that you need to define the number of elements in an array beforehand. This had to be done when the array was declared.
But in a collection, you don't need to define the size of the collection beforehand. You can add elements or even remove elements from the collection at any point of time. This chapter will focus on how we can work with the different collections available in C#.
Collection | Description |
---|---|
ArrayList | The ArrayList collection is similar to the Arrays data type in C#. The biggest difference is the dynamic nature of the array list collection. |
Stack | The stack is a special case collection which represents a last in first out (LIFO) concept |
Queues | The Queue is a special case collection which represents a first in first out concept |
Hashtable | A hash table is a special collection that is used to store key-value items |
SortedList | The SortedList is a collection which stores key-value pairs in the ascending order of key by default. |
BitArray | A bit array is an array of data structure which stores bits |