Constant objects in C#

  • Thread starter Thread starter Piotr Bartczak
  • Start date Start date
P

Piotr Bartczak

I've started learning C# (after C++) and I found that
there is no way to make an object constant. In C++ there
is a const modifier which allows me to define an object
which will not change after initialization. In C# it is
impossible (as far as I know). My question is: Why? In
C++ checking for changes to const objects is being done
during compilation. I don't see any reason why can't they
do the same in C#. Does anybody know??
 
Piotr,

If you're just looking for the object equivalent of a constant field, then
you can use "readonly" instead of const.

If you're asking about const parameters and methods, you can find some big
discussions in the archives.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top