C# 中鋸齒陣列的元素型別是什麼?
鋸齒陣列是陣列的陣列,因此它的元素是引用型別,並被初始化為空。
讓我們看看如何使用鋸齒陣列 -
宣告一個鋸齒陣列 -
int [][] marks;
現在,讓我們初始化它,其中 marks 是一個包含 5 個整數的陣列 -
int[][] marks = new int[][]{new int[]{ 40,57 },new int[]{ 34,55 }, new int[]{ 23,44 },new int[]{ 56, 78 }, new int[]{ 66, 79 } };現在讓我們看一個 C# 中的鋸齒陣列的完整示例,並瞭解如何實現它 -
示例
using System;
namespace MyApplication {
class MyDemoClass {
static void Main(string[] args) {
int i, j;
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
廣告
資料結構
網路
關係型資料庫
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP