星空网 > 软件开发 > ASP.net

LINQ的All的方法

方法All返回布尔值bool,判断集合中是否所有元素都满足某一条件,通俗一点说,就是每一个元素,均符合同一个条件,它才返回真,不然返回假。

举列,创建一个model:
LINQ的All的方法

 

source code:

LINQ的All的方法LINQ的All的方法
namespace Insus.NET.Models{  public class Book  {    public string Publishing { get; set; }    public string ISBN { get; set; }    public DateTime PublicationDate { get; set; }  }}

View Code


ASP.NET MVC的视图片中,实现:
LINQ的All的方法

source code:

LINQ的All的方法LINQ的All的方法
 Book[] books = { new Book { Publishing = "商务出版社",ISBN="13468564394",PublicationDate=Convert.ToDateTime("2016-04-13")},               new Book { Publishing = "中华出版社",ISBN="56634565746",PublicationDate=Convert.ToDateTime("2016-01-19")},               new Book { Publishing = "海天出版社",ISBN="78234235454",PublicationDate=Convert.ToDateTime("2016-03-22")},               new Book { Publishing = "云贵出版社",ISBN="46724356756",PublicationDate=Convert.ToDateTime("2016-02-22")}      };      IEnumerable<Book> query = from bk in books                   where books.All(b => b.PublicationDate > Convert.ToDateTime("2016-01-01"))                   select bk;      query.ForEach(delegate (Book b)      {        WriteLiteral(string.Format("publishing: {0}; ISBN: {1}; Publication Date: {2} <br />",                      b.Publishing,                      b.ISBN,                      b.PublicationDate.ToString("yyyy-MM-dd")));      });

View Code


更好理解,修改一下:
LINQ的All的方法

 




原标题:LINQ的All的方法

关键词:linq

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

真行国际物流:https://www.goluckyvip.com/tag/48821.html
臻顺科技:https://www.goluckyvip.com/tag/48822.html
阵亡将士纪念日:https://www.goluckyvip.com/tag/48823.html
振隆跨境电商:https://www.goluckyvip.com/tag/48824.html
振韵国际货运代理:https://www.goluckyvip.com/tag/48825.html
振智科技:https://www.goluckyvip.com/tag/48826.html
对话上海文化广场|音乐剧的剧场怎么做?:https://www.xlkjsw.com/news/90169.html
链接评论中图片排序规则:https://www.kjdsnews.com/a/1841014.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流