C#中:你如何获取类'基地班呢? [英] C# : how do you obtain a class' base class?
本文介绍了C#中:你如何获取类'基地班呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C#中,一个人如何获得对基类的给定类的参考?
In C#, how does one obtain a reference to the base class of a given class?
例如,假设你有一定的阶级, MyClass的
,和你想获得对 MyClass的
'超类的引用。
For example, suppose you have a certain class, MyClass
, and you want to obtain a reference to MyClass
' superclass.
我想到的是这样的:
Type superClass = MyClass.GetBase() ;
// then, do something with superClass
然而,似乎没有合适的 GetBase
方法。
推荐答案
从当前类的类型使用反射。
Use Reflection from the Type of the current class.
Type superClass = myClass.GetType().BaseType;
这篇关于C#中:你如何获取类'基地班呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文