473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C# and const

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
3 4053
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Sergey Tolstov | last post by:
Hello, I am working with Visual C++ 6.0 compiler. In the following declaration: int const A = 10, B = 10; both A and B are const. However, in declaration
20
by: Corno | last post by:
Hi all, There's probably a good reason why a const object can call non const functions of the objects where it's member pointers point to. I just don't see it. For me, that makes the the const...
6
by: Virendra Verma | last post by:
This sounds weird, but I am looking for separate behaviors for destruction of a const and non-const object. I am trying to develop a smart/auto pointer class for writing objects to disk...
7
by: johny smith | last post by:
Can someone please explain to me the difference between these two: function1( const int a) function2( int const a) Both seemed to compile, but what is the difference between the two above....
3
by: Steven T. Hatton | last post by:
Sorry about the big code dump. I tried to get it down to the minimum required to demonstrate the problem. Although this is all done with GNU, I believe the problem I'm having may be more general. ...
15
by: Dave | last post by:
Hello NG, It is well known that memory-allocating definitions should not be put in a header file. I believe, however, that this does not apply to const definitions. For example: #ifndef...
4
by: chrisstankevitz | last post by:
This code does not compile on gcc 3.4.4. Should it? Thanks for your help, Chris //================ #include <set> int main()
10
by: d3x0xr | last post by:
---- Section 1 ---- ------ x.c int main( void ) { char **a; char const *const *b; b = a; // line(9)
0
by: d3x0xr | last post by:
Heh, spelled out in black and white even :) Const is useles... do NOT follow the path of considering any data consatant, because in time, you will have references to it that C does not handle,...
4
by: grizggg | last post by:
I have searched and not found an answer to this question. I ran upon the following statement in a *.cpp file in a member function: static const char * const pacz_HTMLContentTypeHeader =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.