Array in C# Tutorials


  • Array is collection of identical data type with sequential order.
  • It is used to declare and access collection of variables.

Declare arrays:

Array declaration requires data type and followed by an array_name.


datatype [] arrayname;


int [] numers;

Initializing and Creating an array:

Using new keyword an array is initialized


datatype [] variablename= newdatatype[ array size];


int [] numbers= new int[10];

Array in C# Assignment Help By Online Tutoring and Guided Sessions from assignmenthippo.com

Assigning Values to an Array and Accessing Array Elements

With an index number, individual array elements values can be assigned

 e.g. int [] numbers= new int[10];

e.g. numbers [0] =4;

At the time of declaration, it is possible to assign values to the array

e.g. double[] bal = { 2340.0, 4523.69, 3421.0};

It is also possible to create and initialize an array, as below

int [] mark = new int[5] { 99, 98, 92, 97, 95};

It is also possible to omit the size of the array, as below

int [] marks = new int[] { 99, 98, 92, 97, 95};

Example program:

arrays image 1