Predicate<T> 委托:表示定义一组条件并确定指定对象是否符合这些条件的方法。
下面的代码示例使用带有 Array.Find<T> 方法的
Predicate<T> 委托搜索
Point 结构的数组。如果 X 和 Y 字段的产品大于 100,000,则该代理所代表的方法
ProductGT10 将返回 true。
Find<T>
方法调用数组的每个元素的代理,从而在第一个满足测试条件的点停止。
using System;
using System.Drawing;
public class Example
{
public static void Main()
{
// Create an array of five Point structures.
Point[] points = { new Point(100, 200),
new Point(150, 250), new Point(250, 375),
new Point(275, 395), new Point(295, 450) };
// To find the first Point structure for which X times Y
// is greater than 100000, pass the array and a delegate
// that represents the ProductGT10 method to the static
// Find method of the Array class.
Point first = Array.Find(points, ProductGT10);
// Note that you do not need to create the delegate
// explicitly, or to specify the type parameter of the
// generic method, because the C# compiler has enough
// context to determine that information for you.
// Display the first structure found.
Console.WriteLine("Found: X = {0}, Y = {1}", first.X, first.Y);
}
// This method implements the test condition for the Find
// method.
private static bool ProductGT10(Point p)
{
if (p.X * p.Y > 100000)
{
return true;
}
else
{
return false;
}
}
}
/* This code example produces the following output:
Found: X = 275, Y = 395
*/
来自:
MSDN
分享到:
相关推荐
JDK1.8【函数式接口】【定义与使用】【源码】 ... * 函数式接口(类的定义与适应形式,只是一...断言型 Predicate<T> return:boolean * <p> * 参数使用形式 * 形式1:传递函数式接口对象 * 形式2:形参上直接写表达式
一般来说,C#在公共语言运行时(CLR)环境中系统为我们内置了一些常用的委托,包括Action类的委托、Func类的委托、Predicate<T>委托、Comparison<T>委托等等。以上这些委托的命名空间都是System,所属程序集都是 ...
本文以实例形式分析了C#中Predicate<T>与Func<T>泛型委托的用法,分享给大家供大家参考之用。具体如下: 先来看看下面的例子: static void Main(string[] args) { List<string> l = new List<string>(); l.Add(a...
主要介绍了C#中Predicate<T>与Func<T>泛型委托的用法,指出了其用法中的误区及易错点,有助于更好的理解泛型委托的用法,需要的朋友可以参考下
Java 8中缺少便捷的takeWhile(Predicate<T> predicate)方法是导致创建此库的原因。 既然Java 9具有Stream.takeWhile()支持,就没有理由将其添加为依赖项了。 该库可以创建以下java.time类的流: LocalDate通过...
最重要的几个函数接口:(Predicate<T>,Consumer<T>,Function<T>,Supplier<T>,UnaryOperator<T>,BinaryOperator<T> 类型推断 流(Stream) 和Iterator类似,是使用内部迭代,经常和Lambda表达式配合使用,可自动并行...
条件表达式(cond (<p1> <e1>) (<p2> <e2>))(cond (<p1> <e1>) (else <e2>))(if <predicate> <consequent> <alternative>)在if表达式中,结果和替代必须是单个表达式。递归和迭代递归过程的特点是一连串的递延操作。 ...
jdk1.8.0_131-的一些新特性 1.接口的扩展方法 2. 函数式接口,方法与构造方法...3.其余的一些接口:Predicate<T>接口/Optional<T>类/Function接口、Supplier 接口、Consumer 接口等 4.lamdba表达式的用法 5. 时间表达式
在 MVVM 应用程序中连接命令是痛苦的,因为您通常会有 4 个与单个命令相关的离散代码块: ViewModel 上的 Command 属性由 Command.CanExecute 引用的Func<bool>或Predicate<T> Command.Execute 引用的Action或...
rsql-jpa规范 将RSQL查询转换为org.springframework.data.jpa.domain.Specification或... < artifactId>rsql-jpa-spring-boot-starter</ artifactId> < version>X.X.X</ version> </ dependency> 将JpaS
SqlPredicate<Person> predicate = person -> person.getAge() < age> height; String sql = Lambda2Sql.toSql(predicate); // age < 100> 200 这个怎么运作 它使用为lambda构建表达式树。 然后遍历表达式树并将其...
用法您可以使用此坐标通过Maven使用此库< dependency> < groupId>org.kametic</ groupId> < artifactId>universalvisitor</ artifactId> < version>1.0</ version></ dependency>原料药UniversalVisitor的API很简单...
列表,字典集合实现接口IEnumerable <T> export interface IEnumerable < T> { elementAt ( index : number ) : T ; any ( predicate ?: ( item : T ) => boolean ) : boolean ; all ( predicate ?: ( item : T...
Predicate(谓词委托)示例,用C#写的小例子。
ScaleCube配置 ... Predicate< Path> predicate = path - > path . toString() . endsWith( " .props " ); // match by .props extension ConfigRegistrySettings settings = ConfigRegistrySettings . builde
java8 源码 java8 java8 note and code example java8新特性 Stream Api Lambda 表达式 行为参数化 ...-> ...表示一个设计类型T的布尔表达式。...Predicate<T> { boolean test(T t); } Consumer 接受泛型T的
1.先写个规则方法 private bool check(string str){ return str.EndsWith(xxx); } 2.再写个Predicate ... Predicate<string> predicate=new Predicate<string>(s =>s.StartsWith(gob.name) ); int i=_nameList
图书馆提供者 该库由 什么是LINQ异步? LINQ-Async允许您链接...public Task<IEnumerable>> MyAsyncMethod(CancellationToken cancellationToken) { List<Customer> customers = DB.GetCustomers(); var task = l
javax.persistence.criteria.Predicate.class javax.persistence.criteria.Root.class javax.persistence.criteria.Selection.class javax.persistence.criteria.SetJoin.class javax.persistence.criteria.Subquery...