0

Please, consider the following code:

static void foo(object v)
{
    System.Console.WriteLine(v.GetType());
}

static void foo(OleDbType v)
{
    System.Console.WriteLine(v.GetType());
}

static void Main(string[] args)
{
    foo(1);
    foo(0);
    foo(2);
}

The output is:

System.Int32
System.Data.OleDb.OleDbType
System.Int32

So foo(0) is resolved to static void foo(OleDbType) and the other calls are resolved to static void foo(object)

I'd expect all the calls to be resolved to the same method, why this happens?

Matteo Umili
  • 3,412
  • 1
  • 19
  • 31

1 Answers1

0

There is an implicit conversion from the constant 0 to any enum type, so foo(0) matches the overload with the OleDbType enum parameter.

Lee
  • 142,018
  • 20
  • 234
  • 287