Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C# what is the equivalent of "is" keyword but using Type objects

An easy question I guess, but in the documentation of the Type class they only talk of interfaces on the GetInterfaces method.

i.e. typeof(ChildClass).XXX(typeof(ParentClass)

like image 537
ilcavero Avatar asked Dec 04 '22 14:12

ilcavero


1 Answers

It depends on what you need; IsAssignableFrom, perhaps:

bool stringIsObj = typeof(object).IsAssignableFrom(typeof(string));

or IsSubclassOf:

bool stringIsObj = typeof(string).IsSubclassOf(typeof(object));
like image 172
Marc Gravell Avatar answered Dec 26 '22 15:12

Marc Gravell