Alexander... I was too busy to give any lengthy answer earlier. There is
no
equivalent of that use of C++ const in C#. The general solution is store
the
data in a read write collection and then wrap a reference to the
collection in a
read only class using containment by reference. You can then pass a
reference to the read only class to the client. In this manner only one
copy of
the collection exists. A smarty solution is to derive a read write class
from a
read only class, create an instance of the read write class and pass a
reference to the read only base class. This is not foolproof since the
client can
still cast the reference to the actual read write class much as you can
const_cast in C++.
In C++ both struct and classes have value semantics. In C# structs have
value
semantics and classes have reference semantics. If you store a struct in
most
C# collections they get boxed anyway, so in general, classes are favored
over
structs.
Regards,
Jeff
*** Sent via Developersdex
http://www.developersdex.com ***