共用方式為


編譯器錯誤 CS1662

更新:2007 年 11 月

錯誤訊息

無法將匿名方法區塊轉換為委派型別 'delegate',因為區塊中某些傳回型別無法隱含轉換為此委派的傳回型別

如果匿名方法區塊的傳回陳述式包含的型別無法隱含轉換為委派的傳回型別,便會發生這個錯誤。

下列範例會產生 CS1662:

// CS1662.cs

delegate int MyDelegate(int i);

class C
{

  public static void Main()
  {
     MyDelegate d = delegate(int i) { return 1.0; };  // CS1662
     // Try this instead:
     // MyDelegate d = dekegate(int i) { return (int)1.0; };
  }
}