Pages

Sunday, May 12, 2013

overloaded in c#

definition:

When a method appears multiple times with the same name and with different signature then the method is said to be overloading.

Signature: 

     It is a combination of method name and parameters list.

Types of overloading:

1.method overloading
2.constructors overloaded

Example:(method overloading)

  { 

D d=new D():

d.m(20,"palle");
d.m("tech",30);
  }

public class D
{
  public int m(int x,string y)
  {
     return 10;
  }
public int m(string a,int b);
  {
   return 5;
  }
}
Note: here method name same and signature name differ

Example:(constructors overloaded)

   {
     Doctor d1=new Doctor(36,"rakesh",4);
     Doctor d2=new Doctor(38,"ritesh");
   }
}
public class Doctor
 {
  public int Age;
  public string Name;
  public string Expe;
public Doctor(int age,string name,int expe)
  Age=age;
  Name=name;
 Expe=expe;
}
public Doctor(int age,string name)
{
  Age=age;
  Name=name;
 }
}
Note:Here two method name same and the method name should be same as class name as per defination
 

No comments:

Post a Comment