Monday, November 22, 2010

В чем разница между typeof и 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());
        }
    }

Будет напечатано:

    Base
    Derived

1 comment:

Anonymous said...

Спасибо понравилось !