Array

Array is a group of similar data type which is fixed in size. Under array there is no process of boxing and unboxing because Array is Strongly typed.

Example:

  1. int[]A=new int[6]={1,2,3,4,5,6}  
  2. for(int i=0;i<6;i++)  
  3. console.write=A[i];  
In above example, array type is int and the name of the array is A which is displaying all the values of array A: 1,2,3,4,5,6.

Generally a developer prefer to use Array because there is no boxing and unboxing. Suppose there is one School and the principal of school would like to know only the name of the student of branch CSE, so it is better to use an array because we know how many students are there in CSE branch and also we know that the type of Student Name is string.

String[]Student_Name=new String[60]{‘ Amit’……….’Sandep’}

This will contain only Student Name. There are the following three types of Array: 
  1. Single Dimensional Array
  2. Multi-Dimensional Array
  3. Jagged Array

Collection

Collection is a group of homogenous and heterogeneous data type. Size of Array is not fixed and also Collection is not strong type. We use Generic to make Collection as Strong type. In C# we use namespace System.Collection.Generic to implement Generic on Collection.

Syntax of Collection

Collection<data type>Name =new <data type>();

Generally we use Collection when there is Heterogeneous data type object. Suppose there is one School and the principal of the school would like to know Student Id, Student Name and Course Name of student of Branch CSE, so it is better to use Collection because we have to display the data of Heterogeneous data type object. Like,

  1. Collection<int>Student_Id=new int();  
  2. Collection<string>Student_Name=new String();  
  3. Collection <string>Course=new string();  
Recap

Array is a group of homogeneous data type object which is fixed in size and this is strongly typed. Collection is a group of homogeneous and heterogeneous data type object which is not fixed in size and thus is not strongly typed. But we use Generic to make Collection as strong Type.

Difference between Array and Collection:
 
Array Collection
1. Array is Group of Homogeneous data type object. 1. Collection is Group of Homogeneous and Heterogeneous data type object.
2. Array is fixed in size. 2. Collection is not fixed in size.
3. Array is Strong type. 3. Collection is not strong Type.
4. There is no boxing and unboxing process on Array 4. There is process of Boxing and Unboxing on Collection.
  5.We use Generic on Collection to make Collection as Strong type

Note: The difference between Array and Collection/Array and Array list /Array and Data list will be the same.

Next Recommended Readings