编译器错误 CS1662
更新:2007 年 11 月
错误消息
无法将匿名方法块转换为委托类型“delegate type”,原因是块中的某些返回类型无法隐式转换为委托返回类型
如果匿名方法块的返回语句有一个无法隐式转换为委托的返回类型的类型,则会发生此错误。
下面的示例生成 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; };
}
}