3 回答

TA貢獻(xiàn)1844條經(jīng)驗(yàn) 獲得超8個(gè)贊
以下是我對(duì)[IMNSHO]關(guān)鍵修復(fù)默認(rèn)的散列策略: -
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 );
? ? }
}
- 3 回答
- 0 關(guān)注
- 414 瀏覽
添加回答
舉報(bào)