- 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