Function Overloading [Polymorphism] in C#

Function Overloading [Polymorphism] in C#
polymorphism in latin word which describes 'poly' means many 'morphs' means forms.
polymorphism has concept like function overloading...
This example Create function Add at three times but its parameter is not same.
Function overloading is the process of having the same name for 
functions but having different parameters (function signatures),
either in number or in type. Function overloading reduces the complexity
 of a program. Function overloading helps the user to use functions
without changing its name or the return type. To overload a function
we need to change the parameters inside the Function.





using Microsoft.VisualBasic;

using System;

using System.Collections;

using System.Collections.Generic;

using System.Data;

using System.Diagnostics;

partial class _Default : System.Web.UI.Page

{

     public class one

        {

               public int i;

               public int j;

               public int k;

               public int @add(int i)

               {

                       //function with one argument

                       return i;

               }

               public int @add(int i, int j)

               {

                       //function with two arguments

                       return i + j;

               }

               public int @add(int i, int j, int k)

               {

                       //function with three arguments

                       return i + j + k;

               }

        }

        protected void Page_Load(object sender, System.EventArgs e)

        {

               one two = new one();

               Response.Write(two.@add(10));

               //calls the function with one argument

               Response.Write(two.@add(10, 20));

               //calls the function with two arguments

               Response.Write(two.@add(10, 20, 30));

               //calls the function with three arguments

        }

        public _Default()

        {

               Load += Page_Load;

        }

}


Ebook Download
View all
milton
Read by 0 people
Download Now!
Learn
View all