I have two overloaded methods one is expecting object type parameter and other generic params list. I'm trying to understand that when which function will be called. I'm passing string object and it's calling generic params method.
class Program
{
static void Main(string[] args)
{
string s = "string";
Invoke(s);
Console.ReadLine();
}
static void Invoke(object s)
{
Console.WriteLine("Object param invoked");
}
static void Invoke<T>(params T[] values)
{
Console.WriteLine("Params method invoked");
}
}
It's giving output as: 'Params method invoked'.
But I'm not sure why always this method called.I also tried with passing int parameter but again params method invoked. Please if anyone can explain this for me. Thanks.