简体   繁体   English

对扩展方法的模糊调用

[英]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)' 错误1699以下方法或属性之间的调用不明确:'BillingFormsApplication.Extensions.IsBetween(double,double,double)'和'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. 只有一个IsBetween的方法Extensions文件...只有一个IsBetween在整个解决方案的方法。

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: 为Frederic添加:

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

I wonder if I cast those numbers to Double if that will fix it. 我想知道如果能解决这个问题,我是否将这些数字转换为Double。 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. 更有可能的是,您引用的DLL具有定义的相同扩展方法,或者您在代码中的其他位置定义了此DLL。 Try doing a find in files search for IsBetween and see if it comes up. 尝试在文件中查找搜索IsBetween并查看它是否出现。 If not, look at the DLLs you have referenced and see if this extension doesn't exist in one of those. 如果没有,请查看您引用的DLL,并查看其中一个扩展名是否存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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