C#中的委托,匿名方法和Lambda表达式用法举例

From , 5 Years ago, written in C#, viewed 95 times.
URL https://pastebin.vip/view/aa36c88c
  1.  
  2. class Customer
  3. {
  4.     public int ID { get; set; }
  5.     public static bool Test(Customer x)
  6.     {
  7.         return x.ID == 5;
  8.     }
  9. }
  10. ...
  11. List<Customer> custs = new List<Customer>();
  12. custs.Add(new Customer() { ID = 1 });
  13. custs.Add(new Customer() { ID = 5 });
  14.  
  15. custs.First(new Func<Customer, bool>(delegate(Customer x) { return x.ID == 5; }));
  16. custs.First(new Func<Customer, bool>((Customer x) => x.ID == 5));
  17. custs.First(delegate(Customer x) { return x.ID == 5; });
  18. custs.First((Customer x) => x.ID == 5);
  19. custs.First(x => x.ID == 5);
  20. custs.First(Customer.Test);
  21.  
  22.  
  23. //csharp/4884

Reply to "C#中的委托,匿名方法和Lambda表达式用法举例"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website