General limitations - I'm not sure how to fix this anyway

I basically have the following:

public static bool IsBetween<T>(this T value, T a, T b)
    where T : IComparable
{
    ...
}

public static bool IsBetween<T>(this T value, T a, T b)
    where T : IComparable<T>
{
    ...
}

The problem is that I cannot do this, because you cannot have a member with the same signature, even if the restrictions are different. But it cannot be said that the restriction is either IComparableOR IComparable<T>. So I'm not sure what to do here, except to just pick one and go with it. And, no matter which one I choose, I lose each other because they are separated and not inherited from each other (which makes sense).

I missed something here, is there a way to do this with both, or will I need to choose one (maybe the general version)?

+5
source share
2 answers

, . :

public static bool IsBetween(this IComparable value, IComparable left, IComparable right)

generic? , , , CompareTo(object).

, . , .

+8

.NET- . IComparable IComparable<T> - , . IComparable<T>. .NET, Int32, Decimal, DateTime,... .

+3

All Articles