Consider this code:
static void Main(string[] args)
{
Log("Test");//Call Log(object obj)
Log(new List<string>{"Test","Test2"});;//Also Call Log(object obj)
}
public static void Log(object obj)
{
Console.WriteLine(obj);
}
public static void Log(List<object> objects)
{
foreach (var obj in objects)
{
Console.WriteLine(obj);
}
}
In first line i call log with a string value and it invokes Log(object obj)
but in the second line i call Log
with list of string new List<string>{"Test","Test2"}
but compiler invoke Log(object obj)
instead of Log(List<object> objects)
.
Why compiler has this behavior?
How can i call the second log with list of string?