Out of curiosity, why is Log(null)
not an ambiguous call in this scenario?
class Program
{
static void Main(string[] args)
{
Log(null); // Output is "String"
}
static void Log(object value)
{
Console.WriteLine("Object");
}
static void Log(string value)
{
Console.WriteLine("String");
}
}
As both Log(object)
and Log(string)
accepts null
as parameter I was expecting the compiler to give me an ambiguous call error, but instead it chooses to call Log(string)
. Why not Log(object)
?