3

Can somebody explain why C# takes method static long Foo(params object[] args) for second expression Foo(null)? Foo(object a) has the correct signature to be called too.

How I can find the answer myself? I tried to look through ILDASM, but it doesn't help :(.

class Bar {};

static short Foo<T>(params T[] args)
{
    return 4;
}

static long Foo(params object[] args)
{
    return 3;
}

static int Foo(object a, object b)
{
    return 2;
}
static byte Foo(object a)
{
    return 1;
}

static void Main(string[] args)
{
    Console.WriteLine(Foo() + Foo(null) + Foo(new Bar()) + Foo(new Bar(), new Bar()));
}
MarredCheese
  • 17,541
  • 8
  • 92
  • 91
Ilya Shmin
  • 126
  • 1
  • 9

0 Answers0