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. Modbus协议学习笔记

    之前也有写过基于 Modbus 通讯协议的控制远程监控程序,但是由于当时时间赶.人手少(软硬件前后台都是在下一人

  2. C++ vector类型要点总结(以及各种algorithm算法函数)

    概述 C++内置的数组支持容器的机制,但是它不支持容器抽象的语义.要解决此问题我们自己实现这样的类.在标准C++中,用容器向量(vector)实现. 容器向量也是一个类模板.vector是C++标准模 ...

  3. 2019.03.19 读书笔记 string与stringbuilder的性能

    1 string与stringbuilder 并不是stringbuilder任何时候都在性能上占优势,在少量(大约个位数)的字符串时,并不比普通string操作快. string慢的原因不是stri ...

  4. LeetCode 881.救生艇(C++)

    第 i 个人的体重为 people[i],每艘船可以承载的最大重量为 limit. 每艘船最多可同时载两人,但条件是这些人的重量之和最多为 limit. 返回载到每一个人所需的最小船数.(保证每个人都 ...

  5. jQuery源码浅析2–奇技淫巧

    最近一直在研读 jQuery 源码,初看源码一头雾水毫无头绪,真正静下心来细看写的真是精妙,让你感叹代码之美. 其结构明晰,高内聚.低耦合,兼具优秀的性能与便利的扩展性,在浏览器的兼容性(功能缺陷.渐 ...

  6. 初学者配置第一个spring mvc Demo

    1.web.xml的配置 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi= ...

  7. log4net 基础

    log4net:日志输出工具. 新建工程Log4NetDemo App.config配置如下: <?xml version="1.0" encoding="utf- ...

  8. c++ 控制台输入参数

    #include <iostream>#include <string> using namespace std; int main(int argc,char **argv) ...

  9. cf868F. Yet Another Minimization Problem(决策单调性 分治dp)

    题意 题目链接 给定一个长度为\(n\)的序列.你需要将它分为\(m\)段,每一段的代价为这一段内相同的数的对数,最小化代价总和. \(n<=10^5,m<=20\) Sol 看完题解之后 ...

  10. textarea存起来的数据把空格也存起来

    textarea的属性wrap="hard"可以把换行的内容也存起来. <html> <head> <title>这是一个小测试</tit ...