有人可以帮我简单解释一下 <Func<T, bool>>

Sam*_*tar 2 c#

我正在查看包含以下内容的代码:

public virtual ICollection<T> GetPk(string pk)
{
    Expression<Func<T, bool>> predicate = c => c.PartitionKey == pk;
    return this.GetAll(predicate);
}
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下 的语法<Func<T, bool>>吗?

Abd*_*nim 5

简单来说Func<T, bool>就是匿名方法签名。第一种类型T是输入参数类型,第二种类型是返回类型。当您考虑您的表示时,这更像是一种方法:

bool AnonMethod(T arg0)
{
   return arg0.PartitionKey == pk;
}
Run Code Online (Sandbox Code Playgroud)