LINQ: Distinct values

前端 未结 7 1317
一生所求
一生所求 2020-11-22 16:29

I have the following item set from an XML:

id           category

5            1
5            3
5            4
5            3
5            3
<
7条回答
  •  面向向阳花
    2020-11-22 16:56

    In addition to Jon Skeet's answer, you can also use the group by expressions to get the unique groups along w/ a count for each groups iterations:

    var query = from e in doc.Elements("whatever")
                group e by new { id = e.Key, val = e.Value } into g
                select new { id = g.Key.id, val = g.Key.val, count = g.Count() };
    

提交回复
热议问题