reflection - What is the C# equivalent to Java's isInstance()? -
i know of is , as instanceof, reflective isinstance() method?
the equivalent of java’s obj.getclass().isinstance(otherobj) in c# follows:
bool result = obj.gettype().isassignablefrom(otherobj.gettype()); note while both java , c# work on runtime type object (java java.lang.class ≣ c# system.type) of obj (via .getclass() vs .gettype()), java’s isinstance takes object argument, whereas c#’s isassignablefrom expects system.type object.
Comments
Post a Comment