How does the compiler choose which method to call when a parameter type is ambiguous?

Posted by Darksider on Stack Overflow See other posts from Stack Overflow or by Darksider
Published on 2010-04-23T06:31:04Z Indexed on 2010/04/23 6:33 UTC
Read the original article Hit count: 213

Filed under:
|

I have the following code:

    [TestMethod]
    public void TestFoo()
    {
        Foo(null);
    }

    private void Foo (object bar)
    {
        Console.WriteLine("Foo - object");
    }

    private void Foo (string bar)
    {
        Console.WriteLine("Foo - string");
    }

and when I run the test "TestFoo()", the console output is "Foo - string". How does the compiler decide which method to call?

© Stack Overflow or respective owner

Related posts about c#

Related posts about compiler