In .net (c# or vb) expressions, how would you implement SQL\'s handy IN() functionality?
i.e. value in (1, 2, 4, 7)
rather than:
value = 1 or value =
if((new int[] {1, 2, 4, 7}).Contains(value))
{
// Do some work.
}
As others have pointed out, you could create an In() Extension method (I'll keep it generic so you can use it on any type):
public static bool In(T this obj, IEnumerable col)
{
return col.Contains(obj);
}
So the initial example becomes:
if(value.In(new int[] {1, 2, 4, 7}))
{
// Do some work.
}