加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – linq查询组在字符串列表中

发布时间:2020-12-15 19:39:51 所属栏目:百科 来源:网络整理
导读:参见英文答案 Remove duplicates from a ListT in C#????????????????????????????????????25个 我对cq的linq查询很新.我有一个字符串列表,我想获得一个新列表或删除所有双字符串. Liststring zipcodes = new Liststring();zipcodes.Add("1234");zipcodes.Ad
参见英文答案 > Remove duplicates from a List<T> in C#????????????????????????????????????25个
我对cq的linq查询很新.我有一个字符串列表,我想获得一个新列表或删除所有双字符串.

List<string> zipcodes = new List<string>();
zipcodes.Add("1234");
zipcodes.Add("1234");
zipcodes.Add("1234");
zipcodes.Add("4321");
zipcodes.Add("4321");

List<string> groupbyzipcodes =
(from zip in zipcodes
group zip by zip into newgroup
select newgroup.ToList());

cannot implicitly convert type
'System.collection.Generic.IEnumarable<System.Collections.Generic.List<string>'
to 'System.collections.Generic.List<string>. an explicit conversion
exists (are you missing a cast?)

解决方法

您还可以在LINQ中使用distinct关键字:

var dedupedlist = zipcodes.Distinct().ToList();

欲了解更多,请参阅https://msdn.microsoft.com/en-us/library/vstudio/bb348436(v=vs.100).aspx

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读