简体   繁体   中英

Ambiguous call on extension method

I have an extension method on my project that has been working fine:

public static class Extensions
{
    public static bool IsBetween<T>(this T value, T low, T high) 
                                                         where T : IComparable<T>
    {
        return value.CompareTo(low) >= 0 && value.CompareTo(high) <= 0;
    }
}

Now when I try to build my project I get this error:

Error 1699 The call is ambiguous between the following methods or properties: 'BillingFormsApplication.Extensions.IsBetween(double, double, double)' and 'BillingFormsApplication.Extensions.IsBetween(double, double, double)'

There is only one IsBetween method in the Extensions file... AND only one IsBetween method in the entire solution.

I tried to clean and rebuild the solution. Still getting the error.

I could remove the extension and keep going, but it has been quite handy in the past.

Added for Frederic:

                    if (percentCash.IsBetween(0, 99))
                {

I wonder if I cast those numbers to Double if that will fix it. I'll try that in a minute. Like:

if (percentCash.IsBetween((double)0, (double)99))

More than likely, you are referencing a DLL that has this same extension method defined or you got this defined somewhere else in your code. Try doing a find in files search for IsBetween and see if it comes up. If not, look at the DLLs you have referenced and see if this extension doesn't exist in one of those.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM