Basic Overloading Example C# with Example
This code contains an overloaded method named Hello:
public static void Hello(int arg)
public static void Hello(double arg)
public static void Main(string args)
When the Main method is called, it will print
At compile-time, when the compiler ﬁnds the method call Hello( ), it ﬁnds all methods with the name Hello. In
this case, it ﬁnds two of them. It then tries to determine which of the methods is better. The algorithm for
determining which method is better is complex, but it usually boils down to "make as few implicit conversions as
Thus, in the case of Hello( ), no conversion is needed for the method Hello(int) but an implicit numeric
conversion is needed for the method Hello(double). Thus, the ﬁrst method is chosen by the compiler.
In the case of Hello(0.0), there is no way to convert 0.0 to an int implicitly, so the method Hello(int) is not even
considered for overload resolution. Only method remains and so it is chosen by the compiler.