我有这个:
class MyContact
{
public string firstname { get; set; }
public string lastname { get; set; }
}
MyContact c1 = new MyContact() { firstname = "Filipe", lastname = "Silva" };
MyContact c2 = new MyContact() { firstname = "Filipe", lastname = "Oliveira" };
MyContact c3 = new MyContact() { firstname = "Maria", lastname = "Santos" };
MyContact c4 = new MyContact() { firstname = "Jose", lastname = "Ricardo" };
MyContact c5 = new MyContact() { firstname = "Joao", lastname = "Roberto" };
MyContact c6 = new MyContact() { firstname = "Joao", lastname = "Augusto" };
MyContact c7 = new MyContact() { firstname = "Joao", lastname = "Mario" };
var cList = new List<MyContact>();
cList.AddRange(new MyContact[] { c1, c2, c3, c4, c5, c6, c7 });
我需要 GroupBy firstname 并连接所有姓氏。
这是我的预期结果:
Filipe - Silva|Oliveira
Maria - Santos
Jose - Ricardo
Joao - Roberto|Augusto|Mario