Type.IsSubclassOf メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As Type Dim c As Type Dim returnValue As Boolean returnValue = instance.IsSubclassOf(c)
戻り値
c パラメータによって表される Type と現在の Type がクラスを表し、現在の Type によって表されるクラスが c によって表されるクラスから派生している場合は true。それ以外の場合は false。c と現在の Type が同じクラスを表す場合、このメソッドは false も返します。


IsSubclassOf メソッドは、インターフェイスが別のインターフェイスから派生しているかどうか、またはクラスがインターフェイスを実装しているかどうかを判断するために使用できません。この処理には、GetInterface メソッドを使用します。
現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合は、クラス制約から派生しています。クラス制約がない場合は System.Object から派生しています。
![]() |
---|
IsSubclassOf が IsAssignableFrom の逆である場合、t1.IsSubclassOf(t2) が true であれば、t2.IsAssignableFrom(t1) も true です。 |

Imports System Public Interface IMyIfc End Interface 'IMyIfc Public Interface IDerived Inherits IMyIfc End Interface 'IDerived Public Class Class1 Implements IMyIfc End Class 'Class1 Public Class MyDerivedClass Inherits Class1 End Class 'MyDerivedClass Class IsSubclassTest Public Shared Sub Main() Dim imyifcType As Type = GetType(IMyIfc) Dim imyderivedType As Type = GetType(IDerived) Dim mc As New Class1() Dim mcType As Type = mc.GetType() Dim mdc = New MyDerivedClass() Dim mdcType As Type = mdc.GetType() Dim array(10) As Integer Dim arrayOfIntsType As Type = array.GetType() Dim arrayType As Type = GetType(Array) Console.WriteLine("Is Array a derived class of int[]? {0}", arrayType.IsSubclassOf(arrayOfIntsType)) Console.WriteLine("Is int [] a derived class of Array? {0}", arrayOfIntsType.IsSubclassOf(arrayType)) Console.WriteLine("Is IMyIfc a derived class of IDerived? {0}", imyifcType.IsSubclassOf(imyderivedType)) Console.WriteLine("Is myclass a derived class of Class1? {0}", mcType.IsSubclassOf(mcType)) Console.WriteLine("Is myderivedclass a derived class of Class1? {0}", mdcType.IsSubclassOf(mcType)) End Sub 'Main End Class 'IsSubclassTest
using System; public interface IMyIfc {} public interface IDerived : IMyIfc {} public class Class1 : IMyIfc {} public class MyDerivedClass : Class1 {} class IsSubclassTest { public static void Main() { Type imyifcType = typeof(IMyIfc); Type imyderivedType = typeof(IDerived); Class1 mc = new Class1(); Type mcType = mc.GetType(); Class1 mdc = new MyDerivedClass(); Type mdcType = mdc.GetType(); int [] array = new int [10]; Type arrayOfIntsType = array.GetType(); Type arrayType = typeof(Array); Console.WriteLine("Is Array a derived class of int[]? {0}", arrayType.IsSubclassOf(arrayOfIntsType)); Console.WriteLine("Is int [] a derived class of Array? {0}", arrayOfIntsType.IsSubclassOf(arrayType)); Console.WriteLine("Is IMyIfc a derived class of IDerived? {0}", imyifcType.IsSubclassOf(imyderivedType)); Console.WriteLine("Is myclass a derived class of Class1? {0}", mcType.IsSubclassOf(mcType)); Console.WriteLine("Is myderivedclass a derived class of Class1? {0}", mdcType.IsSubclassOf(mcType)); } }
using namespace System; interface class IMyIfc{}; interface class IDerived: public IMyIfc{}; public ref class Class1: public IMyIfc{}; public ref class MyDerivedClass: public Class1{}; int main() { Type^ imyifcType = IMyIfc::typeid; Type^ imyderivedType = IDerived::typeid; Class1^ mc = gcnew Class1; Type^ mcType = mc->GetType(); Class1^ mdc = gcnew MyDerivedClass; Type^ mdcType = mdc->GetType(); array<Int32>^arr = gcnew array<Int32>(10); Type^ arrayOfIntsType = arr->GetType(); Type^ arrayType = Array::typeid; Console::WriteLine( "Is Array a derived class of Int32[]? {0}", arrayType->IsSubclassOf( arrayOfIntsType ).ToString() ); Console::WriteLine( "Is Int32[] a derived class of Array? {0}", arrayOfIntsType->IsSubclassOf( arrayType ).ToString() ); Console::WriteLine( "Is IMyIfc a derived class of IDerived? {0}", imyifcType->IsSubclassOf( imyderivedType ).ToString() ); Console::WriteLine( "Is myclass a derived class of Class1? {0}", mcType->IsSubclassOf( mcType ).ToString() ); Console::WriteLine( "Is myderivedclass a derived class of Class1? {0}", mdcType->IsSubclassOf( mcType ).ToString() ); }
import System.*; public interface IMyIfc { } //IMyIfc public interface IDerived extends IMyIfc { } //IDerived public class Class1 implements IMyIfc { } //Class1 public class MyDerivedClass extends Class1 { } //MyDerivedClass class IsSubclassTest { public static void main(String[] args) { Type iMyIfcType = IMyIfc.class.ToType(); Type iMyDerivedType = IDerived.class.ToType(); Class1 mc = new Class1(); Type mcType = mc.GetType(); Class1 mdc = new MyDerivedClass(); Type mdcType = mdc.GetType(); int array[] = new int[10]; Type arrayOfIntsType = array.GetType(); Type arrayType = Array.class.ToType(); Console.WriteLine("Is Array a derived class of int[]? {0}", System.Convert.ToString(arrayType.IsSubclassOf(arrayOfIntsType))); Console.WriteLine("Is int [] a derived class of Array? {0}", System.Convert.ToString(arrayOfIntsType.IsSubclassOf(arrayType))); Console.WriteLine("Is IMyIfc a derived class of IDerived? {0}", System.Convert.ToString(iMyIfcType.IsSubclassOf(iMyDerivedType))); Console.WriteLine("Is myclass a derived class of Class1? {0}", System.Convert.ToString(mcType.IsSubclassOf(mcType))); Console.WriteLine("Is myderivedclass a derived class of Class1? {0}", System.Convert.ToString(mdcType.IsSubclassOf(mcType))); } //main } //IsSubclassTest

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


_Type.IsSubclassOf メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As _Type Dim c As Type Dim returnValue As Boolean returnValue = instance.IsSubclassOf(c)
戻り値
c パラメータによって表される Type と現在の Type がクラスを表し、現在の Type によって表されるクラスが c によって表されるクラスから派生している場合は true。それ以外の場合は false。c と現在の Type が同じクラスを表す場合、このメソッドは false も返します。

このメソッドは、アンマネージ コードからマネージ クラスにアクセスするためのメソッドであるため、マネージ コードからは呼び出さないでください。
Type.IsSubclassOf メソッドは、現在の Type によって表されるクラスが、指定した Type によって表されるクラスから派生しているかどうかを判断します。

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- Type.IsSubclassOfのページへのリンク