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

Daniel Gomez Rico picture Daniel Gomez Rico · Apr 26, 2011 · Viewed 7.7k times · Source

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#?

Answer

Lasse Espeholt picture Lasse Espeholt · Apr 26, 2011

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
}