- 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?
2 ответов
+ 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
+ 1
You do not need to create a bool.
bool b; is enough.
Where do you set the value of b