Tuesday 8 September 2015

Overloading

Overloading
Overloading process is called early binding ,or static linking,
Static binding.It is also known as compile time polymorphism

using System;

namespace operation_Overloading
{
    class addition
    {
        public void add(int a, int b)
        {
            int r = a + b;
            Console.WriteLine("Addition of two Number = " + r);
        }
        public void add(string p, string q)
        {
            Console.WriteLine("Concatenation of two string = " + p +q);
        }
    }
   
    class Program
    {
        static void Main(string[] args)
        {
            //add two integer values
            addition ad = new addition();
            Console.WriteLine("Enter Two Integer values");
            int m =int.Parse(Console.ReadLine());
            int n = int.Parse(Console.ReadLine());
            ad.add(m, n); //call add method which hold integer parameter

            //add two string values
            Console.WriteLine("Enter Two String values");
            string s1 = Console.ReadLine();
            string s2 = Console.ReadLine();
            ad.add(s1, s2); //call add method which hold string parameter
            Console.ReadLine();
        }
    }
}

Here two Add() method are call
ad.add(m, n);
ad.add(s1,s2);
Here One method (Add()) work as a two form,So it is called a polymorphism.