惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
Google DeepMind News
Google DeepMind News
小众软件
小众软件
GbyAI
GbyAI
酷 壳 – CoolShell
酷 壳 – CoolShell
F
Fortinet All Blogs
博客园 - 三生石上(FineUI控件)
B
Blog
量子位
B
Blog RSS Feed
Vercel News
Vercel News
Blog — PlanetScale
Blog — PlanetScale
Last Week in AI
Last Week in AI
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
爱范儿
爱范儿
Jina AI
Jina AI
C
Check Point Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
IT之家
IT之家
H
Hackread – Cybersecurity News, Data Breaches, AI and More
云风的 BLOG
云风的 BLOG

博客园 - xqiwei

WCF RIA Services DomainService life-cycle and adding Transactions C#多线程 使用委托更新UI实例(WP7开发 其他线程中更新UI)(转载) Delegate,Action,Func,匿名方法,匿名委托,事件 (转载) looping(and modifying) a collection - xqiwei LineBreak in a tooltip in xaml - xqiwei GetObjectbyKey in E.F. vs. Querying for a single entity Use GetObjectByKey() for better performance Visual Studio集成开发环境无法启动调试 IValueConverter 接口 ASP.NET页面生命周期和asp.net应用程序生命周期 Windows Presentation Foundation Tools and Controls ArcEngine开发之Command控件使用篇 Resharper进阶 C# 中的委托和事件 WPF系列文章 新技术文章 flash与javascript、asp.net(数据库)的交互 使用vs.net ajax实现幻灯片的效果 职业规划
C#中关于String.Equals(object,object)和(object==object )的...
xqiwei · 2010-01-27 · via 博客园 - xqiwei

情况一
string s = "Test";
string t = string.Copy(s);
Console.WriteLine(s == t);
 Console.WriteLine((object)s == (object)t);
输出为true false

情况二
string s = "Test";
string t = s;
Console.WriteLine(s == t);
 Console.WriteLine((object)s == (object)t);
输出为true true

 情况三
string s = "Test";
string t = string.Copy(s);
Console.WriteLine(s.Equals(t)); //true
Console.WriteLine((object)s.Equals((object)t));//true

情况四
string s = "Test";
string t = s;
Console.WriteLine(s.Equals(t)); //true
Console.WriteLine((object)s.Equals((object)t));//true

            结论:
             String.Equals();方法(是String类从它的超类Object中继承的)被用来检测两个对象是否相等,即两个对象的内容是否相等。
            ==用于比较引用和比较基本数据类型时具有不同的功能:
            比较基本数据类型,如果两个值相同,则结果为true
            而在比较引用时,如果引用指向内存中的同一对象(即内存地址是一样的),结果为true.