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

后端 未结 7 1781
悲哀的现实
悲哀的现实 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条回答
  • 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.

    0 讨论(0)
提交回复
热议问题