La question est de savoir si vous avez un déchiquetée ou un tableau multidimensionnel ... voici comment récupérer une valeur de soit:
int[,] rectArray = new int[3,3]
{
{0,1,2}
{3,4,5}
{6,7,8}
};
int i = rectArray[2,2]; // i will be 8
int[][] jaggedArray = new int[3][3]
{
{0,1,2}
{3,4,5}
{6,7,8}
};
int i = jaggedArray[2][2]; //i will be 8
EDIT: Ajout d'aborder la partie de la tranche ...
Pour obtenir un tableau int à partir d'un de ces tableaux, vous devez faire une boucle et récupérer les valeurs que vous recherchez. Par exemple:
public IEnumerable<int> GetIntsFromArray(int[][] theArray) {
for(int i = 0; i<3; i++) {
yield return theArray[2][i]; // would return 6, 7 ,8
}
}
Que fait' this' dans 'ce T [,] array'? –
@Hamish Grubijan: Il convertit la méthode statique en une [méthode d'extension] (http://msdn.microsoft.com/fr-fr/library/bb383977.aspx) – dtb
Vous ne perdez pas l'index 'row' ici car je pensais qu'il devrait être 'array [ligne, colonne]'? – tsul