zoukankan      html  css  js  c++  java
  • LINQ的All的方法

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

    举列,创建一个model:

    source code:

    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的视图片中,实现:


    source code:

     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


    更好理解,修改一下:


  • 相关阅读:
    推荐有关微信开发的十个开源项目
    curl 常见错误码
    mysql修改root密码
    BAT批处理之文件与文件夹操作代码(附xcopy命令详解)
    UE4 Pak包加载
    libcurl 文件上传
    win7右键在目录当前打开命令cmd窗口
    SQLiteDeveloper破解
    Excel替换应用
    解决局域网2级路由互相连接共享的问题
  • 原文地址:https://www.cnblogs.com/insus/p/5385754.html
Copyright © 2011-2022 走看看