Equals and == check for reference equality. But it behaves differently why? Here
Console.WriteLine(c == d); //False
Console.WriteLine(c.Equals(d)); //True
Console.WriteLine(cc == dd); //True
Console.WriteLine(cc.Equals(dd));//True
Can somebody explain what happens behind the scene.
//https://blogs.msdn.microsoft.com/csharpfaq/2004/03/29/when-should-i-use-and-when-should-i-use-equals/
public void StringDoubleEqualsVsEquals()
{
// Create two equal but distinct strings
string a = new string(new char[] { 'h', 'e', 'l', 'l', 'o' });
string b = new string(new char[] { 'h', 'e', 'l', 'l', 'o' });
Console.WriteLine(a == b); //True
Console.WriteLine(a.Equals(b)); //True
// Now let's see what happens with the same tests but with variables of type object
object c = a;
object d = b;
Console.WriteLine(c == d); //False
Console.WriteLine(c.Equals(d)); //True
/*************************************************************************/
Console.WriteLine(Environment.NewLine);
string aa = "1";
string bb = "1";
Console.WriteLine(aa == bb);//True
Console.WriteLine(aa.Equals(bb));//True
object cc = aa;
object dd = bb;
Console.WriteLine(cc.GetType());//System.String
Console.WriteLine(dd.GetType());//System.String
Console.WriteLine(cc == dd);//True
Console.WriteLine(cc.Equals(dd));//True
Console.ReadKey();
}