Can anyone explain that why Am I getting false in Line Number 5.
string a = "prakash";
string b = "p";
b += "rakash"; // Append to contents of 'b'
Console.WriteLine(a == b); //True
Console.WriteLine((object)a == (object)b); //False
string b = "p";
b += "rakash"; // Append to contents of 'b'
Console.WriteLine(a == b); //True
Console.WriteLine((object)a == (object)b); //False

VulpesPosted Feb 2, 2014, 3:16 PM
However, the equality operator in the string class is overridden so that two string references are considered equal if the contents of the strings are the same.
Now, the contents of 'a' and 'b' are the same and this is why you get 'True' in line 4.
However, 'a' and 'b' do not refer to the same object.
'a' refers to the string literal "prakash" which is stored in a special area of the heap known as the 'string intern pool' when the application starts.
'b' refers to a string object manufactured by concatenating the two string literals "p" and "rakash" and stored in the ordinary heap.
When 'a' and 'b' are cast to object, the normal definition of object equality is used and, since the objects are different, 'False' is returned.