Is Value in the range
using System; namespace Snooty { public class Util { public static T Constrain<T>(T value, T min, T max) where T : IComparable { if (value.CompareTo(min) < 0) { return min; } else if (value.CompareTo(max) > 0) { return max; } else { return value; } } } }