C#でforeachを使って2次元配列の要素を遍歴する

参考コード
using System;
public class foreachdemo{
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++)
nums[i,j] = (i+1)*(j+1);
foreach(int x in nums) {
Console.WriteLine(“値: " + x);
sum += x;
}
Console.WriteLine(“総和: " + sum);
}
}

IT

Posted by arkgame