我对这个错误感到很困惑:
Cannot implicitly convert type 'System.Func<T,T,T> [c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll]' to 'System.Func<T,T,T> [c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll]' path\to\my\project\Operators.cs
类型是相同的,为什么它甚至试图做一个演员?这是代码:
public static class Operators<T>
{
private static Func<T,T,T> _add = null;
public static T Add<T>(T a, T b)
{
if (_add == null) {
var param1Expr = Expression.Parameter(typeof (T));
var param2Expr = Expression.Parameter(typeof (T));
var addExpr = Expression.Add(param1Expr, param2Expr);
var expr = Expression.Lambda<Func<T, T, T>>(addExpr, param1Expr, param2Expr);
_add = expr.Compile(); // <--- error occurs here
}
return _add.Invoke(a, b);
}
}