Question is quite opinion-based, but if readability is a key factor, one option is to use an extension method
public static bool In<T>(this T x, params T[] set)
{
return set.Contains(x);
}
which would allow you to write:
if (myid.In(1, 2, 10, 11, 12, 13, 14, 15))
{
}
I'll fill other options, just to give some sense of comparison (I'm certainly not advocating all of the next options)
Ugly, but works fine for one "continuous" sequence:
if ((myid >= 1 && myid <= 2) || (myid >= 10 && myid <= 15))
{
}
You can define your own Between
extension method. Note: I would always forget if minVal or maxVal are inclusive or exclusive. (For example Random.Next uses minValue inclusive and maxValue exclusive) :
public static bool Between(this int number, int minVal, int maxVal)
{
return number >= minVal && number <= maxVal;
}
Consider much better Between extension method, this is just a naive example. Now you can:
if (myid.Between(1, 2) || myid.Between(10, 15))
{
}
Or use native methods
if (new[]{1, 2, 10, 11, 12, 13, 14, 15}.Contains(myid))
{
}
Or
int[] expectedValues = {1, 2, 10, 11, 12, 13, 14, 15};
if (expectedValues.Contains(myid))
{
}