C# List的并集、交集、差集
2024-10-18 20:20:35
并集---Union
集合的并集是合并两个集合的所有项,去重,如下图所示:
- List<int> ls1 = new List<int>() { 1,2,3,5,7,9 };
- List<int> ls2 = new List<int>() { 2,4,6,8,9,10};
- IEnumerable<int> unionLs = ls1.Union(ls2);
- foreach (int item in unionLs)
- {
- Console.Write("{0}\t", item);
- }
交集---Intersect
集合的交集是取集合的共同的项,如下图所示:
- List<int> ls1 = new List<int>() { 1,2,3,5,7,9 };
- List<int> ls2 = new List<int>() { 2,4,6,8,9,10};
- IEnumerable<int> intersectLs = ls1.Intersect(ls2);
- foreach (int item in intersectLs)
- {
- Console.Write("{0}\t",item);
- }
差集---Except
集合的差集是取在该集合中而不在另一集合中的所有的项,如下图所示:
List<int> ls1 = new List<int>() { 1,2,3,5,7,9 };
List<int> ls2 = new List<int>() { 2,4,6,8,9,10};
IEnumerable<int> exceptLs = ls1.Except(ls2);
foreach (int item in exceptLs)
{
Console.Write("{0}\t", item);
}
最新文章
- grunt集成自动启动
- [ZZ] 基于DirectX shader的Per-pixel lighting实现
- kill 非法用户
- bzoj3130
- mysql索引之唯一索引
- oracle之replace结合substr的使用
- Threads and Anonymous Classes in JAVA
- Monkey源码分析之事件注入
- python3中的一些小改动
- vue和react的介绍
- docker_macvlan
- 水平方向margin:auto
- java字符串拼接的几种方式
- ABAP基础二:ALV基础之ALV的简单编辑
- 6.redis的分布式锁
- python删除x天前文件及文件夹
- 中文latex去掉图片描述
- Atitit.获取验证码图片通过web
- 安装mysql8.0.11以及修改root密码、连接navicat for mysql。
- kafka运行错误:提示找不到或者无法加载主类错误解决方法
热门文章
- ios开发中如何调用苹果自带地图导航
- LeetCode 048 Rotate Image
- centos7安装Python的虚拟环境
- 课堂笔记【java JDBC】
- 转:Cookie详解
- PyQt(Python+Qt)学习随笔:QTableWidget的构造方法
- 函数与函数式编程(生成器 &;&; 列表解析 &;&; map函数 &;&; filter函数)-(四)
- DVWA SQL Injection Medium
- 个人项目(wc.exe)
- 使用Promise实现红绿灯交替重复亮