COLLECTIONS IN C#
COLLECTIONS IN C#
ARRAY COLLECTION
Cannot be resized at run-time. Can be resized at run-time.
The individual elements are of the The individual elements can be of
same data type. different data types.
We can never insert a value into a We can insert a value into a middle of a
middle of an array. collection.
We can never delete a value from We can delete a value from a middle of
a middle of an array. a collection.
A Collection is a set of related data that may not necessarily belong to the
same data type that can be set or modified dynamically at run-time.
In other words, collection is a dynamic array.
o Its Length can increase on runtime. AUTO RESIZING
o
Normal Array’s length is fixed, it means we cannot change the length after
declaring an array.
Array.Resize()
Resize method of an array destroys old array and create a new array with
new length.
We can never insert a value into a middle of an array, because if we want to
do this then array length should be increased but we cannot increase the
length of an array after declaring the length of an array.
We can never delete a value from a middle of an array.
Accessing collections is similar to accessing arrays, where elements are
accessed by their index numbers. However, there are differences between
arrays and collections in C#.
Collections were introduced in C# 1.0
We have two kinds of Collections.
o Non-Generic collections
Stack, ArrayList, Hashtable, SortedList etc.
System.Collections namespace have non-generic
collections.
o Generic collections.
List<T>, LinkedList<T>, Queue<T>,SortedList<T,V>.
System.Collections.Generic namespace have generic
collections.