Monday, January 30, 2012

Best Extension Methods: Value Exists Between

Using below extension method you can check that the value exists in between of a range or not.
//you can use it like: int a=10; if(a.Between(2,20)){...do some work...}
public static bool Between(this T me, T lower, T upper) where T : IComparable
    {
        return me.CompareTo(lower) >= 0 && me.CompareTo(upper) < 0;
    }

Compiled By: Rajesh Rolen

Share This!


No comments:

Powered By Blogger · Designed By Seo Blogger Templates