編譯器錯誤 CS0835
更新:2007 年 11 月
錯誤訊息
如果運算式樹狀架構的型別引數 'type' 不是委派型別,無法將 Lambda 轉換為運算式樹狀架構。
如果將 Lambda 運算式轉換為運算式樹狀架構,運算式樹狀架構的引數必須要有委派 (Delegate) 型別。此外,Lambda 運算式必須可以轉換為委派型別。
若要更正這個錯誤
- 將型別參數從 int 變更為委派型別,例如 Func<int,int>。
範例
下列範例會產生 CS0835:
// cs0835.cs
using System;
using System.Linq;
using System.Linq.Expressions;
public class C
{
public static int Main()
{
Expression<int> e = x => x + 1; // CS0835
// Try the following line instead.
// Expression<Func<int,int>> e2 = x => x + 1;
return 1;
}
}