Get all elements that only occur once

前端 未结 3 1910
情话喂你
情话喂你 2021-01-23 09:09

Using LINQ, can I get a list of all int elements that only occur once?

For instance

{1,2,4,8,6,3,4,8,8,2}

would become



        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-23 09:53

    list.GroupBy(i => i)
        .Where(g => g.Count() == 1)
        .Select(g => g.First());
    

提交回复
热议问题