in C# by (9.4k points)
0 like 0 dislike

How I can to find if an object is from a class but not superclass?

is object of class

1 Answer

0 like 0 dislike
by (9.4k points)

Like this:

typeof(SpecifiedClass) == obj.GetType()


if (Obj.GetType() == typeof(ClassName)) {}


class A {}
class B : A {}
A a = new A();
if (a.GetType() == typeof(A)) {} // returns true
A b = new B();
if (b.GetType() == typeof(A)) {} // returns false

Your answer

Try to answer the question as detailed as possible.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.