So I was making a Rock Paper Scissor game and I've sort of made adjustments to it to include life and other things. Now I got stuck with the switch statement. My if statement works fine:
private void Result_TextChanged(object sender, EventArgs e)
{
if (playerscore == 1 || pcscore == 1)
{
PlayerLife.Image = Properties.Resources.Five;
}
}
I was wondering how I could translate this to the switch statement?
private void Result_TextChanged(object sender, EventArgs e)
{
switch (playerscore || pcscore)
{
case 1:
PlayerLife.Image = Properties.Resources.Five;
break;
}
}
Doesn't seem to work.
switchon a single variable's value, and why do you want to use switch?Selectstatement is a lot more flexible than C#'sswitch.ifstatement is not appropriate in this scenario?||used to pick non-falsy value than C# equivalent of JavaScript||is approximatelyplayerscore != 0? playerscore:pcscore, or sometimes??for reference types (stackoverflow.com/questions/19534876/…)