the important thing is not to stop questioning

导航

 

概念同一性:同一个引用

相等性:所有部分都相等,但并一定是同一个引用。包含4个特征

1、自反性,自已等于自己

2、对称性,x=y,y也一定等于x

3、可传递性,x=y,y=z,则x=z

4、一致性,x,y都不变的情况下,比较结果不能变

Object.Equals 方法

The type of comparison between the current instance and the obj parameter depends on whether the current instance is a reference type or a value type.

比较的第一步是判断是引用类型还是值类型

1、If the current instance is a reference type, the M:System.Object.Equals(System.Object) method tests for reference equality, and a call to the M:System.Object.Equals(System.Object) method is equivalent to a call to the M:System.Object.ReferenceEquals(System.Object,System.Object) method. Reference equality means that the object variables that are compared refer to the same object.

如果是引用类型,则调用System.Object.ReferenceEquals方法

2、If the current instance is a value type, the M:System.Object.Equals(System.Object) method tests for value equality. Value equality means the following

1)The two objects are of the same type.

看是否是同一类型

2)The values of the public and private fields of the two objects are equal.

比较公有和私有字段是否相等

以上两条都满足,则相等

posted on 2016-04-22 13:52  qook  阅读(241)  评论(0编辑  收藏  举报