Function Overloading/Method Overloading: In Function Overloading we can define many methods with the same name but different parameters. It is used when methods require to perform similar tasks but with different parameters.
Step 1
Open your Visual Studio. By pressing Ctrl +Shift + N you will get your “New Project” Window.
Figure 1 Console Application
Step 2
After pressing OK you will get into your Coding Part where you will see three files in Solution Explorer [Properties, References, Program.cs], in which Program.cs file is your main file where you embed all your Inheritance program code.
Figure 2 Solution Explorer
This is your Function Overloading Program.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
-
- namespace Method_overloading32
- {
- class shape
- {
- public void Area(int side)
- {
- int squarearea = side * side;
- Console.WriteLine("The Area of Square is :" + squarearea);
- }
- public void Area(int length, int breadth)
- {
-
- int rectarea = length * breadth;
- Console.WriteLine("The Area of Rectangle is :" + rectarea);
- }
-
- public void Area(double radius)
- {
- double circlearea = 3.14 * radius * radius;
- Console.WriteLine("The Area of Circle is :" + circlearea);
- }
-
- }
-
- class Program
- {
- static void Main(string[] args)
- {
-
- shape s = new shape();
- s.Area(10);
- s.Area(10, 20);
- s.Area(10.8);
- Console.ReadKey();
-
- }
- }
- }
Figure 3 Different Parameters
OUTPUT
By Pressing F5 you will get your Output like this
Figure 4 Output
Hope you like it! Have a nice day. Thank you for Reading!