views:

663

answers:

3

Hi all,

I have programmed C++ for many years but am fairly new to C#. While learning C# I found that the use of the const keyword is much more limited than in C++. AFAIK, there is, for example, no way to declare arguments to a function const. I feel uncomfortable with the idea that I may make inadvertent changes to my function arguments (which may be complex data structures) that I can only detect by testing.

How do you deal with this situation?

+2  A: 

There is an excellent blog post about this issue by Stan Lippman: A question of const

Armin Ronacher
This posting is about C++/CLI, not C#
Seb Rose
It's an explanation why it's not there at all. In any .NET language.
Armin Ronacher
+4  A: 

It was also answered recently on http://stackoverflow.com/questions/114149/const-correctness-in-c

Chris Ballard
+2  A: 

If it matters, I use immutable objects. Or, at a minimum, I use the logic in my property setters.

Will