Possible duplicate:C #: String.Equals vs. ==
Hello everybody.
Sometime someone told me that you should never compare strings with == and that you should use string.equals (), but this applies to java.
¿What is the difference between == and string.equals in .NET C #?
string == stringcoincides with String.Equals. This is the exact code (from Reflector):
string == string
String.Equals
public static bool operator ==(string a, string b) { return Equals(a, b); // Is String.Equals as this method is inside String }
In C #, there is no difference, as the operator ==, and !=was overwhelmed in a string type to trigger equals(). See This MSDN Page .
==
!=
equals()
== String.Equals on Strings.
StringComparision String.Equals....
:
MyString.Equals("TestString", StringComparison.InvariantCultureIgnoreCase)
, . , .
== String.Equals. . :
public static bool operator ==(string a, string b) { return string.Equals(a, b); }
.
== , System.Object.ReferenceEquals.Equals - , ( ).
== , System.Object.ReferenceEquals.
Equals - , ( ).
it makes no difference, it's just an operator overload. for strings, this is internally the same. however, you do not want to get used to using == to compare objects and why it is not recommended to use it for strings.
In C # there is no difference for strings.
If you don’t care about the lowercase case and don’t worry about cultural awarenes, then this is the same ...