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

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -