|
This might be a dumb question, but I need clarification. In C#, let's say I make a class called "Test", and give it an int variable. I then make a Test object, and store it in a Test object variable. I then create two more Test object variables, and assign the original Test object to both. If I change the value of the int variable in either of the two new objects, will those changes propagate backwards to the original object? My brief test says yes, but I'm not sure if that's a consistent behaviour I can take advantage of, or if I've walked into some weird edge case that I can't rely on. If it is consistent, how would I go about splitting a copied object into its own unique object? Would I need to create a new object, and copy the values over? Or is there a way to directly make an object variable unique, and untied to anything else?
|
# ¿ Jan 10, 2018 00:43 |
|
|
# ¿ Apr 28, 2024 01:48 |
|
nielsm posted:You probably want the .NET thread, not the C and C++ thread, for C# questions, but anyway: Ah, thank you. I know this is the wrong thread, but would I be right in thinking that in order to split an object variable into its own unique object, I would need to use the "new" keyword, and copy the values of the original object into the new one?
|
# ¿ Jan 10, 2018 10:55 |