编译器错误 CS1660
更新:2007 年 11 月
错误消息
无法将匿名方法块转换为类型“type”,因为它不是一个委托类型
如果您尝试将匿名方法块分配给或以其他方式转换为不是委托类型的类型,就会发生此错误。
下面的示例生成 CS1660:
// 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();
}
}