Steven Dorning <St****@Image-Metrics.com> wrote:
Is there an equivalent way in C# of writing the following
C++ code.
A and B are classes,
class B
{
private:
A m_A;
public:
const A & ReadA () const { return m_A;}
}
i.e. is there a way of returning a reference to a const
object as opposed to a reference to an non-const object.
Not in normal .NET, although there is a project to provide a modified
version of Rotor which does it. Whether or not this is a good thing is
a source of much debate. Personally I like the idea of constness, but
can see that *expressing* that is quite tricky (when it come to, say, a
Hashtable where each key is const but the value may not be).
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too