编译器错误 CS1940
更新:2007 年 11 月
错误消息
找到了源类型“type”的查询模式的多个实现。对“method”的调用不明确。
如果定义了查询方法的多个实现,而编译器无法确定哪个实现最适合该查询,则会生成此错误。在下面的示例中,Select 的两个版本具有相同签名,因为它们都接受一个 int 作为输入参数,并将 int 用作返回值。
更正此错误
- 为每个方法仅提供一个实现。
示例
下面的代码生成 CS1940:
// cs1940.cs
using System; //must include explicitly for types defined in 3.5
class Test
{
public delegate int Dele(int x);
int num = 0;
public int Select(Func<int, int> d)
{
return d(this.num);
}
public int Select(Dele d) // CS1940
{
return d(this.num) + 1;
}
public static void Main()
{
var q = from x in new Test()
select x;
}
}