We have const
and non-const
function overloading in C++ as described here and used in STL iterators.
Do we have such method overloading in Java and C#?
Java and C# don't have the concept of const functions, so the concept of overloading by const/non-const doesn't really apply.
C# unfortunately does not support const methods or const parameters. There is a new feature in C# 2.0 that somewhat helps in a similar scenario. With C#2.0 get and set accessors of a property can be of different accessibility. So you can make the get accessor public and the set protected as follows
class MyClass
{
int _val;
public int Val
{
protected set { _val = value; }
get { return _val; }
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With