编译器错误 CS0407
更新:2007 年 11 月
错误消息
“return-type method”具有错误的返回类型
此方法与委托类型不兼容。参数类型匹配,但返回类型不是该委托的正确返回类型。若要避免此错误,请使用其他方法、更改方法的返回类型或更改委托的返回类型。
示例
下面的示例生成 CS0407:
// CS0407.cs
public delegate int MyDelegate();
class C
{
MyDelegate d;
public C()
{
d = new MyDelegate(F); // OK: F returns int
d = new MyDelegate(G); // CS0407 – G doesn't return int
}
public int F()
{
return 1;
}
public void G()
{
}
public static void Main()
{
C c1 = new C();
}
}