c#List中获取只出现过一次的值

   List<string> list = new List<string>() { "1", "2", "3", "3", "5" };
    //分组
    var v1 = from item in list group item by item;
    //获取只出现一次的值写法1
    var v2 = (from item in v1 where item.Count() == 1 select item.Key).ToList();
    //获取只出现一次的值写法2
    var v3 = v1.Where(p => p.Count() == 1).Select(p => { return p.Key; }).ToList();
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页