Bonjour
j'ai deux erreurs dans ce code (lignes en gras). Pour la première erreur, je pourrais ajouter ceci: Stm myObj2 = new Stm(); ou bien changer la ligne en ceci: myObj[0].show();
mais je ne trouve pas cela très élégant et ça ne marche pas pour la deuxième erreur (dans la méthode show).
Merci.
using System;
class Stm
{
string nom;
static void Main(string[] args)
{
Stm[] myObj = new Stm[3];
for (int i = 0; i < myObj.Length; i++)
myObj[i] = new Stm();
myObj[0].nom = "Macron";
myObj[1].nom = "Biden";
myObj[2].nom = "Sunak";
myObj.show();
}
void show()
{
for (int i = 0; i < myObj.Length; i++)
Console.WriteLine(nom);
}
}
Partager