編譯器錯誤 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();
}
}