Rather than something like this:
switch (id) {
case 2:
case 5:
case 11:
case 15:
...
}
Is there a concise way to check if an int variable is equal to any one of a series of integers? Maybe something like if (id == {2|5|11|15}) ...
?
You could put all the ints into a HashSet and do a contains.
Hashset<int> ids = new HashSet<int>() {...initialize...};
if(ids.Contains(id)){
...
}
if((new List<int> { 2, 5, 11, 15}).Contains(id))
But you probably don't want to create a new List
instance every time, so it would be better to create it in the constructor of your class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With