KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
The code is pretty self explanatory. I expected when I made a1 and b1 that I was creating two different string instances that contain the same text. So I figure a1 == b1 would be true but object.ReferenceEquals(a1,b1) would be false, but it isn't. Why? //make two seemingly different string instances string a1 = "test"; string b1 = "test"; Console.WriteLine(object.ReferenceEquals(a1, b1)); // prints True. why? //explicitly "recreating" b2 string a2 = "test"; string b2 = "tes"; b2 += "t"; Console.WriteLine(object.ReferenceEquals(a2, b2)); // prints False //explicitly using new string constructor string a3 = new string("test".ToCharArray()); string b3 = new string("test".ToCharArray()); Console.WriteLine(object.ReferenceEquals(a3, b3)); // prints False
Tags (comma-separated)
Save Edits
Cancel