a)
string s = "value";
string s1 = "value";
Do s and s1 reference variables point to same string object ( I’m assuming this due to the fact that strings are immutable )?
b) I realize equality operators ( ==, > etc ) have been redefined to compare the values of string objects, but is the same true when comparing two strings using static methods Object.Equals() and Object.ReferenceEquals()?
thanx
No, not all strings with the same value are the same object reference.
Strings generated by the compiler will all be Interned and be the same reference. Strings generated at runtime are not interned by default and will be different references.
Note the line above where you can force a string to be interned using
String.Intern(string)which then allows you to use object equality instead of string equality for some checks, which is much faster. One example where this is very commonly used is inside the generated XML serializer code along with the name table.