还是直接上代码吧,只是一个语法糖,可以让我们的编程更自然一些。
#region Linq To Object private static void LinqToObject() { //Linq To Object List<Book> books = new List<Book>() { new Book(){Title="Asp.net本质论", Author="郝冠军", ISBN="2011-2-1-223", Price=58}, new Book(){Title="C#本质论", Author="Jack", ISBN="1234-021-112", Price=189}, new Book(){Title="人月神话", Author="Smith", ISBN="342-123-123", Price=38}, new Book(){Title="WP7代码艺术", Author="Rock", ISBN="4492-2332-113", Price=87}, }; var result = from book in books where book.Price < 100 orderby book.Price descending select book; Console.WriteLine("单价小于100元的书:"); foreach (var item in result) { Console.WriteLine(item.Title); } } #endregion