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

Dim instance As Type Dim c As Type Dim returnValue As Boolean returnValue = instance.IsAssignableFrom(c)
戻り値
true が返されるのは、c および現在の Type が同じ型を表している場合、現在の Type が c の継承可能な階層内にある場合、現在の Type が c に実装されるインターフェイスである場合、または c がジェネリック型パラメータであり、現在の Type が c の制約の 1 つを表している場合です。false が返されるのは、これらの条件がいずれも満たされない場合、または c が null 参照 (Visual Basic では Nothing) である場合です。

![]() |
---|
ジェネリック型定義は、クローズ構築型から割り当てることはできません。つまり、クローズ構築型 MyGenericList<int> (Visual Basic の場合は MyGenericList(Of Integer)) を型 MyGenericList<T> の変数に割り当てることはできません。 |

配列を使用する IsAssignableFrom メソッドの例を次に示します。
Imports System Class ArrayTypeTest Public Shared Sub Main() Dim i As Integer = 1 Dim array10(10) As Integer Dim array2(2) As Integer Dim array22(2, 2) As Integer Dim array24(2, 4) As Integer Dim array333(3, 3, 3) As Integer Dim array10Type As Type = array10.GetType() Dim array2Type As Type = array2.GetType() Dim array22Type As Type = array22.GetType() Dim array24Type As Type = array24.GetType() Dim array333Type As Type = array333.GetType() ' If X and Y are not both arrays, then return false. Console.WriteLine("Is int[2] assignable from int? {0}.", array2Type.IsAssignableFrom(i.GetType())) ' If X and Y have same type and rank, then return true. Console.WriteLine("Is int[2] assignable from int[10]? {0}.", array2Type.IsAssignableFrom(array10Type)) Console.WriteLine("Is int[2,2] assignable from int[2,4]? {0}.", array22Type.IsAssignableFrom(array24Type)) Console.WriteLine("Is int[2,4] assignable from int[2,2]? {0}.", array24Type.IsAssignableFrom(array22Type)) ' If X and Y do not have the same rank, then return false. Console.WriteLine("Is int[2,2] assignable from int[10]? {0}.", array22Type.IsAssignableFrom(array10Type)) Console.WriteLine("Is int[2,2] assignable from int[3,3,3]? {0}.", array22Type.IsAssignableFrom(array333Type)) Console.WriteLine("Is int[3,3,3] is assignable from int[2,2]? {0}.", array333Type.IsAssignableFrom(array22Type)) End Sub 'Main End Class 'ArrayTypeTest
using System; class ArrayTypeTest { public static void Main() { int i = 1; int [] array10 = new int [10]; int [] array2 = new int[2]; int [,]array22 = new int[2 ,2]; int [,]array24 = new int[2 ,4]; int [,,]array333 = new int[3 ,3,3]; Type array10Type = array10.GetType(); Type array2Type = array2.GetType(); Type array22Type = array22.GetType(); Type array24Type = array24.GetType(); Type array333Type = array333.GetType(); // If X and Y are not both arrays, then return false. Console.WriteLine("Is int[2] assignable from int? {0}.", array2Type.IsAssignableFrom(i.GetType())); // If X and Y have same type and rank, then return true. Console.WriteLine("Is int[2] assignable from int[10]? {0}.", array2Type.IsAssignableFrom(array10Type)); Console.WriteLine("Is int[2,2] assignable from int[2,4]? {0}.", array22Type.IsAssignableFrom(array24Type)); Console.WriteLine("Is int[2,4] assignable from int[2,2]? {0}.", array24Type.IsAssignableFrom(array22Type)); // If X and Y do not have the same rank, then return false. Console.WriteLine("Is int[2,2] assignable from int[10]? {0}.", array22Type.IsAssignableFrom(array10Type)); Console.WriteLine("Is int[2,2] assignable from int[3,3,3]? {0}.", array22Type.IsAssignableFrom(array333Type)); Console.WriteLine("Is int[3,3,3] assignable from int[2,2]? {0}.", array333Type.IsAssignableFrom(array22Type)); } }
using namespace System; int main() { Int32 i = 1; array<Int32>^array10 = gcnew array<Int32>(10); array<Int32>^array2 = gcnew array<Int32>(2); array<Int32, 2>^array22 = gcnew array<Int32,2>(2,2); array<Int32, 2>^array24 = gcnew array<Int32,2>(2,4); array<Int32, 3>^array333 = gcnew array<Int32,3>(3,3,3); Type^ array10Type = array10->GetType(); Type^ array2Type = array2->GetType(); Type^ array22Type = array22->GetType(); Type^ array24Type = array24->GetType(); Type^ array333Type = array333->GetType(); // If X and Y are not both arrays, then return false. Console::WriteLine( "Is Int32[2] assignable from Int32? {0}.", array2Type->IsAssignableFrom( i.GetType() ).ToString() ); // If X and Y have same type and rank, then return true. Console::WriteLine( "Is Int32[2] assignable from Int32[10]? {0}.", array2Type->IsAssignableFrom( array10Type ).ToString() ); Console::WriteLine( "Is Int32[2,2] assignable from Int32[2,4]? {0}.", array22Type->IsAssignableFrom( array24Type ).ToString() ); Console::WriteLine( "Is Int32[2,4] assignable from Int32[2,2]? {0}.", array24Type->IsAssignableFrom( array22Type ).ToString() ); // If X and Y do not have the same rank, then return false. Console::WriteLine( "Is Int32[2,2] assignable from Int32[10]? {0}.", array22Type->IsAssignableFrom( array10Type ).ToString() ); Console::WriteLine( "Is Int32[2,2] assignable from Int32[3,3,3]? {0}.", array22Type->IsAssignableFrom( array333Type ).ToString() ); Console::WriteLine( "Is Int32[3,3,3] assignable from int[2,2]? {0}.", array333Type->IsAssignableFrom( array22Type ).ToString() ); }
import System.*; class ArrayTypeTest { public static void main(String[] args) { int i = 1; int array10[] = new int[10]; int array2[] = new int[2]; int array22[,] = new int[2, 2]; int array24[,] = new int[2, 4]; int array333[, ,] = new int[3, 3, 3]; Type array10Type = array10.GetType(); Type array2Type = array2.GetType(); Type array22Type = array22.GetType(); Type array24Type = array24.GetType(); Type array333Type = array333.GetType(); // If X and Y are not both arrays, then return false. Console.WriteLine("Is int[2] assignable from int? {0}.", System.Convert.ToString(array2Type.IsAssignableFrom( ((Int32)i).GetType()))); // If X and Y have same type and rank, then return true. Console.WriteLine("Is int[2] assignable from int[10]? {0}.", System.Convert.ToString(array2Type.IsAssignableFrom(array10Type))); Console.WriteLine("Is int[2,2] assignable from int[2,4]? {0}.", System.Convert.ToString(array22Type.IsAssignableFrom( array24Type))); Console.WriteLine("Is int[2,4] assignable from int[2,2]? {0}.", System.Convert.ToString(array24Type.IsAssignableFrom( array22Type))); // If X and Y do not have the same rank, then return false. Console.WriteLine("Is int[2,2] assignable from int[10]? {0}.", System.Convert.ToString(array22Type.IsAssignableFrom( array10Type))); Console.WriteLine("Is int[2,2] assignable from int[3,3,3]? {0}.", System.Convert.ToString(array22Type.IsAssignableFrom( array333Type))); Console.WriteLine("Is int[3,3,3] assignable from int[2,2]? {0}.", System.Convert.ToString(array333Type.IsAssignableFrom( array22Type))); } //main } //ArrayTypeTest

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.IsAssignableFrom メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As _Type Dim c As Type Dim returnValue As Boolean returnValue = instance.IsAssignableFrom(c)
戻り値
true が返されるのは、c および現在の Type が同じ型を表している場合、現在の Type が c の継承可能な階層内にある場合、現在の Type が c に実装されるインターフェイスである場合、または c がジェネリック型パラメータであり、現在の Type が c の制約の 1 つを表している場合です。false が返されるのは、これらの条件がいずれも満たされない場合、または c が null 参照 (Visual Basic では Nothing) である場合です。


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.IsAssignableFromのページへのリンク