How to Use Method OverLoading in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo
{
class Class1
{
public int Sum(int A, int B)
{
return A + B;
}
public float Sum(int A, float B)
{
return A - B;
}
}
class Class2 : Class1
{
public int Sum(int A, int B, int C)
{
return A * B * C;
}
}
class MainClass
{
static void Main()
{
Class2 obj = new Class2();
Console.WriteLine("Method 1 -- Sum is:" + obj.Sum(10, 20));
Console.WriteLine("Method 2 -- Subtarction is:" + obj.Sum(10, 15.70f));
Console.WriteLine("Method 3 -- Product is:" + obj.Sum(10, 20, 30));
Console.Read();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo
{
class Class1
{
public int Sum(int A, int B)
{
return A + B;
}
public float Sum(int A, float B)
{
return A - B;
}
}
class Class2 : Class1
{
public int Sum(int A, int B, int C)
{
return A * B * C;
}
}
class MainClass
{
static void Main()
{
Class2 obj = new Class2();
Console.WriteLine("Method 1 -- Sum is:" + obj.Sum(10, 20));
Console.WriteLine("Method 2 -- Subtarction is:" + obj.Sum(10, 15.70f));
Console.WriteLine("Method 3 -- Product is:" + obj.Sum(10, 20, 30));
Console.Read();
}
}
}
0 comments:
Post a Comment