在C#是什么&QUOT相当于是"关键字,但使用Type对象 [英] In C# what is the equivalent of "is" keyword but using Type objects

查看:144
本文介绍了在C#是什么&QUOT相当于是"关键字,但使用Type对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简单的问题我猜,但Type类他们只对GetInterfaces方法接口谈话的文档中。

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

即。 typeof运算(ChildClass).XXX(typeof运算(父类)

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

推荐答案

这取决于你所需要的; IsAssignableFrom,也许是:

It depends on what you need; IsAssignableFrom, perhaps:

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

IsSubclassOf

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

这篇关于在C#是什么&QUOT相当于是"关键字,但使用Type对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆