C# and const

  • Thread starter news.microsoft.com
  • Start date
N

news.microsoft.com

It seems to me that C# has a serious issue regarding const. It's not
possible
to have a method parameter declared as const. Often you will want to call
a method, and you don't want the method to modify the class you are sending
a reference to. Also it's not possible to declare a method as const,
something
you could do in C++.

These const issues are irritating, and in my opinion the language don't live
up
to what we come to expect from a modern language.

Long live C++.


regards
Kjetil Kristoffer Solberg
 
S

Sylvain Lafontaine

C# is not C++ but a simplified version of it designed to make things simpler
or easier for programmers.

If you want to have the full control of C++ inside the .NET Framework, all
you have to do is to use managed C++. (BTW, the next version of VS.NET,
2005, will have an easier syntaxe for managed C++).

The designers of C# have choosen to drop things like const parameters and
multiple heritages for a very good reason: the complexity of using such
statements was simply going out of control and, in the case of const
parameters, there are other ways of programming than treating programmers as
children. The langage cannot be considered as a replacement for a bad
programmer/designer.

S. L.
 
J

Jeff Louie

Kjetil... This has been discussed numerous times :). Neither c# nor java
support const on a method parameter. There are significant differences
between the C++ and C# approach to programming, not the least is that
C++ classes use value semantics by default and have deterministic
destructors. For instance, a c++ coder could say that C#s lack of
deterministic destructors and use of garbage collection is irritating.

http://www.geocities.com/jeff_louie/OOP/oop5.htm

To program in C# you must change your approach. The approach to const is
to use immutable objects or readonly collections.

http://www.geocities.com/jeff_louie/OOP/oop7.htm

Irritating to a c++ coder? Yes. Wrong? I don't think so. Just different.

Regards,
Jeff
 
J

Joerg Jooss

news.microsoft.com said:
It seems to me that C# has a serious issue regarding const. It's not
possible
to have a method parameter declared as const. Often you will want to
call a method, and you don't want the method to modify the class you
are sending a reference to. Also it's not possible to declare a
method as const, something
you could do in C++.

These const issues are irritating, and in my opinion the language
don't live up
to what we come to expect from a modern language.

Long live C++.

Const correctness in C++? What ever happened to casting?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top