O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.14. Function Overloading

Two or more functions can be given the same name if the parameter list of each function is unique either by the type or by the number of parameters. For example, the following five declarations represent overloaded instances of a method called message():

class MessageHandler
{
   public void message(){ ... }
   public void message( char ch ){ ... }
   public void message( string msg ){ ... }
   public void message( string msg,int val ){ ... }
   public void message( string msg,int v1,int v2 ){ ... }
}

How does the compiler know which instance of an overloaded function to invoke? It compares the actual arguments supplied to the function invocation against the parameters of each overloaded instance, choosing the best match.

The return ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required