C# : how do you obtain a class' base class?

2019-03-14 06:56发布

In C#, how does one obtain a reference to the base class of a given class?

For example, suppose you have a certain class, MyClass, and you want to obtain a reference to MyClass' superclass.

I have in mind something like this:

Type  superClass = MyClass.GetBase() ;
// then, do something with superClass

However, it appears there is no suitable GetBase method.

标签: c# superclass
7条回答
甜甜的少女心
2楼-- · 2019-03-14 07:43

obj.base will get you a reference to the parent object from an instance of the derived object obj.

typeof(obj).BaseType will get you a reference to the parent object's type from an instance of the derived object obj.

查看更多
登录 后发表回答