Write a C# program to demonstrate function overloading
Description:
In this post we are going to learn function overloading.
Open Microsoft visual studio
File-> New -> Project -> visual c#-> console Application
Program:
Description:
In this post we are going to learn function overloading.
Open Microsoft visual studio
File-> New -> Project -> visual c#-> console Application
Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _6.FunctionOverloading
{
class Program
{
static void Main(string[] args)
{
shape s = new shape();
s.area(5);
s.area(5, 2);
}
}
class shape
{
public void area(int a)
{
int c = a * a;
Console.WriteLine("Square
area:{0}",c);
Console.ReadLine();
}
public void area(int a,int b)
{
int d = a * b;
Console.WriteLine("Rectangle area:{0}",d);
Console.ReadLine();
}
}
}
Demo:
Write a C# program to demonstrate function overloading |
No comments:
Post a Comment