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.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version