0.2.比较接口Default

abstract class EqualityComparer:IEqualityComparer,IEqualityComparer

0
static volatitle EqualityComparer defaultComparer; public static EqualityComparer Default{get;} //调用CreateComparer()
//Default属性就返回了8种comparer
private static EqualityComparer<T> CreateComparer()
{
    //根据不同情况返回8种默认实现的comparer        
}
## 其他的额外方法
IndexOf()
LastIndexOf()

1.GenericEqualityComparer
2.NullableEqualityComparer
3.ObjectEqualityComparer
4.ByteEqualityComparer
5.EnumEqualityComparer
6.SByteEnumEqualityComparer
7.ShortEnumEqualityComparer
8.LongEnumEqualityComparer

abstract class Comparer:IComparer,IComparer

0
public static Comparer Default{get;} //使用CreateComparer()
CreateComparer产生4个不同的派生类,根据泛型

1. ComparisonComparer<T>
2. GenericComparer<T>
3. NullableComparer<T>
4. ObjectComparer<T>
0

常见的3类比较接口

1.IComparable,IComparable 我有比较的能力,我和其他instance比

int CompareTo(T other);

2.IComparer,IComparer 我是个比较器,所以我能比较任何两个instance

int Compare(T x,T y);

3.IEqualityComparer,IEqualityComparer 强调改变了equals也要改变gethashcode

bool Equals(T x,T y);
int GetHashCode(T obj);

IEquatable 强调是否相等

bool Equals(T other); 
两个对象是否相等

IStructuralEquatable

Boolean Equals(Object other,IEqualityComparer comparer);
int GetHashCode(IQualityComparer comparer);

IStructuralComparable

Int32 CompareTo(Object other, IComparer comparer);
posted @ 2017-10-19 21:15  给我一个理由  阅读(249)  评论(0编辑  收藏  举报