lambda運算式進行對象結合操作的執行個體詳解

來源:互聯網
上載者:User
1publicclass Person : BaseDomain 2    { 3long _id; 4string firstName; 5string secondName; 6string comments; 7 8public Person() 9        {}1011public Person(long id)12        {13this._id = id;14        }15public Person(long id,string firstName, string secondName)16        {17this._id = id;18this.firstName = firstName;19this.secondName = secondName;20             comments = String.Empty;21        }22public Person(long id,string firstName, string secondName, string comments)23             : this(id,firstName, secondName)24        {25this.comments = comments;26        }2728publicstring FirstName29        {30get { return firstName; }31set { firstName = value; }32        }33publicstring SecondName34        {35get { return secondName; }36set { secondName = value; }37        }38publicstring Comments39        {40get { return comments; }41set { comments = value; }42        }43publicoverridestring ToString()44        {45returnstring.Format("FirstName: {0}\tSecondName: {1}\tComment: {2}", this.firstName, this.secondName, this.comments);46        }47     }

View Code

上面是測試需要的簡單類型:Person

1var list = new List<Person>(5); 2     list.Add(new Person(1,"咬金","程","拿斧子砍人的那個傢伙"); 3     list.Add(new Person(2,"咬金","程","拿斧子砍人的那個傢伙"); 4     list.Add(new Person(3,"貂蟬","王","3技能很厲害哦"); 5     list.Add(new Person(4,"昭君","李","適合打團戰"); 6     list.Add(new Person(5,"亞瑟","毛","狠狠厚的肉"); 7 8//進行去重操作,需要先引入linq引用"using System.Linq; " 9var result_list = list.GroupBy(obj=>obj.FirstName).Select(g=>g.First()).ToList();1011foreach(var item in result_list)12    {13        Console.WriteLine(item);14     }

View Code

以上就介紹了Lambda運算式 使用lambda運算式進行對象結合的篩選操作,包括了Lambda運算式方面的內容,希望對.NET教程有興趣的朋友有所協助。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.