Thursday, May 5, 2011

Between Extension method for double

This is a work in progress and can be used for only numeric data types. And also works with all the object that implements IComparable.

Works for almost every case and it is pretty handily.

/// <summary>
/// Extention method for between
/// </summary>
public static class SomeExtention
{
public static bool Between<T>(this T actual, T lower, T upper) where T : IComparable<T>
{
return actual.CompareTo(lower) >= 0 && actual.CompareTo(upper) <= 0;
}
}


Looking forward to share more about this stuff. Until next time bye bye.

No comments:

Post a Comment