![]() | ![]() |
Collections are special data structures that store data in a specific format. The collections are stored in System.Collections namespace. All the collection classes inherit IEnumerator, IEnumerable and ICollection interfaces. The IEnumerator interface allows iteration over items in the collections The IEnumerable interface is used to return the next item in the collection and the ICollections interface define general collection functions such as size definition etc.
Following are the most commonly used classes in the System.Collections namespace:
An ArrayList collection is similar to the basic C# array. However, in case of ArrayList, you don’t have to specify the size of the ArrayList.
SortedList stores item in the form of key and value pairs and by default sorts the item in ascending order of the keys.
A Stock follows principle of LIFO( Last in, First Out). The item inserted last will be removed first. The Stack has a method Push() which pushes the item on top of the stack. Similarly, it has a method Pop() which removes the data from the top of the stack.
A queue follows the principle of FIFO where the item inserted first is removed first.
In this chapter, we will see these collections in detail.