Type.IsAssignableTo(Type) 方法


判斷現有類型是否可以指派至指定 targetType的變數。Determines whether the current type can be assigned to a variable of the specified targetType.

 bool IsAssignableTo(Type ^ targetType);
public bool IsAssignableTo (Type? targetType);
member this.IsAssignableTo : Type -> bool
Public Function IsAssignableTo (targetType As Type) As Boolean



要與目前的類型比較的類型。The type to compare with the current type.



true (下列任何條件成立時):true if any of the following conditions is true: - 現有執行個體與 targetType代表相同的型別。- The current instance and targetType represent the same type.

- 現有類型是直接或間接衍生自 targetType- The current type is derived either directly or indirectly from targetType. 現有類型如果繼承自 targetType,則會直接衍生自 targetType;現有類型如果是從繼承自 targetType 的一或多個一連串類別,則會直接衍生自 targetTypeThe current type is derived directly from targetType if it inherits from targetType; the current type is derived indirectly from targetType if it inherits from a succession of one or more classes that inherit from targetType.

  • targetType 是目前型別所實行的介面。
  • targetType is an interface that the current type implements.
  • - 目前類型是泛型類型參數,而 targetType代表目前類型的其中一個限制式。- The current type is a generic type parameter, and targetType represents one of the constraints of the current type.

    - 現有類型代表實質型別,而 targetType 代表在 Visual Basic 中 Nullable<c> (Nullable(Of c))。- The current type represents a value type, and targetType represents Nullable<c> (Nullable(Of c) in Visual Basic).

    如果以上條件都不成立,或是 targetTypethisnull,則為 falsefalse if none of these conditions are true, or if targetType or this is null.