dimanche 27 novembre 2016

Issue in C# if statement

Hi i have the following part of code

string[] choices = new string[UserChoices.Count];  
int count1 = 0;
        for (int i = 0; i < UserChoices.Count; i++)
        {
            choices[i] = UserChoices[i];
            //MessageBox.Show(choices[i]);
            if (choices[i] == "1")
            {
                count1++;
            }        
        } 

I declare the array choices in which array i store the contains of a list with name UserChoices

So far so good but i have a problem with the if statement, for some reason when choices[i] is equal to "1" as a string the variable count1 does not increases.

I have checked every value of choices array through Message.Box and in some loops choices[i] is "1". I tried different ways to check equality such as .Equals, switch.

Any idea why my if statement does not goes true ?

Aucun commentaire:

Enregistrer un commentaire