In this example, You will learn how to create a two dimensional array. And also you will learn how to dynamically add values into the 2D array by user by random.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
static void Main(string[] args) { Random rnd = new Random(); int[,] arr = new int[3, 4]; for(int i=0;i<3;i++) { for(int j=0;j<4;j++) { arr[i, j] = rnd.Next(0, 100); Console.WriteLine("arr[{0},{1}] = {2}",i,j,arr[i,j]); } Console.WriteLine(); } Console.ReadKey(); } |
Output: