Thursday, August 5, 2010

program to implement function overloading

Write a program to implement function overloading
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Csharp
{
    class polymorphism
    {
     
        public static void Main(string[] args)
        {
            polymorphism obj = new polymorphism();
            obj.add(2.3F, 3.2F);
            obj.add(2, 3);
            obj.add(2.6m, 3.2m);
            obj.disp('b', 5);
            obj.disp(5, 'b');
            obj.display('b');
            obj.display(5, 'b');
            Console.ReadLine();
          
        }
        /// <summary>
        /// (a)Type of parameters
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        public void add(int a, int b)
        {
            int sum;
            sum = a + b;
            Console.WriteLine("{0}", sum);
        }
        public void add(float a, float b)
        {
            float sum;
            sum = a + b;
            Console.WriteLine("{0}", sum);
        }
        public void add(decimal a, decimal b)
        {
            decimal sum;
            sum = a + b;
            Console.WriteLine("{0}", sum);
        }
        /// <summary>
        /// (b)number of parameters
        /// </summary>
        /// <param name="a"></param>
        public void display(int a,char b)
        {
          
            Console.WriteLine("{0}{1}", a,b);
        }
        public void display(char a)
        {
         
            Console.WriteLine("{0}", a);
        }
        /// <summary>
        /// (c)seqeunce of parameters
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        public void disp(int a, char b)
        {
          
            Console.WriteLine("{0}{1}", a, b);
        }
        public void disp(char b, int a)
        {
        
            Console.WriteLine("{0}{1}", a, b);
        }
    }

No comments:

Post a Comment