CSharp Articles

Arrays in C#

Arrays in C#

Array is collection of variable of same datatype .

Syntax to declare arrays :

DataType[] arrayname ;

Arrays are following types : single dimensional , two dimensional and jagged arrays

Single-dimensional array :

  1. int[] singlearray1 = new int[5];
  2. int[] singlearray2 = new int[] { 1, 3, 5, 7, 9 };
  3. int[] singlearray3 = { 1, 2, 3, 4, 5, 6 };

Two dimensional array :

  1. int[,] twoDimensionalArray1 = new int[2, 3];
  2. int[,] twoDimensionalArray2 = { { 1, 2, 3 }, { 4, 5, 6 } };

Jagged array :

int[][] jaggedArray = new int[6][];

jaggedArray[0] = new int[4] { 1, 2, 3, 4 };

Leave a Reply