C# Type BaseType
Description
Type BaseType
gets the type from which the current Type
directly inherits.
Syntax
Type.BaseType
has the following syntax.
public abstract Type BaseType { get; }
Example
The following example demonstrates using the BaseType property.
/*from ww w .j a v a2s.co m*/
using System;
class TestType
{
public static void Main()
{
Type tt = typeof(int);
Console.WriteLine("{0} inherits from {1}.", tt,tt.BaseType);
foreach (var t in typeof(C).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.