用委托来实现IEqualityComparer<T>接口
2016-06-06 15:29
330 查看
直接上代码吧。
class FuncEqualityComparer<T> : IEqualityComparer<T> { readonly Func<T, T, bool> _comparer; readonly Func<T, int> _hash; public FuncEqualityComparer( Func<T, T, bool> comparer ) : this( comparer, t => 0 ) // NB Cannot assume anything about how e.g., t.GetHashCode() interacts with the comparer's behavior { } public FuncEqualityComparer( Func<T, T, bool> comparer, Func<T, int> hash ) { _comparer = comparer; _hash = hash; } public bool Equals( T x, T y ) { return _comparer( x, y ); } public int GetHashCode( T obj ) { return _hash( obj ); } }
相关文章推荐
- macvim一些简单的配置
- android- View工作原理(二)导致View重建原因
- 数据结构—图的存储—邻接表和邻接矩阵
- Android DefaultHttpClient 上传文件
- nginx中conf配置
- ffmpegturtor06.c做了修改,使用sdl2.0
- laravel POST请求失败的原因
- Eclipse快捷键
- iOS如何准确获取通知
- 112. Path Sum [easy] (Python)
- OpenGL学习脚印: 坐标变换过程(vertex transformation)
- hadoop fsck
- Spiral Matrix(medium)
- Android SDK与API的对应关系
- NFS挂载时出现"mount.nfs: access denied by server while mounting "的解决方法
- 一汽妈妈叫你来看跌停
- 2.Redis学习(二)redis配置
- 简单选择排序的代码实现与思考
- [深入学习C#]——IEqualityComparer<T>中GetHashCode的作用
- OCP 052 002