C# Linq 交集、并集、差集、去重

using System.Linq;

List<string> ListA = new List<string>();
List<string> ListB = new List<string>();
List<string> ListResult = new List<string>();

ListResult = ListA.Intersect(ListB).ToList();//交集

ListResult= ListA.Union(ListB).ToList(); //并集

ListResult = ListA.Except(ListB).ToList();//差集

ListResult = ListA.Distinct().ToList();//去重

Concat  将两个集合“首尾相连”

Reverse  “反转”集合中所有数的排序顺序

Sum  对集合中的数“累加求和”

Average  求集合中所有数的平均值

Max和MIn  找出集合中的“最大”和“最小”的元素

OfType  筛选出指定类型的对象

猜你喜欢

转载自blog.csdn.net/qingkaqingka/article/details/85060216