What is the difference between typeof and GetType()?
class Base { }
class Derived : Base { }
class Program
{
static void Main()
{
ShowType( new Derived() );
}
static void ShowType( Base b )
{
Console.WriteLine(typeof(Base));
Console.WriteLine(b.GetType());
}
}
gives the following output:
Base
Derived
Comments