Errore del compilatore CS0428

Aggiornamento: novembre 2007

Messaggio di errore

Impossibile convertire il gruppo di metodi 'Identificatore' nel tipo non delegato 'tipo'. Si desiderava richiamare il metodo?
Cannot convert method group 'Identifier' to non-delegate type 'type'. Did you intend to invoke the method?

Questo errore si verifica quando si converte un gruppo di metodi in un tipo non delegato oppure quando si tenta di richiamare un metodo senza utilizzare le parentesi.

Esempio

Il seguente codice di esempio genera l'errore 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();
    }
}