Function Overloading

C#—and the .NET Common Language Runtime (CLR)in general—enables you to create methods, with the same name, that vary only in their number and/or type of arguments.

Function overloading is one means by which .NET allows for polymorphism which is the notion that a single entity can perform different functions or a single function different ways but appear as only one object. Listing A.32 shows an example of function overloading.

Listing A.32. Function Overloading
 using System; class MyClass{ public int add(int num1, int num2){ return num1 + num2; } public double add(double num1, double num2){ return num1 + num2; } public string add(string string1, string string2){ return string1 + string2; } public static void Main(){ MyClass ...

Get Building e-Commerce Sites with the .NET Framework now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.