Basically I have an object which for the purpose of this question I am calling "a". If property "b" of object "a" is any one of 1
, 4
, 6
(for example but there could be more values that are appropriate) I want to set it to 8
(again for example). Now typically I would end up doing something like -
if( a.b == 1 || a.b == 4 || a.b == 6 )
a.b = 8;
But I can't help thinking that there must be something simpler/shorter. I'm really looking for something like MSSQL in
syntax (if it exists) -
SELECT
*
FROM table
WHERE
table.field IN (1, 4, 6)
I suppose I could create an array, populate it and then check if it contains my values in the if
statement but that is just going to result in pretty much the same amount of code than the original if
statement and creating an array variable just for the if
feels a little overkill -
int[] values = { 1, 4, 6 };
if(values.Contains(a.b))
a.b = 8;