Type.IsAssignableFrom Method

Determines whether an instance of the current Type can be assigned from an instance of the specified Type.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

virtual bool IsAssignableFrom (
	Type^ c
public boolean IsAssignableFrom (
	Type c
public function IsAssignableFrom (
	c : Type
) : boolean



The Type to compare with the current Type.

Return Value

true if c and the current Type represent the same type, or if the current Type is in the inheritance hierarchy of c, or if the current Type is an interface that c implements, or if c is a generic type parameter and the current Type represents one of the constraints of c. false if none of these conditions are true, or if c is a null reference (Nothing in Visual Basic).

This method can be overridden by a derived class.


A generic type definition is not assignable from a closed constructed type. That is, you cannot assign the closed constructed type MyGenericList<int> (MyGenericList(Of Integer) in Visual Basic) to a variable of type MyGenericList<T>.

Determine the element types of a Type using GetElementType.

The following example demonstrates the IsAssignableFrom method using arrays.

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}.",

        // If X and Y have same type and rank, then return true.
        Console.WriteLine("Is int[2] assignable from int[10]? {0}.", 
        Console.WriteLine("Is int[2,2] assignable from int[2,4]? {0}.",
        Console.WriteLine("Is int[2,4] assignable from int[2,2]? {0}.",

        // If X and Y do not have the same rank, then return false.
        Console.WriteLine("Is int[2,2] assignable from int[10]? {0}.",
        Console.WriteLine("Is int[2,2] assignable from int[3,3,3]? {0}.",
        Console.WriteLine("Is int[3,3,3] assignable from int[2,2]? {0}.",
    } //main
} //ArrayTypeTest

This code produces the following output:

int[2] is assignable from int? False
     int[2] is assignable from int[10]? True
     int[2,2] is assignable from int[2,4]? True
     int[2,4] is assignable from int[2,2]? True
     int[2,2] is assignable from int[10]? False
     int[2,2] is assignable from int[3,3,3]? False
    int[3,3,3] is assignable from int[2,2]? False

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions