Errore del compilatore CS0149

Aggiornamento: novembre 2007

Messaggio di errore

È previsto il nome di un metodo.
Method name expected

Durante la creazione di un delegato specificare un metodo. Per ulteriori informazioni, vedere Delegati (Guida per programmatori C#).

Il seguente codice di esempio genera l'errore CS0149:

// CS0149.cs
using System;

delegate string MyDelegate(int i);

class MyClass
{
   // class member-field of the declared delegate type
   static MyDelegate dt;   

   public static void Main()
   {
      dt = new MyDelegate(17.45);   // CS0149
      // try the following line instead
      // dt = new MyDelegate(Func2);
      F(dt);
   }

   public static string Func2(int j)
   {
      Console.WriteLine(j);
      return j.ToString();
   }

   public static void F(MyDelegate myFunc)
   {
      myFunc(8);
   }
}