Hi,

I have a very strange problem with function overloading in C# when there are two possible overloads: one with enum, one with object as parameter. When i call the method with parameter 0 - the enum version is called. When I choose any other value - the object version is called. The short code snippet explains the problem:

Code:
    class Program
    {
        enum Bar
        {
            Value1,
            Value2,
            Value3
        }

        static void Main(string[] args)
        {
            Foo(0);
            Foo(1);
            Console.ReadLine();
        }

        static void Foo(object a)
        {
            Console.WriteLine("object");
        }

        static void Foo(Bar a)
        {
            Console.WriteLine("enum");
        }
    }
Could anyone explain this strange behavior?

This is not just a theoretical or academical problem - I came across it when adding parameters to commands in Npgsql v1.0. This sort of language construct is used there and it causes my code do behave improperly (0 is added as NULL, because invalid overload of NpgsqlParametersCollection.Add() is used).