C# 對 List<string> 取交集、補集、超集、串聯

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();
原文地址:https://www.cnblogs.com/keepee/p/9963332.html