Declaring, writing to, and reading from a one-dimensional and a two-dimensional array in C#

One dimensional array:

int[]  intArr1 = new int[15] ;        // Declare 1-D array. 
intArr1[2]     = 10;                 // Write to element 2 of the array. 
int var1       = intArr1[2];         // Read from element 2 of the array.

Two dimensional array:

int[,] intArr2 = new int[5,10] ;      // Declare 2-D array. 
intArr2[2, 3]   = 7;                  // Write to the array. 
int var2       = intArr2[2,3];       // Read from the array.

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.