By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,424 Members | 1,351 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,424 IT Pros & Developers. It's quick & easy.

C# and const

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

"news.microsoft.com" <kj******@tihlde.org> wrote in message
news:et**************@TK2MSFTNGP10.phx.gbl...
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

Nov 16 '05 #2

P: n/a
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
It seems to me that C# has a serious issue regarding const.<


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

P: n/a
news.microsoft.com wrote:
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?

--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.