zoukankan      html  css  js  c++  java
  • 对象相等性和同一性

    概念同一性:同一个引用

    相等性:所有部分都相等,但并一定是同一个引用。包含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.

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

    以上两条都满足,则相等

  • 相关阅读:
    Linux的chattr与lsattr命令详解
    ls命令
    linux PS1
    which,whereis,locate,find
    linux下的文件结构
    Linux各种命令
    PHP将两个二维数组合并为一个二维数组的方法
    vagrant virtualbox VM inaccessible解决办法
    常用Mysql查询语句
    删除数组元素并重建索引的方法
  • 原文地址:https://www.cnblogs.com/qook/p/5421044.html
Copyright © 2011-2022 走看看