csharp-linqmerge 发表于 2015-12-01 | 更新于 2019-05-09 | 评论数: | 阅读次数: C# Linq合并List中的对象1234567891011121314151617181920212223242526272829303132333435363738394041424344454647static void Main(string[] args){ List<Person> pList = new List<Person>(); Person person1 = new Person() { FirstName = "john", LastName = "wonder" }; Person person3 = new Person() { FirstName = "john2", LastName = "wonder22" }; Person person4 = new Person() { FirstName = "john2", LastName = "wonder2233" }; pList.Add(person1); pList.Add(person3); pList.Add(person4); var pMergeList= pList.ToLookup(x => x.FirstName).Select(x => x.Aggregate((p1, p2) => new Person{ FirstName = p1.FirstName, LastName = p1.LastName + ";"+ p2.LastName } )).ToList(); foreach (var item in pMergeList) { Console.WriteLine("FirstName:" + item.FirstName); Console.WriteLine("LastName:" + item.LastName); } Console.Read(); } class Person { public string FirstName { get; set; } public string LastName { get; set; } } class PersonModel { public string FirstName { get; set; } public string LastNameList { get; set; } } 欢迎关注我的公众号:沉迷Spring 本文作者: John | 微信公众号【沉迷Spring】 本文链接: http://johnwonder.github.io/2015/12/01/csharp-linq-merge/ 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!