11,927,711 members (29,115 online)
Rate this:
See more:
Hi I want to fill jagged array using for loop in C#.In this jagged array we would have 768 rows with 9 elements in each row. I want to fill each row with random number.for example my first row would be

row 1 12 18 19 158 147 145 147 155 15
row2 14 17 18 15 19 16 114 15 4

thank you.
Posted 11-Jan-13 20:26pm
Shanu2rick 12-Jan-13 1:40am

what have you tried?
Show the code, if you, please?

Rate this:

## Solution 1

And the issue is? Tried?

You need two `for` loops and then just get random numbers to add to each array element. Try out.
Rate this:

## Solution 2

First, if you know the number of coulmns and rows and they are fixed it is not jagged, it is just 2 dimentional array.

second, this is actually easy, just see the sample code here (random range: 0, 1000)

```public static void Main(string[] atgs)
{
//row 1 12 18 19 158 147 145 147 155 15
//row2 14 17 18 15 19 16 114 15 4

const int rows = 768;
const int columns = 9;
int[,] ai = new int[rows, columns];

Random r = new Random();

for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < columns; ++j)
{
ai[i, j] = r.Next(0, 1000);
}
}

}```
Rate this:

## Solution 3

Top Experts
Last 24hrsThis month
 OriginalGriff 204 Richard Deeming 175 Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ) 130 ppolymorphe 94 Jochen Arndt 80
 OriginalGriff 7,740 KrunalRohit 4,723 Sergey Alexandrovich Kryukov 3,658 George Jonsson 2,970 Suvendu Shekhar Giri 2,331