I came up with the following extensions method in C#:
public static class NeatExtensions{ public static bool In<T>(this T element, params T[] elements){ return new HashSet<T>(elements).Contains(element); } }
It actually yields a nice syntax for checking enum values and the likes:
enumValue.In(Enum.X, Enum.Z)
I am wondering whether there is actually a de-factor standard library in the C# world that has extensions like this.
Leave a Reply