Dot Net Interview Questions and Tutorials
By Dr. Rajesh Rolen
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;
}
No comments:
Post a Comment