Skip to content

Instantly share code, notes, and snippets.

@ForeverZer0
Created June 5, 2018 16:41
Show Gist options
  • Save ForeverZer0/605024e6722a69be499f9ae08474fb0f to your computer and use it in GitHub Desktop.
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
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