memberwiseclone and strings

  • Thread starter Thread starter Dan Holmes
  • Start date Start date
D

Dan Holmes

Am I reading the docs right? If i have a class that has a string field
when i call MemberWiseClone() the same field in then new object will
reference the string in the original object? Meaning changing one
changes the other.

dan
 
No: CLR strings are immutable; they never change once created. When you
"change" one, you assign a new string (object reference) to the existing
(object reference) field. Re-assigning one leaves the others unchanged.

Marc
 
Back
Top