Collection Classes in C#
In this article we will discuss about what is Collection Classes in details.
Collection Classes are used to store the different kinds of values. There are two types of Collection Classes:
- Generic Collection Classes
- Non-Generic Collection Classes
Generally, we use Array to store multiple values but Array size is not auto incremented and we can store same type of values also an, Array does not have any particular mechanism for inserting and retrieving the element of the collection. So, we use Collection Classes to serve as a Collection of different Type. These Classes resides in System.Collections namespace.
Some of the most important Collections Classes are:
||It provides Collection similar to array, but difference is its size changes dynamically as the number of element chances in it.
||This Collection Class works on Last In First Out (LIFO) principle .i.e. last inserted item will be the first item to be removed.
||This Collection Class works on First In First Out (FIFO) principle i.e. First inserted item will be the first item to be removed.
||It provides a Collection of Key-Value pairs and on the basis of key we can get another value.
||It provides a Collection of Key-Value pairs where the item are sorted according to the key.
All the above Classes implement the ICollection Interface, which contains three properties and one method:
- The Count property returns the number of elements in the collection.
- The IsSynchronized property returns a boolean value depending on whether access to the collection is thread-sage or not.
- The SyncRoot property returns an object that can be used to maintain the synchronization to the access to the Collections.
- The CopyTo() method copies the elements of the Collection to the array.
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here