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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.