更新时间:2023-02-07 20:28:57
与Java的 obj等效。 C#中的getClass()。isInstance(otherObj)
如下:
bool result = obj.GetType().IsAssignableFrom(otherObj.GetType());
请注意,尽管Java和C#均可在运行时类型对象上运行(Java java.lang.Class
≣ obj
的C# System.Type
)(通过 .getClass()
与 .getType()
),Java的 isInstance
将对象作为参数,而C#的 IsAssignableFrom
期望另一个 System.Type
对象。
Note that while both Java and C# work on the runtime type object (Java java.lang.Class
≣ C# System.Type
) of an obj
(via .getClass()
vs .getType()
), Java’s isInstance
takes an object as its argument, whereas C#’s IsAssignableFrom
expects another System.Type
object.