By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,640 Members | 2,094 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,640 IT Pros & Developers. It's quick & easy.

Constant objects in C#

P: n/a
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??
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
OK. thanks.
-----Original Message-----
Hi,

There was a big discussion about this in the csharp newsgroup. Please lookthere instead of putting us all through it again (it got quite heated).
Pete


Jul 19 '05 #2

P: n/a
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.
"Piotr Bartczak" <pb***@go2.pl> wrote in message
news:03****************************@phx.gbl...
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??

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.