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

转载于:https://www.cnblogs.com/jixinyu12345/p/4872613.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值