I have a variable whose value is populated at runtime. I want to check whether that value is between two different datatype values (say lowest and highest) or not using an Extension Method.
These two values (lowest and highest) can be of same datatypes (No problem). Then its like
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;
}
courtesy my earlier asked question How to create a Between Extension Method
But what if they have different datatypes but same base class.
say
I want to check like
byte a = 2; //here static but is can be changed at runtime
if(a.Between(0,8.0))
DoSomething();
else
DoNothing();
In the above snippet i am checking a byte value between an int value and double value. How to do in such cases. I want to create an extension method like
public static bool Between<T1, T2, T3>(this T1 actual, T2 lowest, T3 highest)
where T1: ????
where T2: ????
where T3: ????
{
What code to write here????
}
For above snippet my EM should return true