When we normally think of "equality",we're thinking of value equality - the idea that the values stored in two different objects are the same. This is also known as equivalence. For example, if we have two different variables that both store an integer value of 12, we say that the variables are equal.

 int i1 = ;
int i2 = ; // Value equality - evaluates to true
bool b2 = (i1 == i2);

The variables are considered "equal", even though we have two different copies of the integer value of 12.

We can also talk about reference equality, or identity - the idea that two variables refer to exactly the same object in memory.

 Dog d1 = new Dog("kirby", );
Dog d2 = new Dog("kirby", );
Dog d3 = d1; bool b1 = (d1 == d2); // Evaluates to false
bool b2 = (d1 == d3); // Evaluates to true

In C#, the == operator defaults to using value equality for value types and reference equality for reference types.

原文地址:#402 - Value Equality vs. Reference Equality

【转载】#402 - Value Equality vs. Reference Equality的更多相关文章

  1. [Training Video - 4] [Groovy] Object equality and variable equality check

    def x=2 def y=3 if(x == y){ log.info "equal" }else{ log.info "not equal" // prin ...

  2. 关于C#你应该知道的2000件事

    原文 关于C#你应该知道的2000件事 下面列出了迄今为止你应该了解的关于C#博客的2000件事的所有帖子. 帖子总数= 1,219 大会 #11 -检查IL使用程序Ildasm.exe d #179 ...

  3. First-class function

    https://en.wikipedia.org/wiki/First-class_function In computer science, a programming language is sa ...

  4. C# ==、Equals、ReferenceEquals 区别与联系 (转载)

    相关概念 .Net提供了ReferenceEquals.静态Equals,具体类型的Equals以及==操作符这四个判等函数.但是这四个函数之间有细微的关系,改变其中一个函数的实现会影响到其他函数的操 ...

  5. 【转载】C#相等性比较

    本文阐述C#中相等性比较,其中主要集中在下面两个方面 ==和!=运算符,什么时候它们可以用于相等性比较,什么时候它们不适用,如果不使用,那么它们的替代方式是什么? 什么时候,需要自定一个类型的相等性比 ...

  6. java8-Optional的引入

    背景 NPE问题,100%的Java程序员都碰到,并且曾经是心中的痛. 1965年英国TonyHoare引入了Null引用,后续的设计语言包括Java都保持了这种设计. 一个例子 业务模型 Perso ...

  7. java8-新的日期API

    背景 java的日期和时间API设计不理想,java8引入新的时间和日期API就是为了解决这个问题. 老的日期API的核心类 缺点 Date 月从0开始,年最小从1900年开始,没有时区的概念 Cal ...

  8. Java-Class-FC:java.time.Duration

    ylbtech-Java-Class-FC:java.time.Duration 1.返回顶部   2.返回顶部   3.返回顶部 1. /* * Copyright (c) 2012, 2015, ...

  9. Java-Class-FC:java.util.Optional

    ylbtech-Java-Class-FC:java.util.Optional 1.返回顶部   2.返回顶部 1.1. import java.util.Optional; 1.2.1. @Api ...

随机推荐

  1. mysql隔离级别与锁,接口并发响应速度的关系(1)

    默认隔离级别:可重复读 原始数据 | id | name | addr | | nick | NULL | 事务1 事务2 start transaction start transaction ; ...

  2. 工作必备,五分钟如何搞定Excel甘特图

    工作必备,五分钟如何搞定Excel甘特图  https://www.sohu.com/a/212628821_641930 EXCEL中如何给图表添加标题 1.选中图表 >> [布局] 菜 ...

  3. Yii2 前台控制器访问权限控制

    class BaseController extends Controller { public function behaviors() { return [ 'access' => [ 'c ...

  4. Linux环境搭建禅道项目管理工具

    1.开源版安装包下载 [root@iZbp ~]# wget http://dl.cnezsoft.com/zentao/9.0.1/ZenTaoPMS.9.0.1.zbox_64.tar.gz 2. ...

  5. epoll 中ET与LT 关于读取处理 复习

    https://zhuanlan.zhihu.com/p/21374980 =============================================== https://zhuanl ...

  6. MapReduce的主要的六个类讲解

    a.InputFormat类.该类的作用是将输入的文件和数据分割成许多小的split文件, 并将split的每个行通过LineRecorderReader解析成<Key,Value>,通过 ...

  7. Linux环境常用命令

    bash host                    #查看IP对应机器名 hostname         #查看本机名         hostname –i     #查看本机IP mssh ...

  8. suffix ACM-ICPC 2017 Asia Qingdao

    Consider n given non-empty strings denoted by s1 , s2 , · · · , sn . Now for each of them, you need ...

  9. 多级菜单 menu

    jquery menu: http://jqueryui.com/menu/ Kendo UI Demos http://demos.telerik.com/kendo-ui/web/menu/ind ...

  10. 13、Selenium+python+API分类总结

    Selenium+python+API分类总结 http://selenium-python.readthedocs.org/index.html 分类 方法 方法描述 客户端操作 __init__( ...