转换为LINQ lambda表达式4

时间:2015-01-23 16:00:13

标签: c# linq lambda

如何转换为lambda:

var source = new Item[]{
                    new Item { Key = "A", ID = 1, Text = "Hello" },
                    new Item { Key = "A", ID = 2, Text = "World" },
                    new Item { Key = "B", ID = 2, Text = "Bar" },
                    new Item { Key = "B", ID = 1, Text = "Foo" }
                };

var results = (from r in source
                           group r by r.Key.ToString() into g
                           select new
                           {
                               g.Key,
                               Data = string.Join("", g.OrderBy(s => s.ID).Select(s => s.Text))
                           });

可以转换?

感谢您的回答

1 个答案:

答案 0 :(得分:1)

这个怎么样?

var results = source.GroupBy(r => r.Key).Select(g => new
{
    g.Key,
    Data = string.Join("", g.OrderBy(s => s.ID).Select(s => s.Text))
});
相关问题