zoukankan      html  css  js  c++  java
  • 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  筛选出指定类型的对象

  • 相关阅读:
    164-268. 丢失的数字
    163-20. 有效的括号
    Sword 30
    Sword 29
    Sword 27
    Sword 25
    Sword 24
    Sword 22
    Sword 21
    Sword 18
  • 原文地址:https://www.cnblogs.com/huangj/p/9120522.html
Copyright © 2011-2022 走看看