Created
June 5, 2018 16:41
-
-
Save ForeverZer0/605024e6722a69be499f9ae08474fb0f to your computer and use it in GitHub Desktop.
[C#] Extension method to test if a numeric type is within a given range
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static bool IsBetween<T>(this T value, T min, T max) where T : struct, IComparable, IComparable<T>, | |
IConvertible, IEquatable<T>, IFormattable | |
{ | |
return value.CompareTo(min) >= 0 && value.CompareTo(max) <= 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment