Why a Collection?
- Array size is fixed and cannot be increased dynamically. However, in actual development scenarios, the same type of objects are needed to be processed and added dynamically, and the size of the unit holding the objects should grow or shrink accordingly. This functionality is provided in Collections.
- The insertion and deletion of elements in an array are also costly in terms of performance.
- Also, the way these objects should be stored can be different, there can be a requirement to store the objects sequentially, non-sequentially, sorted order, etc.
- Collections come in handy as a return type in the implementation of business methods, generally, when data is obtained from a file or database, it can be a single or multiple objects. When one is not sure, it is safe to define return type as a collection since it can hold multiple objects. This works even if a single or no object is returned.
Introduction
- A collection is a set of similar types of objects that are grouped together.
- System.Collections namespace contains specialized classes for storing and accessing the data.
- Each collection class defined in .NET has a unique feature.
Collection Interfaces
There are some basic operations that are possible on any collection.
- Search specific objects in the collection.
- Adding or removing objects dynamically in the collection.
- List the objects in the collection by iterating through it. And so on
These basic operations are defined in the form of interfaces. All the collection classes implement these interfaces to get the required functionality. The implementation can be different for different classes. For example, adding objects in an Array is different than adding objects in an ArrayList collection. ArrayList grows and shrinks dynamically. Both the collections need the functionality of iteration using a foreach loop to display the list of objects contained in them.
Types of collections

-
ArraysArray class is defined in System namespace. Arrays can store any type of data but only one type at a time. The size of the array has to be specified at compilation time. Insertion and deletion reduce performance.
-
Advanced CollectionsMany times we can’t give number elements in the list and we need to perform different operations like inserting, deleting, sorting, searching, comparing, and so on. To perform these operations efficiently, the data needs to be organized in a specific way. This gives rise to advanced collections. Advanced collections are found in System.Collections namespace.


Colin FitzGeraldPosted Jun 2, 2019, 9:38 PM
Good article thanks
Rizwan AnsariPosted Sep 21, 2018, 12:23 AM
NiceArticle
Pandurang PailvanPosted Mar 27, 2017, 8:46 AM
Hi Rafnas..Its an very good article and you explained well difference between Collections and generics.