Liststring[] 如何去重

 

List<string[]> 如何去重,代码如下:

static void Main(string[] args){List<string[]> list = new List<string[]>();list.Add(new string[] { "1", "2", "3" });list.Add(new string[] { "1" });list.Add(new string[] { "1", "2", "3" });list.Add(new string[] { "1" });list.Add(new string[] { "1" });List<string> strList = new List<string>();foreach (var item in list){string s = string.Join(",", item);strList.Add(s);}//要删除的元素的下标集合List<int> removeIndexList = new List<int>();if (list.Count >= 2)  //确保下标i不越界
            {string currentStr = string.Empty;for (int i = 0; i < strList.Count; i++){currentStr = strList[i];for (int j = i + 1; j < strList.Count; j++){if (currentStr == strList[j]){//添加到要删除的索引集合removeIndexList中
                            removeIndexList.Add(j);}}}removeIndexList = removeIndexList.Distinct().ToList();////去除重复的索引//添加到要删除的对象集合List<string[]> removeList = new List<string[]>();foreach (var index in removeIndexList){removeList.Add(list[index]);}//遍历要删除对象的集合,删除原集合中的对象foreach (var item in removeList){list.Remove(item);}foreach (var item in list){string s = string.Join(",", item);Console.WriteLine(s);}Console.ReadKey();}}
View Code

 

运行截图如下:

 

 

那么问题又来了,挖掘机技术……呸! 如果是List<List<string[]>>的集合又该如何去重呢?

原理是一样的把List<string[]>变成字符串,装到List<string>中,根据List<sting>重复的元素的下标索引,删除原集合中重复的元素,

代码如下:

 static void Main(string[] args){List<string[]> list = new List<string[]>();list.Add(new string[]{"1","2","3"});list.Add(new string[] { "1","2" ,"3"});list.Add(new string[] { "1" });list.Add(new string[] { "1" });list.Add(new string[] { "1" });List<string[]> list2 = new List<string[]>();list2.Add(new string[] { "1", "2", "3", "4", "5" });list2.Add(new string[] { "1", "2", "3" });list2.Add(new string[] { "1" });list2.Add(new string[] { "1" });list2.Add(new string[] { "1" });List<string[]> list3 = new List<string[]>();list3.Add(new string[] { "1", "2", "3" });list3.Add(new string[] { "1", "2", "3" });list3.Add(new string[] { "1" });list3.Add(new string[] { "1" });list3.Add(new string[] { "1" });List<string[]> list4= new List<string[]>();list4.Add(new string[] { "1", "2", "3", "4", "5" });list4.Add(new string[] { "1", "2", "3" });list4.Add(new string[] { "1" });list4.Add(new string[] { "1" });list4.Add(new string[] { "1" });List<List<string[]>> superList = new List<List<string[]>>();//集合list和集合list3是相同,list2和list4相同,并且list4添加了2次
            superList.Add(list);superList.Add(list2);superList.Add(list3);superList.Add(list4);superList.Add(list4);List<string> strList = new List<string>();foreach (var d in superList){StringBuilder sb = new StringBuilder();foreach (var dd in d){string s = string.Join(",", dd);sb.Append(s);}string str = sb.ToString();strList.Add(str); //把superList中每个子元素拼接成一条字符串放到strList中
            }//要删除的元素的下标集合List<int> removeIndexList = new List<int>();if (strList.Count >= 2) //有2个以上的元素才有可能出现重复
            {string currentStr = string.Empty;for (int i =0; i < strList.Count; i++){currentStr = strList[i];for (int j =i+1; j < strList.Count; j++){if (currentStr == strList[j]){//添加到要删除的索引集合removeIndexList中
                            removeIndexList.Add(j);}}}}removeIndexList = removeIndexList.Distinct().ToList();//去除重复的索引//要删除的对象集合List<List<string[]>> superRemoveList = new List<List<string[]>>();foreach (var index in removeIndexList){superRemoveList.Add(superList[index]);}foreach (var item in superRemoveList){superList.Remove(item);}Console.WriteLine(superList.Count());Console.ReadKey();}
View Code

 

 

运行截图如下:

 

转载于:https://www.cnblogs.com/527289276qq/p/4590395.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/288600.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

前端大屏模板分享-可在线浏览

1. 前言站长以前介绍过这个开源项目&#xff0c;最近又有人在问&#xff0c;索性挂在Dotnet9网站上&#xff0c;方便大家在线浏览&#xff0c;先声明&#xff0c;模板来自下面的仓库&#xff1a;仓库名&#xff1a;大屏数据展示模板作者&#xff1a;lvyeyou开源协议&#xff1a…

音视频基本概念和FFmpeg的简单入门

写在前面最近正好有音视频编辑的需求&#xff0c;虽然之前粗略的了解过FFmpeg不过肯定是不够用的&#xff0c;借此重新学习下&#xff1b;基本概念容器/文件(Conainer/File)&#xff1a;即特定格式的多媒体文件&#xff0c;一般来说一个视频文件是由视频&#xff0c;音频&#…

Windows Live Writer 的昨日荣光

今天这一篇文章&#xff0c;想写一写Windows Live Writer这款博客编辑器&#xff08;最早的一个版本是2007年发布的&#xff09;。毫不夸张地说&#xff0c;这是为数不多的几款所见即所得的编辑器之一&#xff0c;当然&#xff0c;它的运行速度慢也是一个众所周知的问题。作为一…

猎豹MFC--CMenu菜单 设置主菜单 给主对话框设置菜单 设置快捷菜单

设置主菜单&#xff08;不是快捷菜单&#xff09;&#xff1a;给主对话框设置菜单&#xff1a;效果如下&#xff1a;修改菜单的ID使之便于记忆&#xff1a;给菜单添加消息处理&#xff1a;添加处理代码&#xff1a;设置快捷菜单&#xff1a;打开对话框&#xff0c;属性添加消息…

领域事件和集成事件没那么高大上

前言随着系统架构的演变&#xff0c;有很多名词也随之涌现&#xff0c;如&#xff1a;微服务、灰度发布、资源隔离、容器、领域/集成事件等&#xff0c;听着的确高大上&#xff0c;让很多小伙伴有一种无法征服的感觉&#xff1b;其实很多东西可能之前就已经用过了&#xff0c;只…

20142335郝昊第三周学习总结

20145335郝昊 《Java程序设计》第3周学习总结 教材学习内容总结 第四章 类与对象 定义&#xff1a; 对象&#xff08;Object&#xff09;&#xff1a;存在的具体实体&#xff0c;具有明确的状态和行为。 类&#xff08;Class&#xff09;:具有相同属性和行为的一组对象的集合&…

hierarchyviewer

为什么80%的码农都做不了架构师&#xff1f;>>> 学习monkeyrunner&#xff0c;无奈怎么都无法启动activity&#xff0c;人家告诉我.hierarchyviewer这个工具可以&#xff0c;今天我就开始学习这个了&#xff0c;但愿有所帮助啊。http://www.xuebuyuan.com/2104811.…

linux之如何查看哪些进程在使用某一个so

1 问题 在我们服务端&#xff0c;我们怎么查看哪些进程在使用某一个so 2 解决办法 lsof **.so 很明显&#xff0c;我们的apache的httpd几个进程在使用这个so

“威胁情报”在手,反黑客终于有地图了!

安全是一场攻防战&#xff0c;那么&#xff0c;如今这样的攻防战发展到了什么level了呢&#xff1f;日前&#xff0c;安全领域的大神们进行了一场闭门研讨 。大神们表示&#xff0c;如今要想保证自己的安全&#xff0c;你不仅需要武器&#xff0c;还需要侦察兵&#xff0c;需要…

winform插入时间类型数据到oracle数据库,winform操作访问Oracle 10g数据库,并自动填充到DataGridView...

使用oracle的ODP.NET是官方推荐&#xff0c;而且相对简单的方法。官方指导文档&#xff1a;http://www.oracle.com/technetwork/cn/testcontent/o23odp-084525-zhs.htmlapp.configForm1.aspx.csusing System;using System.Collections.Generic;using System.ComponentModel;usi…

print的describe的展示全部数据_大数据项目中的QA需要迎接新的挑战

根据IDC全球半年度大数据和分析支出指南的最新预测&#xff0c;到2022年全球大数据和业务分析解决方案的收入将达到2600亿美元。在大数据和业务分析解决方案上投资增长最快的行业包括银行&#xff08;复合年增长率13.3%&#xff09;、医疗、保险、证券和投资服务、电信&#xf…

Enum枚举类型实战总结,保证有用!

一般在我们开发时如果能使用枚举罗列的&#xff0c;一般都会定义一个枚举类型。将枚举类型作为方法的参数&#xff0c;可以方便的进行调用&#xff0c;给我们带来不少的便利&#xff0c;当然有时候它还不如直接用一个int类型带来&#xff0c;带来一定灵活性。但只要能满足业务咱…

linux c之通过popen执行shell命令

1 popen介绍 我是在ubuntu上面进行man popen的,解释如下 这个函数通过创建一个管道通过fork一个进程,然后执行一个command,因为在管道中,所以数据流是单向的,然后type一般只能是读“r”或者写“w”,返回值在IO流里面,用了popen之后我们要记得用pclose函数。 2 使用 #inc…

用java调用.net的wcf其实还是很简单的

前些天和我们的一个邮件服务商对接&#xff0c;双方需要进行一些通讯&#xff0c;对方是java团队&#xff0c;而作为.net团队的我们&#xff0c;只能公布出去的是一个wcf的basicbinding&#xff0c;想不 到问题来了&#xff0c;对方不知道怎么去调用这个basic&#xff0c;可能他…

DbTool 2.0.0 Released

DbTool 2.0.0 ReleasedIntroDbTool 一个支持 DbFirst、ModelFirst 和 CodeFirst 的数据库小工具。DbFirst 是根据数据库中的表信息生成代码中的 Model&#xff0c;以及生成数据表结构文档ModelFirst 是根据数据表信息或者数据表结构文档生成创建数据库的脚本CodeFirst 是指根据…

[蓝桥杯] 蚂蚁感冒

[蓝桥杯] 蚂蚁感冒 峰值内存消耗 < 256M  CPU消耗 < 1000ms 【题目描述 - Problem Description】 长100厘米的细长直杆子上有n只蚂蚁。它们的头有的朝左&#xff0c;有的朝右。 每只蚂蚁都只能沿着杆子向前爬&#xff0c;速度是1厘米/秒。 当两只蚂蚁碰面时&#xff0…

Source Insight之Relation Window Properties配置和一些快捷键

1 Source Insight之Relation Window Properties配置 我们先点击source Insight的这个地方 然后鼠标右键&#xff0c;点击Relation Window Properties&#xff0c;配置如下 2 快捷键 目前就我知道的 1&#xff09;按亮和按熄这个变量 shift F8 2&#xff09;跳转到具体一行…

ArcGIS 10.2 Calculate Value(Data Management) 工具的使用

1、概述 Calculate Value tool returns a value based on a specified Python expression. 计算值工具返回一个基于特定Python表达式的值。 工具位置:ToolBox→Data Management Tools→General→Calculate Value 2、注意事项 (1)该工具只能用于MoudleBuilder,而不能用于Py…

vb6编写dll读取dat文件_【STM32Cube_15】使用硬件I2C读取温湿度传感器数据(SHT30)...

寻求更好的阅读体验&#xff0c;请移步Mculover666的个人博客&#xff1a;【STM32Cube_15】使用硬件I2C读取温湿度传感器数据&#xff08;SHT30&#xff09;​www.mculover666.cn本篇详细的记录了如何使用STM32CubeMX配置STM32L431RCT6的硬件I2C外设&#xff0c;读取SHT30温湿度…

tcp/ip ---数据封装过程

转载于:https://www.cnblogs.com/saryli/p/5306721.html