C#对多个集合和数组的操作方法(合并,去重,判断)
作者:jingxian 时间:2021-12-11 14:02:44
在开发过程中.数组和集合的处理是最让我们担心.一般会用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#,数组,操作,集合
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
IDEA的Swing可视化插件JFormDesigner详解
2023-09-23 08:02:54
![](https://img.aspxhome.com/file/2023/6/62996_0s.jpg)
详解Spring中的Environment外部化配置管理
2023-11-23 05:24:24
![](https://img.aspxhome.com/file/2023/9/59859_0s.png)
MTK Android平台开发流程
2023-06-23 08:59:11
SpringBoot使用prometheus监控的示例代码
2021-05-29 02:37:41
![](https://img.aspxhome.com/file/2023/0/65590_0s.jpg)
JAVA回顾:封装,继承,多态
2021-09-26 20:17:59
![](https://img.aspxhome.com/file/2023/7/67627_0s.png)
将JavaDoc注释生成API文档的操作
2023-06-16 18:24:06
![](https://img.aspxhome.com/file/2023/1/61151_0s.png)
一看就懂的Android APP开发入门教程
2023-07-18 04:10:41
![](https://img.aspxhome.com/file/2023/5/82405_0s.jpg)
Java线程中sleep和wait的区别详细介绍
2021-08-27 02:23:12
教你如何使用Java输出各种形状
2023-08-21 00:46:55
如何用120行Java代码写一个自己的区块链
2023-07-17 03:44:33
Java 守护线程_动力节点Java学院整理
2023-11-28 07:51:14
![](https://img.aspxhome.com/file/2023/7/60177_0s.png)
C#几种截取字符串的方法小结
2023-07-16 09:55:10
基于java构造方法Vector删除元素源码分析
2023-11-25 14:54:45
![](https://img.aspxhome.com/file/2023/8/60238_0s.png)
java实现FTP文件上传与文件下载
2023-08-16 08:28:38
Java设计模式中的观察者模式
2021-08-22 01:27:20
![](https://img.aspxhome.com/file/2023/5/63745_0s.png)
微信公众号 网页授权登录及code been used解决详解
2023-02-06 18:49:00
![](https://img.aspxhome.com/file/2023/8/65768_0s.png)
java中sleep方法和wait方法的五个区别
2023-08-27 18:37:23
![](https://img.aspxhome.com/file/2023/5/61035_0s.webp)
一篇文章带你Java Spring开发入门
2021-06-25 10:04:15
![](https://img.aspxhome.com/file/2023/4/62724_0s.png)
Java实现简单邮件发送功能
2023-08-15 00:53:23
java.text.DecimalFormat用法详解
2022-09-30 03:02:27
![](https://img.aspxhome.com/file/2023/9/61249_0s.jpg)