I got this question from someone just starting out on the .NET platform. He is used to hit F12 (go to definition) on types and then figure out the inheritance chain. However, he couldn't do that say on a number (int) or array.
The solution is to write a simple recursive routine as follows
static void Dump(Type t)
{
if (t != null)
{
Dump(t.BaseType);
Console.WriteLine(t.ToString());
}
}
The routine can be called as follows
Dump(typeof(int));No marks for guessing the output though :)
Dump("abc".GetType());
Dump(1.GetType());
Dump(typeof(EventAttributes));
No comments:
Post a Comment