'=='VS string.equals C#.NET [英] '==' vs string.equals c# .net
本文介绍了'=='VS string.equals C#.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
C#:String.Equals与==
喜的。
有的时候有人跟我说,你不应该用==比较字符串,并且你应该使用string.equals(),但它指的是java的。
Some time someone told me that you should never compare strings with == and that you should use string.equals(), but it refers to java.
¿什么是性差异高炮==和string.equals在.NET C#?
¿What is the diference beteen == and string.equals in .NET c#?
推荐答案
字符串==字符串
是完全一样的 String.Equals
。这是确切的code(从反射镜):
string == string
is entirely the same as String.Equals
. This is the exact code (from Reflector):
public static bool operator ==(string a, string b)
{
return Equals(a, b); // Is String.Equals as this method is inside String
}
这篇关于'=='VS string.equals C#.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文