In fact, I prefer to create a small extension method for it:
public static bool IsIn<T>(this T obj, params T[] set) {
return set.Any(el => element.Equals(obj));
}
It encapsulates all black magic and makes your code very concise, which is your goal, obviously:
if (!trsaz.IsIn(v1, v4, v7, v11)) {
}
It is always useful to hide the mechanism if it is not important, especially in this case, when the use of some mechanism is not required at all and will confuse some people who will support your code.
source
share