Method Overloading
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MethodOverloading
{
public class Numbers
{
public int FirstNum;
public int SecondNum;
public int ThirdNum;
public int FourthNum;
public void printSum()
{
Console.WriteLine("Sum is
{0}", FirstNum + SecondNum + ThirdNum +
FourthNum);
Console.ReadLine();
}
}
public static class Program
{
static void Main(string[] args)
{
Numbers sumNumber = new Numbers();
sumNumber.FirstNum = 1;
sumNumber.SecondNum = 2;
sumNumber.ThirdNum = 3;
sumNumber.FourthNum = 4;
sumNumber.printSum();
}
public static void Add(int FirstNum, int SecondNum)
{
Console.WriteLine("Sum is
{0}", FirstNum + SecondNum);
}
public static void Add(int FirstNum, int SecondNum, int ThirdNum)
{
Console.WriteLine("Sum is
{0}", FirstNum + SecondNum + ThirdNum);
}
public static void Add(int FirstNum, int SecondNum, int ThirdNum, int FourthNum)
{
Console.WriteLine("Sum is
{0}", FirstNum + SecondNum + ThirdNum +
FourthNum);
}
public static void Add(int FirstNum, float SecondNum)
{
Console.WriteLine("Sum is
{0}", FirstNum + SecondNum);
}
public static void Add(float FirstNum, float SecondNum)
{
Console.WriteLine("Sum is
{0}", FirstNum + SecondNum);
}
}
}
No comments:
Post a Comment