What is C # analog of C ++ const reference return value

I am writing a C ++ accessor to a class member as

SomeClass const& x() const { return m_x; }

It seems that the only protection of this type in C # is to define a property with a closed (or undefined) set. But this protects only from assignments, and not from manipulating the state of a certain class.

Side note: C ++ allows m_x to be removed using the const pointer - IMHO is just an amazing oversight of standard bodies.

+4
source share
1 answer

const in C ++ does not protect against anything, you can drop it without any problems.

# , ( ) . const ness , , , " " ( ).

0

Source: https://habr.com/ru/post/1608218/


All Articles