Leer en inglés

Compartir vía


Error del compilador CS0149

Se espera un nombre de método

Al crear un delegado, especifique un método. Para obtener más información, vea Delegados (Guía de programación de C#).

El ejemplo siguiente genera la advertencia CS0149:

C#
// 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);  
   }  
}