C#对多个集合和数组的操作方法(合并,去重,判断)
在开发过程中.数组和集合的处理是最让我们担心.一般会用for or foreach 来处理一些操作.这里介绍一些常用的集合跟数组的操作函数.
首先举例2个集合A,B.
List<int> listA = new List<int> {1,2,3,5,7,9};
List<int> listB = new List<int> {13,4,17,29,2};
listA.AddRange(listB ); 把集合A.B合并
List<int> Result = listA.Union(listB).ToList<int>(); //剔除重复项
List<int> Result = listA.Concat(listB).ToList<int>(); //保留重复项
listA.BinarySearch("1"); //判断集合中是否包含某个值.如果包含则返回0
在举例两个数组
int[] i=new int[]{1,2};
int[] j=new int[]{2,3};
List<int> r = new List<int>();
r.AddRange(i);
r.AddRange(j);
int[] c = r.ToArray(); 合并数组
int[] x=i.Union(j).ToArray<int>(); //剔除重复项
int[] x=i.Concat(j).ToArray<int>(); //保留重复项
int n = Array.BinarySearch(i,3);//判断数组中是否包含某个值.如果包含则返回0
以上这篇C#对多个集合和数组的操作方法(合并,去重,判断)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。
您可能感兴趣的文章
- 01-10C#使用Dispose模式实现手动对资源的释放
- 01-10C#实现ComboBox控件显示出多个数据源属性的方法
- 01-10C#实现获取不同对象中名称相同属性的方法
- 01-10C#操作IIS方法集合
- 01-10C#编程自学之类和对象
- 01-10C#编程和Visual Studio使用技巧(上)
- 01-10C#语句先后顺序对程序的结果有影响吗
- 01-10C#实现过滤sql特殊字符的方法集合
- 01-10C#编程实现对象与JSON串互相转换实例分析
- 01-10C#微信开发(服务器配置)
阅读排行
本栏相关
- 01-10C#通过反射获取当前工程中所有窗体并
- 01-10关于ASP网页无法打开的解决方案
- 01-10WinForm限制窗体不能移到屏幕外的方法
- 01-10WinForm绘制圆角的方法
- 01-10C#实现txt定位指定行完整实例
- 01-10WinForm实现仿视频播放器左下角滚动新
- 01-10C#停止线程的方法
- 01-10C#实现清空回收站的方法
- 01-10C#通过重写Panel改变边框颜色与宽度的
- 01-10C#实现读取注册表监控当前操作系统已
随机阅读
- 04-02jquery与jsp,用jquery
- 01-10SublimeText编译C开发环境设置
- 08-05DEDE织梦data目录下的sessions文件夹有什
- 08-05织梦dedecms什么时候用栏目交叉功能?
- 01-11Mac OSX 打开原生自带读写NTFS功能(图文
- 08-05dedecms(织梦)副栏目数量限制代码修改
- 01-11ajax实现页面的局部加载
- 01-10delphi制作wav文件的方法
- 01-10使用C语言求解扑克牌的顺子及n个骰子
- 01-10C#中split用法实例总结