please look at the below code:
using System;
class MyClass
{
static void Main()
{
object o = ".NET Framework";
object o1 = new string(".NET Framework".ToCharArray());
Console.WriteLine(o == o1);
Console.WriteLine(o.Equals(o1));
}
}
and the result is:
False
True
and now consider this one:
using System;
class MyClass
{
static void Main()
{
object o = ".NET Framework";
object o1 = ".NET Framework";
Console.WriteLine(o == o1);
Console.WriteLine(o.Equals(o1));
}
}
and the result is:
True
True
“==” compares if the object references are same while “.Equals()” compares if the contents are same. and i want to know what is different between these codes?!
object o1 = new string(".NET Framework".ToCharArray());
and
object o1 = ".NET Framework";
both of them turn out an object but why results are different?