Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MSDN C#阵列教程_C#_Arrays - Fatal编程技术网

MSDN C#阵列教程

MSDN C#阵列教程,c#,arrays,C#,Arrays,我正在学习C#数组语法。它有以下代码: // Array-of-arrays (jagged array) byte[][] scores = new byte[5][]; // Create the jagged array for (int i = 0; i < scores.Length; i++) { scores[i] = new byte[i + 3]; } // Print length of each row for (int i = 0; i < sco

我正在学习C#数组语法。它有以下代码:

// Array-of-arrays (jagged array)
byte[][] scores = new byte[5][];

// Create the jagged array
for (int i = 0; i < scores.Length; i++)
{
    scores[i] = new byte[i + 3];
}

// Print length of each row
for (int i = 0; i < scores.Length; i++)
{
    Console.WriteLine("Length of row {0} is {1}", i, scores[i].Length);
    Console.ReadLine();
}
我已将代码复制粘贴到控制台应用程序的主方法中,我的控制台输出为:

Length of row 0 is 3
Length of row 1 is 4
Length of row 2 is 5
Length of row 3 is 6
Length of row 4 is 7
Length of row 0 is 3

有人知道为什么我的输出不同吗

您的程序要求您在连续的输出行之间按Enter键:

Console.ReadLine();
  • 这里有一个
    Console.ReadLine()
    ,因此必须在显示下一行输出之前按enter键
  • VisualStudio(如果您正在使用)调试器是您的朋友(或者通常是调试器)
  • byte[][]得分=新字节[5][];
    //创建锯齿状数组
    for(int i=0;iConsole.ReadLine();按Enter键查看以下行谢谢,很多答案都正确。
    
            byte[][] scores = new byte[5][];
    
            // Create the jagged array
            for (int i = 0; i < scores.Length; i++)
            {
                scores[i] = new byte[i + 3];
            }
    
            // Print length of each row
            for (int i = 0; i < scores.Length; i++)
            {
                Console.WriteLine("Length of row {0} is {1}", i, scores[i].Length);
                Console.ReadLine(); <------ Press enter here to continue, If you want your output like MSDN's, remove this line and the program will output all results
            }