GroupBy使List <t>成为List <list <t>&gt;

时间:2017-06-22 11:48:41

标签: c# linq

我有以下内容:

List<Something> somethings = new List<Something>()
{
    new Something(){ Connection = "Bob" },
    new Something(){ Connection = "Bob" },
    new Something(){ Connection = "Peter" },
}

我想最终得到以下结论:

List<List<<Something>> groupedSomethings = new List<List<<Something>>()
    new List<Something>()
    {
        new Something(){ Connection = "Bob" },
        new Something(){ Connection = "Bob" }
    }
    new List<Something>()
    {
        new Something(){ Connection = "Peter" },
    }
}

我无法正确获得Linq声明。

我想它看起来像这样:

List<List<<Something>> groupedSomethings = somethings
    .GroupBy(x => x.Connection)
    .SelectMany(somethings => new List<Something>());

你会怎么做?

1 个答案:

答案 0 :(得分:6)

您可以使用$ .get("/getProces") .then((res) => res.error ? Promise.reject(res) : Promise.resolve(res)) .then((data) => { for (var i = 0; i < data.message.length; i++) { var obj = data.message[i] console.log(obj.processen_id) } }) ,然后从该组中获取值:

GroupBy