用委托来实现IEqualityComparer接口
生活随笔
收集整理的這篇文章主要介紹了
用委托来实现IEqualityComparer接口
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
轉載自詩人江湖老,原文地址
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 );} }?
總結
以上是生活随笔為你收集整理的用委托来实现IEqualityComparer接口的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MyEclipes 设置代码自动提示
- 下一篇: C#中使用SqlBulk百万级数据秒级插