c sharp overloading programs with source code
namespace overloading
{
class overload
{
public void ovl()
{
Console.WriteLine("No Parameters.");
}
public void ovl(int a)
{
Console.WriteLine("One parameter is passed i.e " + a);
}
public int ovl(int a, int b)
{
Console.WriteLine("Two parameters are passed they are" + a + "and" + b);
return a + b;
}
public double ovl(double a, double b)
{
Console.WriteLine("Two double parameters are passed they are" + a + "and" + b);
return a + b;
}
}
public class poly
{
static void Main(string[] args)
{
overload ob = new overload();
int resi;
double resd;
ob.ovl();
Console.WriteLine();
resi = ob.ovl(4, 6);
Console.WriteLine("Result of adding these integers is" + resi);
Console.WriteLine();
resd = ob.ovl(1.11, 1.12);
Console.WriteLine("Result of adding these doubles is:" + resd);
Console.WriteLine();
Console.ReadLine();
}
}
namespace overloading
{
class overload
{
public void ovl()
{
Console.WriteLine("No Parameters.");
}
public void ovl(int a)
{
Console.WriteLine("One parameter is passed i.e " + a);
}
public int ovl(int a, int b)
{
Console.WriteLine("Two parameters are passed they are" + a + "and" + b);
return a + b;
}
public double ovl(double a, double b)
{
Console.WriteLine("Two double parameters are passed they are" + a + "and" + b);
return a + b;
}
}
public class poly
{
static void Main(string[] args)
{
overload ob = new overload();
int resi;
double resd;
ob.ovl();
Console.WriteLine();
resi = ob.ovl(4, 6);
Console.WriteLine("Result of adding these integers is" + resi);
Console.WriteLine();
resd = ob.ovl(1.11, 1.12);
Console.WriteLine("Result of adding these doubles is:" + resd);
Console.WriteLine();
Console.ReadLine();
}
}
0 comments: