C# Tutorials - Herong's Tutorial Examples - v3.32, by Herong Yang
Method Overloading
This section describes what is method overloading - multiple methods in the same class with the same name but different method signatures.
A method is overloaded if there is another method with the same method name but a different method signature existing in the same class. A method signature includes the following elements:
and excludes the following elements:
// Overloads.cs // Copyright (c) 2008 HerongYang.com. All Rights Reserved. class Overloads { public static void Main() { Print(1); Print(12345678901234); Print((object)2); Print(3, 4); Print(new int[]{5,6}); } public static void Print(object o) { System.Console.WriteLine("Print(object o): {0}.", o.ToString()); } public static void Print(int i) { System.Console.WriteLine("Print(int i): {0}.", i); } public static void Print(long i) { System.Console.WriteLine("Print(long i): {0}.", i); } public static void Print(ref int i) { System.Console.WriteLine("Print(ref int i): {0}.", i); } public static void Print(int i, int j) { System.Console.WriteLine("Print(int i, int j): {0}, {1}.", i, j); } // public static void Print(int[] a) { // // identical to Print(params int[] a) // System.Console.WriteLine("Print(int[] a): {0}, {1}.", a[0], // a[1]); // } public static void Print(params int[] a) { System.Console.WriteLine("Print(params int[] a): {0}, {1}.", a[0],a[1]); } }
Output:
Print(int i): 1. Print(long i): 12345678901234. Print(object o): 2. Print(int i, int j): 3, 4. Print(params int[] i): 5, 6.
Two interesting notes:
Table of Contents
Logical Expressions and Conditional Statements
Visual C# 2010 Express Edition
"const" and "readonly" Variables
C# Compiler and Intermediate Language
Compiling C# Source Code Files
MSBuild - Microsoft Build Engine
System.Diagnostics.FileVersionInfo Class
WPF - Windows Presentation Foundation