说明:表示定义一组条件并确定指定对象是否符合这些条件的方法。此委托由 Array 和 List 类的几种方法使用,用于在集合中搜索元素。

var predicate = new Predicate<int>(num=>num%2==0);
var list = new List<int>();
for (int i = 0; i < 20; i++)
{
list.Add(i);
}

var result = list.FindAll(predicate).ToArray();

for (int i = 0; i <result.Length ; i++)
{

Console.WriteLine($"{i}位:{result[i]}");
}

Predicate<DateTime> predicateTime;
predicateTime = a => a.AddDays(2).Day == DateTime.Now.Day;
Console.WriteLine(predicateTime(DateTime.Now.AddDays(-3)));

Console.WriteLine(DateTime.Now);
Console.ReadKey();

Func<T, bool> :表示有传入T类型的参数,返回值为bool的委托
Predicate<T>:表示有传入T类型的参数,返回值为bool的委托
 
 
  Delegate至少0个参数,至多32个参数,可以无返回值,也可以指定返回值类型。这个是祖宗。
  Func可以接受0个至16个传入参数,必须具有返回值。
  Action可以接受0个至16个传入参数,无返回值。
  Predicate只能接受一个传入参数,返回值为bool类型

---------------------

本文来自 rye_grass 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/rye_grass/article/details/66041423?utm_source=copy

 
  Func<T, bool>是对delegate bool Predicate<T>(T obj)的简化,
  Predicate<T>又是对Func<T, bool>的简化,
  其实,就是一个东西。
  List<T>中的方法应该统一参数

可以改善以前的判断逻辑 提高代码重用率

---一些内容由网络搬运而来

Predicate--入门简介的更多相关文章

  1. 掌握 Ajax,第 1 部分: Ajax 入门简介

    转:http://www.ibm.com/developerworks/cn/xml/wa-ajaxintro1.html 掌握 Ajax,第 1 部分: Ajax 入门简介 理解 Ajax 及其工作 ...

  2. MongoDB入门简介

    MongoDB入门简介 http://blog.csdn.net/lolinzhang/article/details/4353699 有关于MongoDB的资料现在较少,且大多为英文网站,以上内容大 ...

  3. (转)Web Service入门简介(一个简单的WebService示例)

    Web Service入门简介 一.Web Service简介 1.1.Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从I ...

  4. NodeJS入门简介

    NodeJS入门简介 二.模块 在Node.js中,以模块为单位划分所有功能,并且提供了一个完整的模块加载机制,这时的我们可以将应用程序划分为各个不同的部分. const http = require ...

  5. ASP.NET Core学习之一 入门简介

    一.入门简介 在学习之前,要先了解ASP.NET Core是什么?为什么?很多人学习新技术功利心很重,恨不得立马就学会了. 其实,那样做很不好,马马虎虎,联系过程中又花费非常多的时间去解决所遇到的“问 ...

  6. webservice入门简介

    为了梦想,努力奋斗! 追求卓越,成功就会在不经意间追上你 webservice入门简介 1.什么是webservice? webservice是一种跨编程语言和跨操作系统平台的远程调用技术. 所谓的远 ...

  7. Web Service入门简介(一个简单的WebService示例)

    Web Service入门简介 一.Web Service简介 1.1.Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从I ...

  8. Android精通教程-第一节Android入门简介

    前言 大家好,给大家带来Android精通教程-第一节Android入门简介的概述,希望你们喜欢 每日一句 If life were predictable it would cease to be ...

  9. Nginx入门简介

    Nginx入门简介 Nginx 介绍 Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一个IMAP/POP3/SMTP服务.Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二 ...

  10. Markdown入门简介

    参考 http://sspai.com/25137 作者: Te_Lee 文章来源: 少数派 Markdown入门简介(使用工具Haroopad) 一.使用的工具----haroopad(http:/ ...

随机推荐

  1. 基于vue-cli配置移动端自适应

    移动端自适应:手淘的 lib-flexible + rem 配置 flexible 安装 lib-flexible 在命令行中运行如下安装: 1 npm i lib-flexible --save 引 ...

  2. 什么是 ajax?----异步 javascript 和 xml

    GET 用于请求服务器数据 POST 用于上传数据到服务器,或者修改服务器数据 ajax 异步通信,实现页面的局部刷新,按需获取数据,节约带宽,带来更好的用户体验 客户端与服务器在不必刷新浏览器的情况 ...

  3. Json----简单介绍

    Json 先分享一个网站http://www.bejson.com/,这个是用来检测Json文件的错误的,Json文件一般不好查找错误. 看懂Json只需要四句话: 对象表示为键值对 数据由逗号分隔 ...

  4. Java笔试题:给定一个ReadOnlyClass的对象roc,能否把这个对象的age值改成30?

    在Java笔试面试中,经常会遇到代码题,今天我们就来看一则Java代码笔试题. 有如下代码: Class ReadOnlyClass { private Integer age=20; public ...

  5. [Swift]LeetCode85. 最大矩形 | Maximal Rectangle

    Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and ...

  6. [Swift]LeetCode157.用Read4来读取N个字符 $ Read N Characters Given Read4

    The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actua ...

  7. [Swift]LeetCode204. 计数质数 | Count Primes

    Count the number of prime numbers less than a non-negative number, n. Example: Input: 10 Output: 4 E ...

  8. [SQL]LeetCode595. 大的国家 | Big Countries

    SQL架构 Create table If Not Exists World (name varchar(), continent varchar(), area int, population in ...

  9. [Swift]LeetCode830. 较大分组的位置 | Positions of Large Groups

    In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...

  10. Python内置函数(33)——int

    英文文档: class int(x=0) class int(x, base=10) Return an integer object constructed from a number or str ...