Use for loop to assign value to an array in CSharp
Description
The following code shows how to use for loop to assign value to an array.
Example
using System;
//from www .ja v a 2 s .c o m
public class MainClass
{
static void Main(string[] args)
{
//multidimensional array
int[,] MyIntArray = new int[5, 5];
for (int x = 0, y = 0; x < 5; x++, y++)
{
MyIntArray[x, y] = 0;
}
for (int x = 0, y = 0; x < 5; x++, y++)
{
Console.WriteLine(MyIntArray[x, y]);
}
}
}
The code above generates the following result.