Lambda expressions are used to filter objects.

Source: Internet
Author: User

Lambda expressions are used to filter objects.
1 public class Person: BaseDomain 2 {3 long _ id; 4 string firstName; 5 string secondName; 6 string comments; 7 8 public Person () 9 {} 10 11 public Person (long id) 12 {13 this. _ id = id; 14} 15 public Person (long id, string firstName, string secondName) 16 {17 this. _ id = id; 18 this. firstName = firstName; 19 this. secondName = secondName; 20 comments = String. empty; 21} 22 public Person (long id, string firstName, string secondName, string comments) 23: this (id, firstName, secondName) 24 {25 this. comments = comments; 26} 27 28 public string FirstName29 {30 get {return firstName;} 31 set {firstName = value ;} 32} 33 public string SecondName34 {35 get {return secondName;} 36 set {secondName = value;} 37} 38 public string Comments39 {40 get {return comments ;} 41 set {comments = value;} 42} 43 public override string ToString () 44 {45 return string. format ("FirstName: {0} \ tSecondName: {1} \ tComment: {2}", this. firstName, this. secondName, this. comments); 46} 47}View Code

The above is a simple type required for testing: Person

1 var list = new List <Person> (5); 2 list. add (new Person (1, "Bite gold", "Cheng", "guy with an ax"); 3 list. add (new Person (2, "Bite gold", "Cheng", "guy with an ax"); 4 list. add (new Person (3, "mink Chan", "King", "3 skills very powerful"); 5 list. add (new Person (4, "Zhao Jun", "Li", "suitable for group battles"); 6 list. add (new Person (5, "Arthur", "Mao", ""); 7 8 // deduplication, you must first introduce the "using System. linq; "9 var result_list = list. groupBy (obj => obj. firstName ). select (g => g. first ()). toList (); 10 11 foreach (var item in result_list) 12 {13 Console. writeLine (item); 14}View Code

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.