Method Overloading in C#
The Method Overloading is defined as Defining More than One Method with the same Name or In Other words we can say that, contain Multiple Methods with the Same Name under the same Class.
These Methods Are differentiated by the type of parameter or variating by the having more than one parameter But Changing of return type of Method is Invalid and Complier will throw error. Not a valid Method. These are mainly derived from the Base library – “System” Class.
Example,
Here in This Example,
Form1 Class Has Method – “MethodOverLoadingDemo”, And this Has been Overloaded with Multiple times as mentioned in the image.
MethodOverLoadingDemo à Normal Private Method has been Defined.
MethodOverLoadingDemo(string str= “MethodOverLoadingDemo”) à Overloaded the previous
Method by String Parameter.
MethodOverLoadingDemo(int MethodCount = 3) à Overloaded the previous Method by int Parameter.
And All the Above Methods are Non-Value Return Type I.e. Void Type but Below Method is string return Type, this is not a valid Statement Allowed in c#, because this an invalid Overloading it will throw an error as already same method is defined- Mentioned in the image
String MethodOverLoadingDemo(int MethodCount = 3) à Invalid Overloading
Comments
Post a Comment