Logo 
Search:

C# FAQ

Submit Interview FAQ
Home » Interview FAQ » C#RSS Feeds

How do I enforce const correctness in C#?

  Shared By: Corey Brown    Date: Sep 18    Category: C#    Views: 632

Answer:

You can't - at least not in the same way you do in C++. C# (actually, the CLI) has no real concept of const correctness, For example, there's no way to specify that a method should not modify an argument passed in to it. And there's no way to specify that a method does not modify the object on which it is acting.

To get a feel for the angst this causes among some C++ programmers, read the feedback on this post from Raymond Chen.

There are of course ways of addressing this issue. For example, see Brad Abram's(blogs.msdn.com/.../67859.aspx) post (and associated feedback) for some ideas on adding optional read-only behaviour to collection classes.

Share: 
 

Didn't find what you were looking for? Find more on How do I enforce const correctness in C#? Or get search suggestion and latest updates.


Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: