How can I do this elegantly with C# and .NET 3.5/4?
For example, a number can be between 1 and 100.
I know a simple if would suffice; but the keyword to this
Regarding elegance, the closest thing to the mathematical notation (a <= x <= b) slightly improves readability:
public static bool IsBetween(this int value, int min, int max)
{
return min <= value && value <= max;
}
For further illustration:
public static bool IsOutside(this int value, int min, int max)
{
return value < min || max < value;
}