码迷,mamicode.com
首页 > 其他好文 > 详细

自定义比较器

时间:2017-01-20 10:59:56      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:logs   sel   hang   class   his   com   this   nbsp   int   

 1 /// <summary>
 2 /// 自定义比较器 ZhangQC 2016.11.29
 3 /// </summary>
 4 /// <typeparam name="T"></typeparam>
 5 /// <typeparam name="TV"></typeparam>
 6 public class CommonEqualityComparer<T, TV> : IEqualityComparer<T> 
 7 {
 8 private readonly Func<T, TV> _keySelector;
 9 
10 public CommonEqualityComparer(Func<T, TV> keySelector)
11 {
12 this._keySelector = keySelector;
13 } 
14 public bool Equals(T x, T y)
15 {
16 return EqualityComparer<TV>.Default.Equals(_keySelector(x), _keySelector(y)); 
17 }
18 
19 public int GetHashCode(T obj)
20 {
21 return EqualityComparer<TV>.Default.GetHashCode(_keySelector(obj)); 
22 }
23 }

 

自定义比较器

标签:logs   sel   hang   class   his   com   this   nbsp   int   

原文地址:http://www.cnblogs.com/creater/p/6322016.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!