如何用C#创建一个N维数组

2025-02-24 14:44:51
推荐回答(1个)
回答1:

一维数组、多维数组【示例】

                       // 一维数组
            int[] numbers = new int[5];
 
            // 多维数组
            string[,] names = new string[5, 4];
 
            // 数组的数组(交错数组)
            byte[][] scores = new byte[5][];
 
            // 创建交错数组
            for (int i = 0; i < scores.Length; i++)
            {
                scores[i] = new byte[i + 3];
            }
            // 打印每行的长度
            for (int i = 0; i < scores.Length; i++)
            {
                Console.WriteLine("Length of row {0} is {1}", i, scores[i].Length);
            }