Techie Talks

Friday, February 18, 2005

C# Arrays

Array handling in C# is different from that in C++ or C.

To declare a 1D array:

int[] test1DArray = new int[10]; // All arrays needs to be instantiated.

test1DArray[1] = 10; //To access

To declare a 2D rectangular array:

int[,] test2DRArray = new int[10,20];

test2DRArray[1,2] = 10; //To access

To declare a 2D jagged array (where each row can contain different no. of columns):

int[][] test2DJArray = new int[3][];

test2DJArray[0] = new int[1];
test2DJArray[1] = new int[2];
test2DJArray[2] = new int[4];

test2DJArray[2][3] = 10; //To access

0 Comments:

Post a Comment

<< Home