共用方式為


編譯器錯誤 CS1660

更新:2007 年 11 月

錯誤訊息

無法將匿名方法區塊轉換為型別 'type',因為它不是委派型別

如果您嘗試指派或轉換匿名方法區塊為非委派型別的型別時,便會發生這個錯誤。

下列範例會產生 CS01660:

// CS1660.cs
delegate int MyDelegate();
class C {
   static void Main()
   {
     int i = delegate { return 1; };  // CS1660
     // Try this instead:
     // MyDelegate myDelegate = delegate { return 1; };
     // int i = myDelegate();
   }
}