Consider this code:
static void Main(string[] args)
{
Get<Student>(new Student());
System.Console.Read();
}
public static void Get<T>(T person)
{
Console.WriteLine("Generic function");
}
public static void Get(Person person)
{
person.Show();
}
This my Person Class:
class Person
{
public void Show()
{
Console.WriteLine("I am person");
}
}
class Student : Person
{
public new void Show()
{
Console.WriteLine("I am Student");
}
}
I call Get
and pass student to the method.Like this:
Get<Student>(new Student());
So i get this: Generic function
.But when i call Get
like this:
Get(new Student());
I expect thisGet(Person person)
to be called.but again call:Get<T>(T person)
.
Why Compiler has this behavior?