• c# 中List<T> union 深入理解


    http://www.cnblogs.com/qinpengming/archive/2012/12/03/2800202.html

    借用 这个兄弟的代码 我就不献丑了 。我这里指记录下

    public bool Equals(int x, int y)
      {
          //添加一个比较  返回一个bool值。如何判断两个相等
          return x == y;
      }

      public int GetHashCode(int obj)
      {//这个自己看着办吧
          throw new NotImplementedException();
      }

    image

    Union()

    这个方法将会Union(并集)两个序列(集合)连接成一个新列表(集合)

    方法定义是:

    public static IEnumerable<TSource> Union<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second)
    public static IEnumerable<TSource> Union<TSource>(this IEnumerable<TSource> first,IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)

    Intersect ()

    它将产生两个序列的交集.

    方法定义是:

    public static IEnumerable<TSource> Intersect<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second) 
    
    public static IEnumerable<TSource> Intersect<TSource>(this IEnumerable<TSource> first, Enumerable<TSource> second,IEqualityComparer<TSource> comparer) 

    Except ()

    它是从一个集合中删除存在另一个集合中的项.两个序列产生的集合差. 英文意思是:除此之外

    方法定义是:

    public static IEnumerable<TSource> Except<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second)
    public static IEnumerable<TSource> Except<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)

    实例代码分别如下:

    想看代码

    http://www.cnblogs.com/qinpengming/archive/2012/12/03/2800202.html

  • 相关阅读:
    SpringBoot-10-之初阶整合篇(下)
    09--SpringBoot之初阶整合篇(上)
    07--SpringBoot之数据库JPA(CRUD)
    go 文件操作 io
    类型断言
    多态
    golang interface
    go strcut 封装
    go struct 抽象
    poj-3280 Cheapest Palindrome (dp)
  • 原文地址:https://www.cnblogs.com/jixinyu12345/p/4872613.html
Copyright © 2020-2023  润新知