I'm not sure I understand the question ...
Why can't you just write sample code like this:
Select Case value Case 1, 2 DoWork() End Select
Nothing happens when value = 0 or value = 3 . The number of values ββprovided to the Case statement does not have to be sequential.
Update in response to comment:
I would write this using the Case Else sign:
Select Case myComboBox.SelectedIndex Case 1, 5, 8 'The suggestion is acceptable, so process it DoWork() Case Else 'The suggestion is invalid, so show an error MessageBox.Show("You cannot select that option. " & _ "Please choose options 1, 5, or 8 instead.", _ "Invalid Selection", _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Select
Of course, if in fact you donβt have any βworkβ in the case when the user selects the correct value, it makes little sense to use the Select Case operator at all. The cardinal rule should be to use what makes your code the clearest and easiest to understand. It is unlikely that the Select Case faster than the If statement - the compiler is smart enough to get almost equivalent results in almost every case.
source share