共用方式為


編譯器錯誤 CS0149

更新:2007 年 11 月

錯誤訊息

必須是方法名稱

請在建立委派時指定一個方法,如需詳細資訊,請參閱委派 (C# 程式設計手冊)

下列範例會產生 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);
   }
}