Why, it's wrong? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Why, it's wrong?

int x; bool b = B() ; switch (b) { case true : x = 1; break; case false : x = 2; break; } Console. WriteLine(x) ;//error, why?

7th Dec 2017, 4:17 PM
Валерия
Валерия - avatar
2 Answers
+ 8
Initialize x to zero, int x = 0, and make sure the B() method returns something either true or false, you did not show what B() looks like, it's important, because it is what decides the next value of x. Hth, cmiiw
7th Dec 2017, 5:57 PM
Ipang
+ 1
You do not need to create a bool. bool b; is enough. Where do you set the value of b
7th Dec 2017, 5:56 PM
sneeze
sneeze - avatar