二維數組轉一位數組

static void Main(string[] args)
        {
            int[,] A = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
            int[] B = new int[10];
            int n = 0;
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    B[n++] = A[i, j];
                }
            }

            for (int i = 0; i < 9; i++)
            {
                Console.WriteLine(B[i]);
            }

            Console.Read();
        }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章