for循环遍历
string[,] scores=new string[2,3];
string[,] scores2 = {{"1","2","3"},{"4","5","6"},{"7","8","9"}};Console.WriteLine(scores2.Length);//得到数组的长度(结果为相乘得到的结果 3*3)
Console.WriteLine(scores2.GetLength(0));// 得到数组的行数 3
Console.WriteLine(scores2.GetLength (1));//得到数组的列数 3
for (int i = 0; i < scores2.GetLength(0); i++){
Console.WriteLine("行数为" + i);
for (int j = 0; j < scores2.GetLength(1); j++)
{
Console.WriteLine("列数为" + i);
Console.WriteLine("最终值为" + scores2[i, j]);
}
}
Console.ReadLine();
foreach 循环遍历
foreach (string i in scores2)
{
Console.WriteLine(i);
}