11

Possible Duplicate:
“const correctness” in C#

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?

Community
  • 1
  • 1
andreas buykx
  • 12,608
  • 10
  • 62
  • 76

2 Answers2

2

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

Armin Ronacher
  • 31,998
  • 13
  • 65
  • 69
2

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