public class test
{
public void xov() { return; }
public string xov() { return null; }
public int xov() { return 0; }
}
public class p
{
public p()
{
test v = new test();
v.xov();// Here i cann't use defined overloads :(
}
}
I can overload methods by parameters , but why cann't I overload methods by return type?
The return type is not considered part of a method's signature. That is, methods cannot be overloaded if they differ only by return type.
Calling
int x = Add(5,6);
might be diffrent than:
string y = Add(5,6);
But what if no one reads the return type?
Add(5,6);
How is the compiler suppose to know which add was called? So this option is not legal.
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