In C# is there a shorthand way to write this:
public static bool IsAllowed(int userID)
{
return (userID == Personnel.JohnDoe || userID == Personnel.JaneD
How about this?
public static class Extensions
{
public static bool In(this T testValue, params T[] values)
{
return values.Contains(testValue);
}
}
Usage:
Personnel userId = Personnel.JohnDoe;
if (userId.In(Personnel.JohnDoe, Personnel.JaneDoe))
{
// Do something
}
I can't claim credit for this, but I also can't remember where I saw it. So, credit to you, anonymous Internet stranger.