我有一个构件,其Predicate
我想在一个LINQ表达式中使用的一类:转换一个谓语<T>到函数求<T, bool>
using System.Linq;
class MyClass
{
public bool DoAllHaveSomeProperty()
{
return m_instrumentList.All(m_filterExpression);
}
private IEnumerable<Instrument> m_instrumentList;
private Predicate<Instrument> m_filterExpression;
}
正如我读“Predicate<T>
是[...]完全相当于Func<T, bool>
“(see here),我希望这个工作,因为All
作为参数:Func<Instrument, bool> predicate
。
但是,我得到的错误:
Argument 2: cannot convert from 'System.Predicate<MyNamespace.Instrument>' to 'System.Type'
有没有办法谓词转换成一个参数,这个函数会吞噬?
啊哈,这工作,谢谢!所以Predicate和Func 显然不是**完全相同,至少在语义上讲不是! –
Yellow
2014-08-27 16:05:43
它们在语义上是相同的。只是不在语法上。 – 2014-08-27 16:24:42
糟糕,这就是我的意思。 :-) – Yellow 2014-08-28 08:02:30