共用方式為


編譯器錯誤 CS1706

更新:2007 年 11 月

錯誤訊息

運算式不能包含匿名方法或 Lambda 運算式

您不能在運算式中插入匿名方法。

若要更正這個錯誤

  • 請在運算式中使用規則 delegate。

範例

下列範例會產生 CS1706:

// CS1706.cs
using System;

delegate void MyDelegate();
class MyAttribute : Attribute
{
    public MyAttribute(MyDelegate d) { }
}

// Anonymous Method in Attribute declaration is not allowed.
[MyAttribute(delegate{/* anonymous Method in Attribute declaration */})]  // CS1706
class Program
{
}