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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top