摘要: static void Main(string[] args) { string[] words = { "hello", "wonderful", "linq", "beautiful", "word" }; var groups = from word in words orderby word ascending group word by word.Length into lengthGroups ... 阅读全文
posted @ 2012-06-06 14:26 HWwayne 阅读(434) 评论(0) 推荐(0) 编辑
摘要: 匿名方法 :books.Find(delegate(Bookbook){returnbook.Price<50;});Lambda表达式一个Lambda就是一个delegate,一个delegate指向一个方法 static IEnumerable<int> WithYield() { for (int i = 0; i < 20; i++) { Console.WriteLine(i.ToString()); if(i > 2) yiel... 阅读全文
posted @ 2012-04-09 15:03 HWwayne 阅读(227) 评论(0) 推荐(0) 编辑
摘要: 对象初始化器Bookbook=newBook{Title="InsideCOM",ISBN="123-456-789"};集合初始化器IList<Book> books = new List<Book> { new Book { Title = "Inside COM", ISBN = "123-456-789",Price=20 }, new Book { Title = "Inside C#", ISBN = "123-356-d89",Price 阅读全文
posted @ 2012-04-09 14:44 HWwayne 阅读(188) 评论(0) 推荐(0) 编辑
摘要: public static class MyExtensionMethods { public static IEnumerable<Product>FilterByCategory( this IEnumerable<Product> productEnum, string categoryParam) { foreach(Product prod in productEnum) { if(prod.Category == categoryParam) ... 阅读全文
posted @ 2012-03-14 16:33 HWwayne 阅读(177) 评论(0) 推荐(0) 编辑
摘要: public class Product { private string name; public int ProductID { get; set; } public string Name { get { return ProductID + name; } set { name = value; } } public string Description { get; set; } public decimal Price { get; set; } public string Category { set; get; } } publi... 阅读全文
posted @ 2012-03-14 16:09 HWwayne 阅读(114) 评论(0) 推荐(0) 编辑