Get all elements that only occur once

前端 未结 3 1908
情话喂你
情话喂你 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 10:04

    var result =
        from x in xs
        group xs by x into grp
        where grp.Count() == 1
        select grp.Key;
    

    like that?

    50seconds too late ... :/

提交回复
热议问题