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
*/
GetType() method
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

VulpesRank #55 · 29.2K reputationPosted Mar 8, 2012, 11:39 AM EST
A constructor always has the same name as its containing type.
Posted Mar 8, 2012, 12:27 PM EST