Hey All,
I have been using C# for awhile and I was wondering if there was a short cut when it comes to using the '||' in an if statment. For example. If I have an int i and I want my code to do the same thing if i = 4,6 or 7. I know that I could use a swich statement and or I could use if(i = 4 || i=6 ....) . What I want to do is: if(i= 4 || 6 || 7) Is there a shortcut that would allow this. I have been looking but I haven't been able to find any.
Thanks.
Loading
Jonathan MercerPosted Jun 20, 2007, 12:42 PM
AlanPosted Jun 20, 2007, 11:04 AM
The position is slightly neater with the switch statement as you can 'stack' empty cases on top of each other:
switch(i)
{
case 4:
case 6:
case 7:
// do something
break;
default:
// do something else
break;
}
It's no big deal though :)