I do write c++ accessor to class member as
SomeClass const& x() const { return m_x; }
It seems that the only protection of this sort in c# is to define property with private (or undefined) set. But this protects only against assignments not against manipulation of the some-class state.
Side note: c++ allows m_x to be deleted through const pointer - IMHO this is simply amazing oversight of standard bodies.
Now, with C# 7.2, you can use ref readonly
for the same purpose. You can check more about that here. Check the third point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With