http://www.codeproject.com/Articles/584128/What-is-the-difference-between-equalsequals-and-Eq

When we create any object there are two parts to the object one is the content and the other is reference to that content.
So for example if you create an
object as shown in below code:-
  1. “.NET interview questions” is the content.
  2. “o” is the reference to that content.
object o = ".NET Interview questions"; 
 
 
“==” compares if the object references are same while “.Equals()” compares if the contents are same.
 
So if you run the below code both “==” and “.Equals()” returns true because content as well as references are same.
 
 
 
object o = ".NET Interview questions";
object o1 = o;
Console.WriteLine(o == o1);
Console.WriteLine(o.Equals(o1));
Console.ReadLine();

True

True

Now consider the below code where we have
same content but they point towards different instances. So if you run the below
code both “==” will return false and “.Equals()” will return true.

object o = ".NET Interview questions";
object o1 = new string(".NET Interview questions".ToCharArray());
Console.WriteLine(o == o1);
Console.WriteLine(o.Equals(o1));
Console.ReadLine();

False

True

When you are using string data type it
always does content comparison. In other words you either use “.Equals()” or
“==” it always do content comparison.

You can also watch the following video of the above explanation at C#
interview questions and answers :- Difference between "==" and ".Equals()" ?

<OBJECT type="application/x-shockwave-flash"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=3,0,0,0"
WIDTH="640" HEIGHT="360"
data="http://www.youtube.com/v/3IReFdq5d7o?version=3&feature=player_detailpage"></OBJECT>

方法Equals和操作符==的区别的更多相关文章

  1. Java中==、equals、hashcode的区别与重写equals以及hashcode方法实例(转)

    Java中==.equals.hashcode的区别与重写equals以及hashcode方法实例  原文地址:http://www.cnblogs.com/luankun0214/p/4421770 ...

  2. (转)从一道面试题彻底搞懂hashCode与equals的作用与区别及应当注意的细节

    背景:学习java的基础知识,每次回顾,总会有不同的认识.该文系转载 最近去面试了几家公司,被问到hashCode的作用,虽然回答出来了,但是自己还是对hashCode和equals的作用一知半解的, ...

  3. Java == ,equals 和 hashcode 的区别和联系(阿里面试)

    今天阿里的人问我 equals 与hashcode的区别,我答不上来, 仔细查了一下,做了总结: (1) == 这是Java 比较内存地址,就是内存中的对象: java中的==是比较两个对象在JVM中 ...

  4. Java中BigDecimal的equals与compareTo的区别

          有个是否为零的判断[BigDecimal.ZERO.equals(ratio)]我用了BigDecimal的equals方法,结果,判断失败,因此特地分析一下equals与compareT ...

  5. equals与hashCode的区别

    equals与hashCode的区别 1.类中的equals方法是一定要重写/覆盖(Override)的,因为要让它按照设计的需求来根据特征值判断等价性. 这里的特征值,就是String类型的name ...

  6. android 判断字符串是否为空与比对["=="与equals()的区别]

    if (s == null || s.equals("")) ; } s.equals("")里面是要比对的字符串 声明字符串未赋初始值或值,然后比对就会出错, ...

  7. java基础疑难点总结之成员变量的继承,方法重载与重写的区别,多态与动态绑定

    1.成员变量的继承 1.1要点 子类用extends关键字继承父类.子类中可以提供新的方法覆盖父类中的方法.子类中的方法不能直接访问父类中的私有域,子类可以用super关键字调用父类中的方法.在子类中 ...

  8. String split方法与Guava Splitter用法区别

    String split方法与Guava Splitter用法区别 今天同事写了一段使用String split方法的代码,如下所示,同事期望得到的是字符"1",但是没想到却得到空 ...

  9. delphi dispose释放内存的方法 New 和 GetMem 的区别

    来自:http://blog.sina.com.cn/s/blog_4bc47d2301018trf.html -------------------------------------------- ...

随机推荐

  1. _cpluscplus

    _cpluscplus是c++中的定义,而c中没有该定义 1.用来判定代码是c类型还是c++类型 2._cplusplus的类型是"long int",值为199711L int ...

  2. [SC] OpenSCManager FAILED 1722

    在服务器A(windows server 2008 r2)执行如下命令访问远端服务器B(windows server 2003)的服务运行状况: sc \\servername query " ...

  3. python学习小结1:for循环控制语句

    用一个列表来确定for循环的范围 >>> x = [0,1,2,3,4] >>> for i in x: print i, 0 1 2 3 4  循环一个字符串 & ...

  4. 面试问到struts1与struts2的解析对比

    一.struts1要继承一个抽象类.struts1是类编程而不是接口编程. struts2的action可以实现一个action接口,也可以实现其他的接口,使其成为可选的定制的服务. 二.struts ...

  5. js--eval函数

    前言: js的eval函数很牛叉,用了几次--不过都没有记录.试想:如果没有EXT.JQery,怎样将json字符串转换为对象呢? 示例: 定义2个字符串变量s1.s2.其中s1表示一个对象:s2表示 ...

  6. javamail邮件发送报错解决方案

    如果你用myEclipse进行开发的话,运行时可能会出现以下的错误:Exception in thread "main" java.lang.NoClassDefFoundErro ...

  7. MemSQL Start[c]UP 2.0 - Round 2 - Online Round

    搞到凌晨4点一个没出,要gg了. A. Golden System http://codeforces.com/contest/458/problem/A #include<cstdio> ...

  8. shallow copy & deep copy

    1.深复制与浅复制的概念 ->浅复制(shallow copy)概念   在SDK Guides中(搜索copy),官方给出的浅复制概念为: Copying compound objects, ...

  9. NOI 国家集训队论文集

    鉴于大家都在找这些神牛的论文.我就转载了这篇论文合集 国家集训队论文分类 组合数学 计数与统计 2001 - 符文杰:<Pólya原理及其应用> 2003 - 许智磊:<浅谈补集转化 ...

  10. WAF安恒

    http://wenku.baidu.com/view/c242927f581b6bd97e19ea1a.html?from=search