Type.IsAssignableTo(Type) 方法
定义
确定当前类型是否可分配给指定 targetType 的变量。Determines whether the current type can be assigned to a variable of the specified targetType.
public:
bool IsAssignableTo(Type ^ targetType);
public bool IsAssignableTo (Type? targetType);
member this.IsAssignableTo : Type -> bool
Public Function IsAssignableTo (targetType As Type) As Boolean
参数
- targetType
- Type
要与当前类型进行比较的类型。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 继承的一系列一个或多个类,则它是从 targetType 间接派生的。The 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 表示 Nullable<c>(在 Visual Basic 中为 Nullable(Of c))。- The current type represents a value type, and targetType represents Nullable<c> (Nullable(Of c) in Visual Basic).
如果不满足上述任何一个条件,或者如果 targetType 或 this 为 null,则为 false。false if none of these conditions are true, or if targetType or this is null.