Here's a little extension on Object in C#
public static bool EqualsAny<T>(this T obj, params T[] compareTo)
{
for (int i = compareTo.Length - 1; i >= 0; --i)
{
if (obj.Equals(compareTo[i]))
{
return true;
}
}
return false;
}
If the original code would have looked something like this before:
int nowHour = DateTime.Now.Hour;
if (nowHour.Equals(10) ||
nowHour.Equals(12) ||
nowHour.Equals(15) ||
nowHour.Equals(17) ||
nowHour.Equals(19) ||
nowHour.Equals(23))
{
//Happy hour!
}
the after code would look like this:
if (DateTime.Now.Hour.EqualsAny(10, 12, 15, 17, 19, 23))
{
//Happy hour!
}