75
typeof(foo) is converted into a constant during compiletime. foo.GetType() happens at runtime.
typeof(foo) also converts directly into a constant of its type (ie foo), so doing this would fail:
public class foo
{
}
public class bar : foo
{
}
bar myBar = new bar();
// Would fail, even though bar is a child of foo.
if (myBar.getType == typeof(foo))
// However this Would work
if (myBar is foo)
typeof is executed at compile time while GetType at runtime. That's what is so different about these two methods. That's why when you deal with type hierarchy, you can find out the exact type name of a type simply by running GetType.
public Type WhoAreYou(Base base)
{
base.GetType();
}