c # :( multidimensional arrays) randomly generate student performance reports

[A] idea
syntax initialized two-dimensional array
element type [,] = new array element type name [number of rows, columns] {{a, b, c }, {d, f, g}, {v, b , n}}

[Example] results
Two-dimensional array
[realization]

 class Program
        {
        static void Main(string[] args)
            { //生成学生成绩报表
            byte[,] result = new byte[20, 5];//创建一个二维数组的对象来存放学生的成绩
            Random random = new Random();//Random类是随机生成器;进行创建一个对象
            Console.WriteLine("学号\t高数\tc#语言\t语文\t英语\t数据库");
            for (int i = 0; i < result.GetLength(0); i++)//通过Getlength方法来获取数组的行数和列数,
                {                                        // 参数为0时,返回的时行数,参数为1时,返回的是列数 
                Console.Write(i);

                for (int j = 0; j < result.GetLength(1); j++)
                    {
                    result[i, j] = (byte)random.Next(101);
                    Console.Write("\t"+result[i ,j ]);
                    }
                Console.WriteLine();
                }
            

            }
Published 18 original articles · won praise 6 · views 835

Guess you like

Origin blog.csdn.net/yy52520/article/details/104951851