daixinet

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

用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();
                }
            }
        }

 

posted on 2012-08-28 15:34  daixinet.com  阅读(6137)  评论(0编辑  收藏  举报