C#中使用foreach语句遍历二维数组的源码演示

把写内容过程中比较常用的内容段备份一次,下面的资料是关于C#中使用foreach语句遍历二维数组的演示的内容。

using System;

public class w3demo{
public static void Main() {
int sum = 0;
int[,] nums = new int[3,5];

for(int i = 0; i < 3; i++)
for(int j=0; j < 5; j++)

foreach(int x in nums) {
Console.WriteLine("Value is: " + x);
sum += x;
}
Console.WriteLine("Summation: " + sum);
}
}





猜你喜欢

转载自www.cnblogs.com/s-squirrel/p/10842875.html