Overloading const and non-const

We overload the const and non const functions in C ++, as described here , and are used in STL iterators.

Do we have such method overloads in Java and C #?

+4
source share
2 answers

Java and C # do not have the concept of const functions, so the concept of const / not-const overload does not really apply.

+6
source

C #, unfortunately, does not support const methods or constant parameters. C # 2.0 has a new feature that helps a bit in a similar scenario. With C # 2.0, get and set accessors properties can have different availability. Thus, you can make access to the access object public, and the set is protected as follows.

 class MyClass { int _val; public int Val { protected set { _val = value; } get { return _val; } } } 
+3
source

All Articles