您的位置:首页 > 编程语言 > C#

C# 遍历二维数组

2012-08-28 15:34 169 查看
用foreach遍历二维数组

static void Main(string[] args)
{
object[,] dataArray = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };

int count = 0;
foreach (object item in dataArray)
{

Console.Write(item);
Console.Write(" ");

count++;
if (count % dataArray.GetLength(1) == 0)
{
Console.WriteLine();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: