Static polymorphism in C#
In Static polymorphism, the reaction to capacity is resolved at compile time that why It's known as Compile Time Polymorphism.
Program
using System;
namespace Static_Polymorphism
{
class Print
{
/* Utilizing similar class name multiple times with different strategy */
public void Display( string s )
{
Console.WriteLine("My Name is:" + s);
}
public void Display(int a, int b)
{
int c;
c = a + b;
Console.WriteLine("Sum of two number:" + c);
}
public void Display(double f)
{
Console.WriteLine("float number :" + f);
}
static void Main(string[] args)
{
Print p = new Print();
p.Display("Rohit"); /* Chosing at compile time */
p.Display(50, 9);
p.Display(84.004);
Console.ReadKey();
}
}
}
Output
Name: Rohit
Sum of two number: 59
Float number:84.004
In Static polymorphism, the reaction to capacity is resolved at compile time that why It's known as Compile Time Polymorphism.
Program
using System;
namespace Static_Polymorphism
{
class Print
{
/* Utilizing similar class name multiple times with different strategy */
public void Display( string s )
{
Console.WriteLine("My Name is:" + s);
}
public void Display(int a, int b)
{
int c;
c = a + b;
Console.WriteLine("Sum of two number:" + c);
}
public void Display(double f)
{
Console.WriteLine("float number :" + f);
}
static void Main(string[] args)
{
Print p = new Print();
p.Display("Rohit"); /* Chosing at compile time */
p.Display(50, 9);
p.Display(84.004);
Console.ReadKey();
}
}
}
Output
Name: Rohit
Sum of two number: 59
Float number:84.004