As we know, in C#,
- string is a reference type
- for string == operator is overloaded so that comparison is performed by value
There is the following variables defined:
string s1 = "foo";
object s2 = "foo";
string s3 = new String(new char[] {'f','o','o'});
bool b1 = (s1==s2); //true
bool b2 = (s2==s3); //false
bool b3 = (s1==s3); //true
bool b4 = (s1.equals(s3)); //true
gettype() for all variables s1, s2, and s3, returned the same val String.
Why is s1==s3 true and s2 == s3 is false? s1 and s2 have the same type - so the == operator should behave the same. As I understand, s1 and s2 also interned. (object.ReferenceEquals(s1, s2) returned True.)
What do I miss?