编译器错误 CS0428
更新:2007 年 11 月
错误消息
无法将方法组“Identifier”转换为非委托类型“type”。 您是要调用方法吗?
将方法组转换为非委托类型时,或试图调用不带括号的方法时,会发生此错误。
示例
下面的示例生成 CS0428:
// CS0428.cs
delegate object Del1();
delegate int Del2();
public class C
{
public static C Method() { return null; }
public int Foo() { return 1; }
public static void Main()
{
C c = Method; // CS0428, C is not a delegate type.
int i = (new C()).Foo; // CS0428, int is not a delegate type.
Del1 d1 = Method; // OK, assign to the delegate type.
Del2 d2 = (new C()).Foo; // OK, assign to the delegate type.
// or you might mean to invoke method
// C c = Method();
// int i = (new C()).Foo();
}
}