List<string> ls1 =new List<string> { "a", "b", "c", "d" };

List<string> ls2 = new List<string> { "a", "c", "d" ,"e"};

// 交集: a c d
ls1.Intersect(ls2); // 差集: b
ls1.Except(ls2); // 超集、合集:a b c d e
ls1.Union(ls2); // 串聯: a b c d a c d e
ls1.Concat(ls2);

另一種思路:

// 差集:b
ls1.Where(l => !ls2.contains(l)).ToArray();

C# 對 List<string> 取交集、補集、超集、串聯的更多相关文章

  1. [转][C#] 对List<T>取交集、连集及差集

    本文转自:http://www.cnblogs.com/shuibin/archive/2012/04/19/2457867.html 最近在專案中,剛好遇到這個需求, 需要比對兩個List,進行一些 ...

  2. 俄罗斯水手 [C#] 对List<T>取交集、连集及差集

    ※本文使用int為例,若為使用自訂之DataModel,需實作IEquatable<T>介面才能使用 1.  取交集 (A和B都有) List A : { 1 , 2 , 3 , 5 , ...

  3. C# 对List<T>取交集、连集及差集

    1. 取交集 List A :{1,5,9,3,7} List B:{1,6,8,5,3,2,9,4} var intersectedList = listA.Intersect(listB, new ...

  4. List<T>取交集、差集、并集

    1.  取交集 (A和B都有) List A : { 1 , 2 , 3 , 5 , 9 }List B : { 4 , 3 , 9 }var intersectedList = list1.Inte ...

  5. 一个JS多个数组取交集算法

    如题,多个数组中取交集(共同拥有元素),思路取第一个数组去跟每个数组中的元素对比,同时比较数据类型有救返回没有就返回null. 下面介绍到的算法数据格式是二维数组如: const parentArra ...

  6. sql server中取交集、差集和并集的语法

    这里简单总结下在SQL Server中取交集.差集和并集的语法. 交集:INTERSECT(适用于两个结果集) SELECT ID, NAME FROM YANGGB1 INTERSECT SELEC ...

  7. Swift 中 String 取下标及性能问题

    Swift 中 String 取下标及性能问题 取下标 String String 用 String.Index 取下标(subscript)得到 Character,String.Index 要从 ...

  8. SQL Server操作结果集-并集 差集 交集 结果集排序

    操作结果集 为了配合测试,特地建了两个表,并且添加了一些测试数据,其中重复记录为东吴的人物. 表:Person_1魏国人物 表:Person_2蜀国人物 A.Union形成并集 Union可以对两个或 ...

  9. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) C. String Reconstruction 并查集

    C. String Reconstruction 题目连接: http://codeforces.com/contest/828/problem/C Description Ivan had stri ...

随机推荐

  1. ACM学习历程—ZOJ3471 Most Powerful(dp && 状态压缩 && 记忆化搜索 && 位运算)

    Description Recently, researchers on Mars have discovered N powerful atoms. All of them are differen ...

  2. vue之webpack+vuecli打包生成资源相对引用路径与背景图片的正确引用

    问题描述 一般情况下,通过webpack+vue-cli默认打包的css.js等资源,路径都是绝对的 但当部署到带有文件夹的项目中,这种绝对路径就会出现问题,因为把配置的static文件夹当成了根路径 ...

  3. hdu3501Calculation 2——欧拉函数模板

    题目: Problem Description Given a positive integer N, your task is to calculate the sum of the positiv ...

  4. 用nexus搭建自己的maven私有仓库

    用nexus搭建自己的maven私有仓库  刚安装nexus时,nexus启动失败,启动不到1分钟,自动停止.后来查找到了原因: Java 6 Support EOLOracle's support ...

  5. Win10下Anaconda中安装Tensorflow

    1.安装Anaconda 下载:https://repo.continuum.io/archive/,我用的是Python 3.5 ,64位系统,所以选择的版本是Anaconda2-4.2.0-Win ...

  6. [MTC3]Cracking SHA1-Hashed Passwords

    题目地址:https://www.mysterytwisterc3.org/en/challenges/level-ii/cracking-sha1-hashed-passwords 解题关键:根据键 ...

  7. c++控制台 对齐 域宽

    包含在头文件  iomanip 设置对齐: cout<<setiosflags(ios::xxx); xxx内填参数 left左对齐 right右对齐 setiosflags还有其他选项, ...

  8. Oracle tns 协议

    下面是翻译国外的一篇博客,原文连接如下: https://thesprawl.org/research/oracle-tns-protocol/ 简介 TNS(Transparent Network ...

  9. BootStrap 概念

    网格系统中的缩写; xs   extra  small sm  smal md  middle/medium lg    large

  10. Jquery.ajax 详细解释 通过Http请求加载远程数据

    首先请看一个Jquery.ajax的例子 $.ajax({ type: "GET", url: "/api/SearchApi/GetResults", dat ...