Created
December 3, 2010 12:09
-
-
Save tobiashm/726891 to your computer and use it in GitHub Desktop.
Extension methods for .NET
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
// Source: http://www.pluralsight-training.net/community/blogs/keith/archive/2010/11/12/min-max-between-limit.aspx | |
public static class IComparableExtensions | |
{ | |
public static T Limit<T>(this T value, T minValue, T maxValue) where T : IComparable | |
{ | |
if (value.CompareTo(minValue) < 0) | |
return minValue; | |
if (value.CompareTo(maxValue) > 0) | |
return maxValue; | |
return value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment