Monday, February 04, 2008

Why doesn't c# have const?

One thing I really miss in c# is const. I know most of you are questioning me on this
I must say I am for const correctness, C++ developers argue you always get a library where some plod has forgot to use const correctness and you have to stick const_casts everywhere but I don't think this is a valid argument. Just because people don't use a language feature doesn't mean that language feature should not be provided. C# could have followed on from c++ in this regards and have a const_cast type thing. const as you are aware is a language feature rather then a runtime feature and In my opinion this sort of thing could have been added without effecting the .NET runtime

Perhaps Microsoft will introduce a c# version that does have const in the future but for now one has to rely on documentation to state a method is just an accessor or that parameter objects will not be changed by the called function


Its an interesting debate though
http://blogs.msdn.com/oldnewthing/archive/2004/04/27/121049.aspx

0 Comments:

Post a Comment

<< Home