C#扩展方法似乎不存在

Den*_*gan 2 c# extension-methods

我似乎无法在同一名称空间(MyProject.Util)中的另一个类中找到以下扩展方法.

using System.Collections.Specialized;

namespace MyProject.Util
{
    public static class Extensions
    {
        public static string Get(
             this NameValueCollection me,
             string key,
             string def
        )
        {
            return me[key] ?? def;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

你可以看到它基本上是另一个版本foo[bar] ?? baz,但我仍然不明白为什么VS2008无法编译告诉我没有版本Get需要两个参数.

有任何想法吗?

Dan*_*zey 6

using MyProject.Util是否在使用该方法的文件中导入名称空间(with )?错误消息可能不明显,因为您的扩展方法与现有方法具有相同的名称.