
Un tableau irrégulier est un tableau de tableaux, ses éléments sont donc des types référence et initialisés à null.
Voyons comment utiliser un tableau irrégulier -
Déclarez un tableau irrégulier -
Copier après la connexion
Maintenant, initialisons-le là où Marks est un tableau de 5 entiers -
1 | int[][] marks = new int[][]{ new int[]{ 40,57 }, new int[]{ 34,55 }, new int[]{ 23,44 }, new int[]{ 56, 78 }, new int[]{ 66, 79 } };
|
Copier après la connexion
Voyons maintenant comment cela fonctionne en C# Exemple complet de jagged tableau et apprenez à l'implémenter -
Exemple
Démonstration en direct
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 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();
}
}
}
|
Copier après la connexion
Sortie
1 2 3 4 5 6 7 8 9 10 | 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
|
Copier après la connexion
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!