C# TypeInfo BaseType
Description
TypeInfo BaseType
Gets the type from which the current
Type directly inherits.
Syntax
TypeInfo.BaseType
has the following syntax.
public abstract Type BaseType { get; }
Example
The following example demonstrates using the BaseType property.
using System;/*w ww. j a v a 2 s . c om*/
class TestType
{
public static void Main()
{
Type tt = typeof(int);
Console.WriteLine("{0} inherits from {1}.", tt,tt.BaseType);
foreach (var t in typeof(TestType).Assembly.GetTypes())
{
Console.WriteLine("{0} derived from: ", t.FullName);
var derived = t;
do {
derived = derived.BaseType;
if (derived != null)
Console.WriteLine(" {0}", derived.FullName);
} while (derived != null);
Console.WriteLine();
}
}
}
public class A {}
public class B : A
{}
public class C : B
{}
The code above generates the following result.