Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

superclass

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.

like image 707
JaysonFix Avatar asked Jul 09 '09 17:07

JaysonFix


People also ask

What do you mean by C?

C is a structured, procedural programming language that has been widely used both for operating systems and applications and that has had a wide following in the academic community. Many versions of UNIX-based operating systems are written in C.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

Why is C programming language important?

Being a middle-level language, C reduces the gap between the low-level and high-level languages. It can be used for writing operating systems as well as doing application level programming. Helps to understand the fundamentals of Computer Theories.

Why is C called a mid level programming language?

C has the features of both assembly level languages i.e low-level languages and higher level languages. So that's why C is generally called as a middle-level Language. The user uses C language for writing an operating system and generates menu driven customer billing system.


1 Answers

Use Reflection from the Type of the current class.

 Type superClass = myClass.GetType().BaseType; 
like image 102
JoshJordan Avatar answered Oct 13 '22 07:10

JoshJordan