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.

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

    以上两条都满足,则相等

  • 相关阅读:
    HDU 1251 统计难题(字典树模板题)
    POJ 1182 食物链(带权并查集)
    FJUT 2351 T^T的图论(并查集)
    10.QT程序框架与connect
    9.正则表达式
    8.QList QMap QVariant
    7.treeview
    6.图形化列表查询显示
    5.listview(QStringList QStringListModel)
    4.QList
  • 原文地址:https://www.cnblogs.com/qook/p/5421044.html
Copyright © 2011-2022 走看看