Hey guys, quick question.
When you use a switch statement, does it evaluate the condition once or every time it is tested against a case? I imagine it would be the former, since that's much more efficient, but I need to make sure. For example:
Code:
switch (random.Next(0, 2))
{
case 0:
foo();
break;
case 1:
foo_2();
break;
}
Would this code test each case against a different random number, or would it store the random number and then test it against each case? Either way it's a simple fix; if it's the former, I can just do:
Code:
int randomNumber = random.Next(0, 2);
switch (randomNumber)
{
// stuff
}
The better code depends on when the switch statement and how the switch statement checks the cases. That's my question.
Thanks in advance