Consider following example:
public class Program
{
public enum ExampleEnum
{
Value1,
Value2
}
public static void Main(string[] args)
{
OverloadedMethod(0);
Int32 value = 0;
OverloadedMethod(value);
}
private static void OverloadedMethod(ExampleEnum arg)
{
Console.WriteLine("Overload with enum");
}
private static void OverloadedMethod(object arg)
{
Console.WriteLine("Overload with object");
}
}
Program outputs are: "Overload with enum", "Overload with object". Why is it so? How exactly does C# compiler interprets direct values? Side note: output is the same when zero is explicitly casted to Int32:
public static void Main(string[] args)
{
OverloadedMethod((Int32)0);
Int32 value = 0;
OverloadedMethod(value);
}