2
Reply

GetType() method

Maha

Maha

Mar 8 2012 4:30 PM
1.2k
In the following program instead of giving the type of the object, output gives the name of the constructor. Please explain the
reason for this.

using System;

class A
{
}

class B : A
{
}

class C : B
{
}

class Program
{
static void Main()
{
A a1 = new A();
A a2 = new B();
A a3 = new C();

Console.WriteLine(a1.GetType());
Console.WriteLine(a2.GetType());
Console.WriteLine(a3.GetType());

Console.ReadKey();
}
}
/*
A
B
C
*/

Answers (2)