【转载】#402 - Value Equality vs. Reference Equality
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的更多相关文章
- [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 ...
- 关于C#你应该知道的2000件事
原文 关于C#你应该知道的2000件事 下面列出了迄今为止你应该了解的关于C#博客的2000件事的所有帖子. 帖子总数= 1,219 大会 #11 -检查IL使用程序Ildasm.exe d #179 ...
- First-class function
https://en.wikipedia.org/wiki/First-class_function In computer science, a programming language is sa ...
- C# ==、Equals、ReferenceEquals 区别与联系 (转载)
相关概念 .Net提供了ReferenceEquals.静态Equals,具体类型的Equals以及==操作符这四个判等函数.但是这四个函数之间有细微的关系,改变其中一个函数的实现会影响到其他函数的操 ...
- 【转载】C#相等性比较
本文阐述C#中相等性比较,其中主要集中在下面两个方面 ==和!=运算符,什么时候它们可以用于相等性比较,什么时候它们不适用,如果不使用,那么它们的替代方式是什么? 什么时候,需要自定一个类型的相等性比 ...
- java8-Optional的引入
背景 NPE问题,100%的Java程序员都碰到,并且曾经是心中的痛. 1965年英国TonyHoare引入了Null引用,后续的设计语言包括Java都保持了这种设计. 一个例子 业务模型 Perso ...
- java8-新的日期API
背景 java的日期和时间API设计不理想,java8引入新的时间和日期API就是为了解决这个问题. 老的日期API的核心类 缺点 Date 月从0开始,年最小从1900年开始,没有时区的概念 Cal ...
- Java-Class-FC:java.time.Duration
ylbtech-Java-Class-FC:java.time.Duration 1.返回顶部 2.返回顶部 3.返回顶部 1. /* * Copyright (c) 2012, 2015, ...
- 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 ...
随机推荐
- Java的JsonHelper
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --> <dependency> <g ...
- A. The number of positions
A. The number of positions time limit per test 0.5 second memory limit per test 256 megabytes input ...
- uva 442
#include<iostream>#include<stack>#include<map>using namespace std;struct node{ int ...
- 1.3 guessing game
创建项目 [root@itoracle test]# cargo new guessing_game Created binary (application) `guessing_game` pack ...
- java——为什么要有接口?和抽象类有什么不一样?
1.接口不是类,为什么? 接口如果是类,那就失去了java引入接口的意义了. java之所以引入接口,就是为了弥补不能多继承的缺点,在java中每个类只能有一个超类,但却可以实现多个接口. 2.接口可 ...
- django建表报错
今天在用pycharm创建数据库的表的时候碰见了一个报错,这还是头一次碰见这种奇怪的错误.这里记住希望能避免错误. 我所创建的表是用的django原有的用户表,做了一下继承. class UserI ...
- Mybatis学习笔记3 - 增删改查示例
1.接口定义 package com.mybatis.dao; import com.mybatis.bean.Employee; public interface EmployeeMapper { ...
- 树形dp学习
学习博客:https://www.cnblogs.com/qq936584671/p/10274268.html 树的性质:n个点,n-1条边,任意两个点之间只存在一条路径,可以人为设置根节点,对于任 ...
- [编程题] 小易喜欢的数列 dp
https://www.nowcoder.com/question/next?pid=6291726&qid=112729&tid=12736753 [编程题] 小易喜欢的数列 时间限 ...
- iTween Scale缩放
void Start () { //键值对儿的形式保存iTween所用到的参数 Hashtable args = new Hashtable(); //放大的倍数 args.Add(, , )); / ...