Errore del compilatore CS0407

Aggiornamento: novembre 2007

Messaggio di errore

'metodo tipo restituito' presenta il tipo restituito errato.
'return-type method' has the wrong return type

Il metodo non era compatibile con il tipo delegato. I tipi argomento corrispondevano, ma il tipo restituito non era corretto per il delegato. Per correggere l'errore, utilizzare un metodo diverso oppure modificare il tipo restituito del metodo o del delegato.

Esempio

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