Vous n'êtes pas identifié(e).
L'icône rouge permet de télécharger chaque page du wiki visitée au format PDF et la grise au format ODT →
Ceci est une ancienne révision du document !
int [][] tableauDeTableau; // référence sur tableau à deux dimensions new tabDeTab = new int [5][]; // On alloue 5 lignes, on ne sait pas combien de cases (ou colonnes) // pour le "tableau horizontal" 0| | | | 1| | | | | | | 2| | 3| | | | | | 4| | | // Ici la cinquième ligne, l'indice commence à zéro
int [][] tableauDeTableau; // référence sur tableau à deux dimensions new tabDeTab[0] = new int [3]; // La première ligne référence un tableau de trois entiers /*************************************************** 0 1 2 3 // indice commence à zéro ! 0| | | | | etc... ? *************************************************/
int [][] tableauDeTableau; // référence sur tableau à deux dimensions new tabDeTab = new int [5][]; // On alloue 5 lignes tabDeTab [3][2] = 1515; 0 1 2 3 0| | | | 1| | | | | | | 2| | |1515 | 3| | | | | | 4| | |
// Déclarer un tableau à une dimension int[] array1 = new int[5]; // Déclarer et définir les valeurs des éléments du tableau int[] array2 = new int[] { 1, 3, 5, 7, 9 }; // Autre syntaxe int[] array3 = { 1, 2, 3, 4, 5, 6 }; // Déclarer un tableau à deux dimensions int[,] multiDimensionalArray1 = new int[2, 3]; // Déclarer et définir les valeurs des éléments du tableau int[,] multiDimensionalArray2 = { { 1, 2, 3 }, { 4, 5, 6 } }; // Déclarer un tableau en escalier (a jagged array) int[][] jaggedArray = new int[6][]; // Définir les valeurs de la première matrice dans la structure du tableau en escalier jaggedArray[0] = new int[4] { 1, 2, 3, 4 };
/******************************************************************************* * Les tableaux multidimensionnels sont appelés aussi des matrices * ici on montre différente manière d'afficher une matrice remplie * de valeur dans le programme principal. ******************************************************************************/ static void Main(string[] args) // début du programme principal { //tableau multidimensions de char string[,] tabString = new string[3, 2] { {"un", "deux"}, {"trois", "quatre"}, {"cinq", "six"} }; // Autre écriture ne sera pas afficher, présenter pour syntaxe : string[,] array2Db = new string[,] { { "one", "two" }, { "three", "four" }, { "five", "six" } }; Console.WriteLine("///////////////////////////////////////////////////////////"); Console.WriteLine("Affichage des éléments des tableaux de string et de int :"); Console.WriteLine("///////////////////////////////////////////////////////////"); Console.WriteLine(); Console.WriteLine(".............. AFFICHAGE n° 1 de TabString SANS BOUCLE.............."); Console.WriteLine(); Console.WriteLine("première ligne, tab[0 ,0] et tab[0, 1] => " + tabString[0, 0] + " et " + tabString[0, 1]); //un et deux Console.WriteLine(); Console.WriteLine("deuxième ligne, tab[1, 0] et tab[1, 1] => " + tabString[1, 0] + " et " + tabString[1, 1]); //trois et quatre Console.WriteLine(); Console.WriteLine("troisième ligne, tab[2, 0] et tab[2, 1] => " + tabString[2, 0] + " et " + tabString[2, 1]); //cinq et six Console.WriteLine(); int i, j; //indices vertical et horizontal du tabString Console.WriteLine(".......... AFFICHAGE n° 2 de TabString AVEC UNE BOUCLE (tab de string).........."); for (i = 0; i < 1; i++) { for (j = 0; j < 2; j++) { Console.WriteLine(" | "+ tabString[i, j] +" | "); } } Console.WriteLine(); for ( i = 1 ; i < 2; i++) { for (j = 0; j < 2; j++) { Console.WriteLine(" | " + tabString[i, j] + " | "); } } Console.WriteLine(); for (i = 2; i < 3; i++) { for (j = 0; j < 2; j++) { Console.WriteLine(" | " + tabString[i, j] + " | "); } } Console.WriteLine(); //Tableau multidimensions de int : int[,] tabInt = new int[4, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } }; // autre écriture ne sera pas afficher, présenter pour syntaxe : int[,] array2D = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } }; Console.WriteLine(".......... AFFICHAGE n°1 DU TABLEAU DE INT (avec une boucle)........."); Console.WriteLine(" | "+tabInt[0,0]+ " | " +tabInt[0,1]); Console.WriteLine(" | " +tabInt[1,0]+ " | " +tabInt[1,1]); Console.WriteLine(" | " +tabInt[2,0]+ " | " +tabInt[2,1]); Console.WriteLine(" | " +tabInt[3,0]+ " | " +tabInt[3,1]); Console.WriteLine(); Console.WriteLine(".......... AFFICHAGE n°2 DU TABLEAU DE INT (avec une boucle)........."); int l, c; //indice vertical et horizontal de tabInt for (l = 0; l < 4; l++) { for (c = 0; c < 2; c++) { Console.WriteLine(" | " + tabInt[l, c] + " | "); } } System.Console.WriteLine("Appuyer sur une touche pour quitter le programme."); System.Console.ReadKey(); }