Tableau Public

cs_Byrong Messages postés 224 Date d'inscription mercredi 28 septembre 2005 Statut Membre Dernière intervention 24 juillet 2013 - 19 avril 2010 à 19:34
cs_Robert33 Messages postés 834 Date d'inscription samedi 15 novembre 2008 Statut Membre Dernière intervention 14 janvier 2017 - 19 avril 2010 à 20:50
Bonsoir

voila j'aimerai utiliser un tableau dans différents private void

Comment puis je faire pour utiliser ce tableau.

[CODE]
public String[] Tableau;
[\CODE]

et apres je met dans mon premier private void
donc j'entre des données dans le tableau
[CODE]
Tableau[0,i] = ....
[\CODE]

Et dans mon second private void je fais
[CODE]
MessageBox.Show(Tableau[0,0]);
[\CODE]

Mais cela m'affiche un messagebox vide...

Pourquoi?

3 réponses

cs_Robert33 Messages postés 834 Date d'inscription samedi 15 novembre 2008 Statut Membre Dernière intervention 14 janvier 2017 33
19 avril 2010 à 20:00
Bonsoir,

sans doute une probleme lors de l'initialisation.

Essaye ce code :

    string[,] Tableau = new string[5, 5];
    for (int i=0; i< 5; i++)
        for (int j = 0; j < 5; j++)
            Tableau[i, j] = string.Format("itération i:{0}  j:{1}", i, j);


C# is amazing, enjoy it!
0
cs_Byrong Messages postés 224 Date d'inscription mercredi 28 septembre 2005 Statut Membre Dernière intervention 24 juillet 2013
19 avril 2010 à 20:18
j'ai testé mais ca ne fonctionne toujours pas
0
cs_Robert33 Messages postés 834 Date d'inscription samedi 15 novembre 2008 Statut Membre Dernière intervention 14 janvier 2017 33
19 avril 2010 à 20:50
Sans doute un probleme ailleurs
car j'ai testé et ça marche .

es-tu certain que le code d'initialisation est appelé avant le MessageBox ?

Essaye ça:

Pose un bouton sur ta forme et dans le gestionnaire du click ajoute:
private void button1_Click(object sender, EventArgs e)
{
    string[,] Tableau = new string[5, 5];
    for (int i=0; i< 5; i++)
        for (int j = 0; j < 5; j++)
            Tableau[i, j] = string.Format("itération i:{0}  j:{1}", i, j);

    MessageBox.Show(Tableau[0, 4]); 

        
}


C# is amazing, enjoy it!
0
Rejoignez-nous