日期:2014-05-16 浏览次数:20977 次
List<User> users = new List<User>
{
new User{ No=1,Name="小王",Prize="苹果",Email="163@163.com" },
new User{ No=2,Name="小王",Prize="梨子",Email="163@163.com" },
new User{ No=3,Name="小李",Prize="香蕉",Email="126@126.com" },
new User{ No=4,Name="小张",Prize="青枣",Email="sina@sina.com" },
new User{ No=5,Name="小李",Prize="榴莲",Email="126@126.com" },
new User{ No=6,Name="小刘",Prize="火龙果",Email="sohu@sohu.com" }
};
Func<IEnumerable<User>, User> func = (a) =>
{
User user = a.First();
user.Prize = string.Join(",", a.Select(b => b.Prize));
return user;
};
users.GroupBy(a => a.Name).Select(func).ToList().ForEach(a =>
{
Console.WriteLine("{0}您好,请查收你的物品:{1}”发往“{2}", a.Name, a.Prize, a.Email);
});