Simple Program of Function Overloading in Console in ASP.NET using C#

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.

Console Application

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.

Solution Explorer
Figure 2 Solution Explorer

This is your Function Overloading Program.

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5.   
  6. namespace Method_overloading32  
  7. {  
  8.     class shape   
  9.    {  
  10.         public void Area(int side)  
  11.          {  
  12.             int squarearea = side * side;  
  13.             Console.WriteLine("The Area of Square is :" + squarearea);  
  14.          }  
  15.         public void Area(int length, int breadth)  
  16.          {  
  17.   
  18.             int rectarea = length * breadth;  
  19.             Console.WriteLine("The Area of Rectangle is :" + rectarea);       
  20.          }  
  21.   
  22.         public void Area(double radius)  
  23.         {  
  24.             double circlearea = 3.14 * radius * radius;  
  25.             Console.WriteLine("The Area of Circle is :" + circlearea);  
  26.         }    
  27.       
  28.     }  
  29.   
  30.     class Program  
  31.     {  
  32.         static void Main(string[] args)  
  33.         {  
  34.   
  35.             shape s = new shape();  
  36.             s.Area(10);  
  37.             s.Area(10, 20);  
  38.             s.Area(10.8);  
  39.             Console.ReadKey();  
  40.   
  41.         }  
  42.     }  
  43. }  
Different Parameters

Figure 3 Different Parameters

OUTPUT

By Pressing F5 you will get your Output like this

Output

Figure 4 Output

Hope you like it! Have a nice day. Thank you for Reading!

Ebook Download
View all
Learn
View all