Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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)

public virtual bool IsAssignableFrom(
	Type c


Type: System.Type
The Type to compare with the current Type.

Return Value

Type: System.Boolean
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 null.

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>.

You can determine the element types of a Type using GetElementType.

If the c parameter is of type TypeBuilder, the result is based on the type that is to be built. The following code example demonstrates this using a built type named B.

TypeBuilder b1 = moduleBuilder.DefineType("B", TypeAttributes.Public, typeof(A));
// Returns true:

The following example demonstrates the IsAssignableFrom method using defined classes, integer arrays, and generics.

using System;
using System.Collections.Generic;
class Example
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
      // Demonstrate classes:
      outputBlock.Text += "Defned Classes:" + "\n";
      Room room1 = new Room();
      Kitchen kitchen1 = new Kitchen();
      Bedroom bedroom1 = new Bedroom();
      Guestroom guestroom1 = new Guestroom();
      MasterBedroom masterbedroom1 = new MasterBedroom();

      Type room1Type = room1.GetType();
      Type kitchen1Type = kitchen1.GetType();
      Type bedroom1Type = bedroom1.GetType();
      Type guestroom1Type = guestroom1.GetType();
      Type masterbedroom1Type = masterbedroom1.GetType();

      outputBlock.Text += String.Format("room assignable from kitchen: {0}\n", 
      outputBlock.Text += String.Format("bedroom assignable from guestroom: {0}\n", 
      outputBlock.Text += String.Format("kitchen assignable from masterbedroom: {0}\n", 

      // Demonstrate arrays:
      outputBlock.Text += "\n";
      outputBlock.Text += "Integer arrays:\n";

      int[] array2 = new int[2];
      int[] array10 = new int[10];
      int[,] array22 = new int[2, 2];
      int[,] array24 = new int[2, 4];

      Type array2Type = array2.GetType();
      Type array10Type = array10.GetType();
      Type array22Type = array22.GetType();
      Type array24Type = array24.GetType();

      outputBlock.Text += String.Format("int[2] assignable from int[10]: {0}\n", 
      outputBlock.Text += String.Format("int[2] assignable from int[2,4]: {0}\n", 
      outputBlock.Text += String.Format("int[2,4] assignable from int[2,2]: {0}\n", 

      // Demonstrate generics:
      outputBlock.Text += "\n";
      outputBlock.Text += "Generics:\n";

      // Note that "int?[]" is the same as "Nullable<int>[]"
      int?[] arrayNull = new int?[10];
      List<int> genIntList = new List<int>();
      List<object> genObjList = new List<object>();
      List<Exception> genExList = new List<Exception>();

      Type arrayNullType = arrayNull.GetType();
      Type genIntListType = genIntList.GetType();
      Type genObjListType = genObjList.GetType();
      Type genExListType = genExList.GetType();

      outputBlock.Text += String.Format("int[10] assignable from int?[10]: {0}\n", 
      outputBlock.Text += String.Format("List<object> assignable from List<Exception>: {0}\n", 
      outputBlock.Text += String.Format("List<object> assignable from List<int>: {0}\n", 
class Room

class Kitchen : Room

class Bedroom : Room

class Guestroom : Bedroom

class MasterBedroom : Bedroom

/* This code produces the following output:

Defined Classes:
room assignable from kitchen: true
bedroom assignable from guestroom: true
kitchen assignable from masterbedroom: false

Integer arrays:
int[2] assignable from int[10]: true
int[2] assignable from int[2,4]: false
int[2,4] assignable from int[2,2]: true

int[10] assignable from int?[10]: false
List<object> assignable from List<Exception>: false
List<object> assignable from List<int>: false


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

© 2017 Microsoft