Is there a workaround for overloading the assignment operator in C#?

后端 未结 7 1814
悲哀的现实
悲哀的现实 2020-12-13 02:43

Unlike C++, in C# you can\'t overload the assignment operator.

I\'m doing a custom Number class for arithmetic operations with very large numbers and I want it to h

7条回答
  •  旧时难觅i
    2020-12-13 03:28

    Instead of making a copy of the data when passing the reference you could make the class immutable. When the class is immutable having multiple references to it isn't a problem since it can't be changed.

    Operations that changes the data would of course return new instances.

提交回复
热议问题