C# 中的数组数组双重 [] []?
C# 中的数组数组称为锯齿数组。要声明锯齿数组,请使用双 [ ][ ]。
我们现在声明它们 −
int [][] marks;
现在,让我们对它进行初始化,其中 marks 是 5 个整数的数组 −
int[][] marks = new int[][]{new int[]{ 90,95 },new int[]{ 89,94 }, new int[]{ 78,87 },new int[]{ 76, 68 }, new
int[]{ 98, 91 } };示例
让我们现在看看 C# 中锯齿数组的完整示例,并学习如何实现它 −
using System;
namespace MyApplication {
class MyDemoClass {
static void Main(string[] args) {
int i, j;
/* jagged array of 5 array of integers */
int[][] marks = new int[][]{new int[]{90,95},new int[]{89,94}, new int[]{78,87},new int[]{ 76, 68 },
new int[]{ 98, 91}};
for (i = 0; i < 5; i++) {
for (j = 0; j < 2; j++) {
Console.WriteLine("marks[{0}][{1}] = {2}", i, j, marks[i][j]);
}
}
Console.ReadKey();
}
}
}输出
marks[0][0] = 90 marks[0][1] = 95 marks[1][0] = 89 marks[1][1] = 94 marks[2][0] = 78 marks[2][1] = 87 marks[3][0] = 76 marks[3][1] = 68 marks[4][0] = 98 marks[4][1] = 91
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 程序设计
C++
C#
MongoDB
MySQL
Javascript
PHP