是谓词吗?在 .NET 3.0+ 中不可用;
Predicate 在 .NET 中的任何地方都可用吗?来自 MSDN http://msdn.microsoft.com/en-us/library/ bfcke1bz.aspx,我在任何地方都没有看到谓词。我看到一个匿名返回一个布尔值,但没有泛型或“谓词”关键字。
Is Predicate available anywhere in .NET? From MSDN http://msdn.microsoft.com/en-us/library/bfcke1bz.aspx, I don't see a Predicate anywhere. I see an anonymous that returns a boolean but no generics or a "Predicate" keyword.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以将其用作类型然后将其传入,而不是内联谓词的委托。这是一个示例:
编辑:要使用现有方法声明谓词,您可以使用:
替代方案,更常见的是:
编辑:在另一篇文章的评论中回答您的其他问题,委托是一种定义方法签名的类型,可用于将方法传递给其他人方法作为参数。如果您对 C++ 有一定的了解,它们就像函数指针。有关委托的详细信息,请查看此 MSDN 页面。
Rather than inline a delegate for the predicate, you could use it as a type then pass it in. Here's an example:
EDIT: to declare the Predicate with an existing method, you would use:
The alternatives, which are more common, would've been:
EDIT: to answer your other question in a comment to another post, a delegate is a type that defines a method signature and can be used to pass methods to other methods as arguments. If you're somewhat familiar with C++, they are like function pointers. For more info on delegates check out this MSDN page.
Predicate
是System
命名空间中的一个类型(更具体地说,是委托类型)。这不是一个关键字。Predicate
is a type (more specifically, a delegate type) in theSystem
namespace. It’s not a keyword.它肯定是在 3.0 中...请参阅该 MSDN 页面的底部:
版本信息
.NET Framework
受支持的版本:3.5、3.0、2.0
只要您“使用系统”,您就应该看到它。
It is definitely in 3.0... see the bottom of that MSDN page:
Version Information
.NET Framework
Supported in: 3.5, 3.0, 2.0
As long as you are 'using System' you should see it.
MSDN 上的该页面是关于 Predicate(T) 委托的,它正如它所说:
That page on MSDN is about the Predicate(T) Delegate, which as it states:
谓词类型出现在 3.5 和 4.0 中。
The Predicate Type is there in 3.5 and in 4.0.