const

J

Jeff Louie

Hmmm... I just tested and note that the MC++2.0 compiler will accept
const on a handle to a managed object so that the method cannot change
the state of the object. This implies that theoretically C# could also
implement const. const and RAII are useful idioms. C# has using, but
could it add const?

Regards,
Jeff
 
D

Daniel O'Connell [C# MVP]

Jeff Louie said:
Hmmm... I just tested and note that the MC++2.0 compiler will accept
const on a handle to a managed object so that the method cannot change
the state of the object. This implies that theoretically C# could also
implement const. const and RAII are useful idioms. C# has using, but
could it add const?

It could, but unless the CLR implemented it, it woudl be ineffective(MC++
gets away with it, I believe, mostly as something C++ developers expect,
even if it doesn't confer true safety). And then that brings up the whole
mess of old code.

There have been numerous discussions about it in the past, personally I
think const is a bad way of solving the problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top