0

My class:

public class Foo
{
    public override string ToString()
    {
        return "Bar";
    }
    public string ToString(params int[] values)
    {
        return "Buz";
    }
    public void DoFoo()
    {
    }
    public void DoFoo(params int[] values)
    {
    }
}

When calling ToString() on expression of type Foo, the compiler chooses the overload with params (passing empty int array). However, when I call DoFoo() it picks the overload without the params, as expected. What is the reason?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Mr Anderson
  • 2,200
  • 13
  • 23
  • http://csharpindepth.com/Articles/General/Overloading.aspx – ASh Oct 26 '17 at 18:43
  • I disagree this is an exact duplicate of those questions. The answer https://stackoverflow.com/a/3677779/832705 does give solid reasoning, though. – stackuser83 Oct 26 '17 at 19:22
  • @stackuser83 I disagreed with the dupe-hammer at first as well, but the link from Eric Lippert's answer helped me: https://blogs.msdn.microsoft.com/ericlippert/2007/09/04/future-breaking-changes-part-three/ – Mr Anderson Oct 26 '17 at 19:26

0 Answers0