我有列表new List<Expression<Func<Test, bool>>>
并且我想添加项到.Add()
范围内的所有操作
我该如何实现?
var a = new List<Func<Test, bool>>();
var b = new List<Expression<Func<Test, bool>>>();
a.Add
(
new Func<Test, bool>(x => x.test == false) // works
);
b.Add
(
new Expression<Func<Test, bool>>(x => x.test == false) // fails
);
答案 0 :(得分:3)
只需省略类型并让编译器进行推断:
var a = new List<Func<Test, bool>>();
var b = new List<Expression<Func<Test, bool>>>();
a.Add
(
x => x.test == false
);
b.Add
(
x => x.test == false
);