2d Array in C# with random numbers

前端 未结 2 1656
灰色年华
灰色年华 2021-01-17 06:38

I want to create 2d array in C#. size: 3 on 5, and insert into random numbers. I try that but it\'s not work:

Random rnd = new Random();
            int[][]          


        
2条回答
  •  长情又很酷
    2021-01-17 07:35

    Here it is:

        Random rnd = new Random();
        int[,] lala = new int[3,5];
        for(int i=0;i<3;i++)
        {
            for(int j=0;j<5;j++)
            {
                lala[i, j]= rnd.Next(1, 10);
                Console.WriteLine("[{0}, {1}] = {2}", i, j, lala[i,j]);
            }
        }
    

    working sample: http://dotnetfiddle.net/4Fx9dL

提交回复
热议问题