This documentation is archived and is not being maintained.

Compiler Error CS0149

Method name expected

When creating a delegate, specify a method.

The following sample generates CS0149:

// CS0149.cs
using System;

delegate string func(int i);

class a
{
   static func dt;   // class member-field of the declared delegate type

   public static void Main()
   {
      dt = new func(17.45);   // CS0149
      // try the following line instead
      // dt = new func(func2);
      x(dt);
   }

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

   public static void x(func myFunc)
   {
      myFunc(8);
   }
}
Show: