15,846,346 members
See more:
Hai can any1 help me how to create two dimension array dynamically
Suppose the i retrieve value from datatable in following manner

date Value Name
02/02/2011 2 Rajesh
02/02/2011 3 Ram
03/02/20111 8 Rajesh
03/02/2011 6 Rakesk
03/02/2011 3 Ram

Now my array should be like this

ar[0][0] = 02/02/2011
ar[0][1] = 2
ar[0][2] = 3

ar[1][0] = 03/02/2011
ar[1][1] = 8
ar[1][2] = 6
ar[1][3] = 3
Posted

Solution 1

There will be two different types (let's assume your element type is integer): `int[][]` and `int[,]`.

As you hardly understand topic, start with 2D array (the other way allows for jagged array):

C#
```int [,] array = new int[4, 12];
array[2, 11] = 212;```

The jagged array `int[][]` is not really a 2D array: this is an array of integer arrays. Both inner and outer arrays are 1D. If you think about this words and experiment a bit, you will find a way around them: you initialize outer array (array of array with 1D rank `R`) and then do the cycle `0` to `R` and initialize every inner array with any (different!) lengths. That's why it's called "jagged": inner arrays all have different lengths.

—SA

v3

Solution 2

C#
```//Declaration
string[,] arrDateID = new string[5,5];
//Use
arrDateID [0,0] = 02/02/2011;
arrDateID [0,1] = 2;```

Thanks,

Sergey Alexandrovich Kryukov 8-Feb-11 2:03am
Why would you duplicate existing answer?
There was a scenario when i have clicked on "Add an Answer" at that time no body given any answer. but during answer typing it will take time during this time any body would be given answer for the question.

Did you get it??

Solution 3

See here[^].

You already have the record count so you can just generate the array by using
C#
`int[,] myArray = new int[m,n];`

Sergey Alexandrovich Kryukov 8-Feb-11 2:04am
If you also add a reference about jagged arrays, will be good...
--SA