方法Equals和操作符==的区别
http://www.codeproject.com/Articles/584128/What-is-the-difference-between-equalsequals-and-Eq
So for example if you create an object as shown in below code:-
- “.NET interview questions” is the content.
- “o” is the reference to that content.
object o = ".NET Interview questions";


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>
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2014-05-27 string类的常用方法