Home >Backend Development >C#.Net Tutorial >What is the C# equivalent of Java's isInstance()?

What is the C# equivalent of Java's isInstance()?

WBOY
WBOYforward
2023-09-06 16:33:041187browse

C# 中相当于 Java 的 isInstance() 的是什么?

java.lang.Class.isInstance() Determines whether the specified Object is compatible with assignment The object represented by this class

Java's isInstance() method is equivalent to IsAssignableFrom() in C#.

The other simplest method equivalent to isInstance() is -

bool res = (ob is DemoClass);

You can also use Type.IsInstanceOfType to achieve the same result -

ob.GetType().IsInstanceOfType(otherOb)

The above is the detailed content of What is the C# equivalent of Java's isInstance()?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete