The data type Object is not the same as a String.
It is like comparing a vehicle and a car. A car is a vehicle, but the other way around is not necessarily true.
The same goes for programming. A String inherits from Object, so a String is an Object but an Object could be basically any type.
Try this instead.
Console.WriteLine("{0}", obj.ToString() == s1);
I am not 100% sure, but I think the reason is that for the first two variables, a constant string with the value
"Int32" is allocated on the heap. As this string is only allocated once, the comparison
obj == s is true because it is the same string with two different pointers pointing to the same data.
This construct results in a value allocated on the stack.
String s1 = typeof (int).Name;
The comparison
s == s1 works because now you compare two string types.
When comparing
obj == s1, you try to compare two different types.
This explains it better.
String.Intern Method[
^]
(My internet connection has been slow, so I might have missed some comments that describes this)