Meilleur auteur de réponses
Remplir un tableau

Question
-
bonjour,
J'aimerais remplir un tableau de 2 string en un seul passage de paramètre, mais pas au moment de sa déclaration.
Exemple:
string[] s = {" "," "};
....
if(a > b)
s[] = {"toto","titi"}
if (a<b)
s[] = {"titi","toto"}
else
s[] = {"titi", "tutu"}
Mais apparemment la syntaxe n'est pas la bonne. Comment faire pour remplir mon tableau s en une seule ligne (sans faire s[0] = "toto" et s[1]="titi") ?
Merci
Réponses
-
Bonjour Tito1309,
Par exemple :
if (a > b) s = new string [] {"toto","titi"}; else if (a < b) s = new string [] {"titi","toto"}; else s = new string [] {"titi", "tutu"};
Cordialement, Jacques
- Marqué comme réponse Florin CiucaModerator mercredi 29 août 2012 11:45
-
Bonjour Titou1309,
ce lien peut peut-être vous être utile:http://msdn.microsoft.com/fr-fr/library/0a7fscd0(v=vs.80).aspx
dans votre cas çà devait être:int a = 5;
int b = 3;
if (b > a)
{ string[] s = { "Toto", "Titi" };}
else
{ string[] s = { "Tuto", "Titi" }; }The most important in the answer is the question
- Marqué comme réponse Florin CiucaModerator mercredi 29 août 2012 11:45
Toutes les réponses
-
Bonjour Tito1309,
Par exemple :
if (a > b) s = new string [] {"toto","titi"}; else if (a < b) s = new string [] {"titi","toto"}; else s = new string [] {"titi", "tutu"};
Cordialement, Jacques
- Marqué comme réponse Florin CiucaModerator mercredi 29 août 2012 11:45
-
Bonjour Titou1309,
ce lien peut peut-être vous être utile:http://msdn.microsoft.com/fr-fr/library/0a7fscd0(v=vs.80).aspx
dans votre cas çà devait être:int a = 5;
int b = 3;
if (b > a)
{ string[] s = { "Toto", "Titi" };}
else
{ string[] s = { "Tuto", "Titi" }; }The most important in the answer is the question
- Marqué comme réponse Florin CiucaModerator mercredi 29 août 2012 11:45