Mega Code Archive

 
Categories / C# Book / 01 Language Basics
 

0136 Overloading and Resolution

When an overload is called, the most specific type has precedence: using System; class Person { } class Employee : Person { } class Program { static void aMethod(Person p) { Console.WriteLine("Person"); } static void aMethod(Employee e) { Console.WriteLine("Employee"); } static void Main(string[] args) { Person p = new Employee(); aMethod(p); } } The output: Person