Compilerfehler CS0428
Aktualisiert: November 2007
Fehlermeldung
Die Methodengruppe "Bezeichner" kann nicht in den Nichtdelegattyp "Typ" konvertiert werden. Wollten Sie die Methode aufrufen?
Cannot convert method group 'Identifier' to non-delegate type 'type'. Did you intend to invoke the method?
Dieser Fehler tritt beim Konvertieren einer Methodengruppe in einen Nicht-Delegattyp auf bzw. beim Versuch, eine Methode ohne Klammern aufzurufen.
Beispiel
Im folgenden Beispiel wird der Fehler CS0428 generiert.
// 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();
}
}