Why is the original object changed after a copy, without using ref arguments?

后端 未结 4 2052
渐次进展
渐次进展 2020-12-16 08:08

At work we were encountering a problem where the original object was changed after we send a copy through a method. We did find a workaround by using IClonable

4条回答
  •  借酒劲吻你
    2020-12-16 08:40

    that's normal since your MyClass is a reference type so you are passing a reference to original data not the data itself this why it's an expected behavior here is an explanation of what a reference type is from Parameter passing in C#

    A reference type is a type which has as its value a reference to the appropriate data rather than the data itself

提交回复
热议问题