Overloading is what happens when you have two methods with the same name but different signatures. At compile time, the compiler works out which one it's going to call, based on the compile time types of the arguments and the target of the method call.
For example :
string Substring (int startIndex)
string Substring (int startIndex, int length)
No, a C# method cannot be overloaded by only changing the return type.
Overloading happens by changing the parameters.
The return type of a method is not considered to be part of a method's signature (section 3.6), and an overload is determined before the compiler checks whether or not the return type will cause an error in the wider context of the method call. In other words, it's not part of the test for an applicable function member.
No comments:
Post a Comment