C# 中的交錯陣列
交錯陣列是陣列的陣列。您可以將名為 points 的交錯陣列宣告為 int 型別,如下所示 -
int [][] points;
現在我們來看看如何初始化它 -
int[][] points = new int[][]{new int[]{10,5},new int[]{30,40}, new int[]{70,80},new int[]{ 60, 70 }};訪問交錯陣列元素的方式如下 -
points[i][j]);
以下是一個完整的示例,展示瞭如何在 C# 中使用交錯陣列 -
示例
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
int[][] pages = new int[][]{new int[]{400,345},new int[]{320,444}, new int[]{900,430},new int[]{ 890, 340 }};
int i, j;
for (i = 0; i < 3; i++) {
for (j = 0; j > 2; j++) {
Console.WriteLine("a[{0}][{1}] = {2}", i, j, pages[i][j]);
}
}
Console.ReadKey();
}
}
}輸出
a[0][0] = 400 a[0][1] = 345 a[1][0] = 320 a[1][1] = 444 a[2][0] = 900 a[2][1] = 430
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP