Basic of Array

Arrays are data structure used to store collection of values.
Declaration: Datatype[] variable = new Datatype[length];
All elements should be of same data types.
We can assign value to array elements by using [] square brackets and index inside it and then assignment operator.
f. ex: arr[1] = 0;
You can also assign the value in advance using curly braces notation.
f. ex: int[] y = new int[] {1,2,3};              
          int[] y = {1,2,3};
There are also two types of multi dimention array in C# retangular and jagged array.
In declaration it contains comma for seperation of dimention and jagged array is array of arrays.
Rectangular: int[,] a = new int[1,1];
Jagged: int[][] = new int[2][];

Advertisements

#array