Search code examples
c#.netequals-operator

'==' vs string.equals c# .net


Possible Duplicate:
C#: String.Equals vs. ==

Hi to all.

Some time someone told me that you should never compare strings with == and that you should use string.equals(), but it refers to java.

¿What is the diference beteen == and string.equals in .NET c#?


Solution

  • 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
    }