[置顶] Linq模糊查询

 
List<Book> books = new List<Book>() {
   new Book { Id=1, Title="LINQ in Action" },
   new Book {Id=2,  Title="LINQ for Fun" },
   new Book {Id=3,  Title="LINQ Action Fun" },
   new Book {Id=4,  Title="LINQ Action Fun1" },
   new Book {Id=5,  Title="LINQ Action2 Fun" },
   new Book {Id=6,  Title="LINQ Action3 Fun4" },
   new Book {Id=7,  Title="LINQ  Fun5" },
   new Book {Id=8,  Title="LINQ  Fun55" },
   new Book {Id=9,  Title="LINQ  Fun445" },
   new Book {Id=10,  Title="Action Extreme LINQ" }
  };
  
        //模糊查询
        var titles = from book in books
                     where book.Title.Contains("Action")
                     orderby book.Id descending
                     select book;
  
        foreach (var item in titles)
        {
            int id = item.Id;
  
        }
        //分页
        //        Skip(100)代表跳过100行后.从第101行开始分页;
        //        take(10)表示多少行分页;
  
        var pageInfos = titles.Skip(0).Take(2);
        foreach (var item in pageInfos)
        {
            int id = item.Id;
        }

你可能感兴趣的:(action,LINQ,fun,books)