How can you overload a method?

Different parameter data types, different number of parameters, different order of parameters.

Showing Answers 1 - 4 of 4 Answers

learnasp

  • Oct 11th, 2007
 

A method can be overloaded by having different parameters as in different type of parameters and well different number of parameters.

Also, if the parameter types are different than you can also have different return type.

example :

you can have

public int MethodA()
{
return 5;
}

and

public int MethodA( int i)
{
return i;
}

and

public string MethodA(string i)
{
return i;
}

but not

public string MethodA(int i)
{
return "alpha";
}


because a method with one int as parameter already exists. Hence you can have different return types but then the parameters should be different.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions