Examples of lambda expressions for object-combining operations

Source: Internet
Author: User
1publicclass Person:basedomain 2 {3long _id; 4string firstName; 5string secondname; 6string comments; 7 8public Pers On () 9 {}1011public person (long id) {13this._id = id;14}15public person (long id,string firstName, String secondname) + {17this._id = Id;18this.firstname = Firstname;19this.secondname = Secondname;20 Co             mments = string.empty;21}22public person (long id,string firstName, String secondname, string comments) 23 : This (id,firstname, secondname) {25this.comments = comments;26}2728publicstring FirstName29 {3 0get {return firstName;} 31set {firstName = value;} }33publicstring SecondName34 {35get {return secondname;} 36set {secondname = value;} PNs}38publicstring Comments39 {40get {return comments;} 41set {comments = value;} }43publicoverridestring ToString () 45returnstring. Format ("FirstName: {0}\tsecondname: {1}\tcomment: {2}", This.firStname, This.secondname, this.comments); 46}47} 

View Code

Above is the simple type of test required: person

1var list = new list<person> (5); 2     list. ADD (New person (1, "Bite gold", "Cheng", "the guy with the Axe"); 3     list. ADD (New person (2, "Bite gold", "Cheng", "the guy with the Axe"); 4     list. ADD (New person (3, "Marten Cicada", "King", "3 skill is great"); 5     list. ADD (New Person (4, "Zhao June", "Lee", "Fit to Fight"); 6     list. ADD (New person (5, "Arthur", "Mao", "hard thick meat"); 7 8//to perform a de-redo operation, you need to first introduce the LINQ reference "using System.Linq; "9var result_list = list. GroupBy (obj=>obj. FirstName). Select (G=>g.first ()). ToList (); 1011foreach (var item in result_list)    {        Console.WriteLine (item);     

View Code

The above describes the lambda expression filter that uses lambda expressions to combine objects, including the contents of the lambda expression, in the hope of. NET tutorial interested friends are helpful.

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.