Tableau et foreach

yogui411 Messages postés 36 Date d'inscription dimanche 5 décembre 2004 Statut Membre Dernière intervention 6 juin 2006 - 14 avril 2006 à 14:20
Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 - 14 avril 2006 à 15:00
Bonjour,

Je sais faire un foreach en utilisant un tableau.
Mais je sais pas faire avec un tableau à 2 dimensions. Je voudrais faire un foreach sur une des 2 dimensions.

Merci
A voir également:

1 réponse

Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 41
14 avril 2006 à 15:00
Salut, foreach parcours les éléments dans l'ordre faut utiliser une boucle for ou un tableau irregulier :

int[ , ] tab0 = { { 0, 1 }, { 2, 3 } };


for ( int i = 0; i < tab0.GetLength( 1 ); i++ )
MessageBox.Show( tab0[ 1, i ].ToString( ) );


int[ , ] tab1 = { { 0, 1 }, { 2, 3 } };


foreach( int i in tab1 )
MessageBox.Show( i.ToString( ) );


int[ ][ ] tab2 = { new int[ ] { 0, 1 },new int[ ] { 2, 3 } };


foreach( int[ ] t in tab2 )
foreach( int i in t )
MessageBox.Show( i.ToString( ) );
0
Rejoignez-nous