P
P
Pragma Games2022-02-06 12:03:55
C++ / C#
Pragma Games, 2022-02-06 12:03:55

When will Type.IsInstanceOfType(Type) and Type.IsAssignableFrom(Type) give different results with the same input parameter?

Hello. Type.IsInstanceOfType(Type) checks whether the current type is in the inheritance hierarchy of the object represented by the type, or if the current type implements the target type interface, and Type.IsAssignableFrom(Type) determines whether an instance of the specified type can be assigned to a target type variable. As far as I understand, the second method can, for example, tell us whether an int can be cast to a float , unlike the first one. But can these date methods produce different results if both types are classes.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
@
@insighter, 2022-02-06
_

I don't think it's worth bothering with it at all.
When there is an instance of an object, then you can check it through IsInstanceOfType, when only data types then IsAssignableFrom

the method can for example tell us if an int can be cast to a float

This is impossible, inheritance and conversion of meaningful data types are completely different things
PS Usually I adhere to this practice: I write as I understand intuitively, if problems arise, I start digging.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question