How to find the child class name from base class?

C#ReflectionInheritance

C# Problem Overview


At run-time, inside base class, how to find the current child class name ?

C# Solutions


Solution 1 - C#

Get the type of the current object, then its name.

this.GetType().Name

Solution 2 - C#

Try this:

Type type = this.GetType().UnderlyingSystemType;  
String className = type.Name;  

Solution 3 - C#

If you call this.GetType() you'll always get the current runtime type regardless of the base class you're inheriting from.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionXaqronView Question on Stackoverflow
Solution 1 - C#tvanfossonView Answer on Stackoverflow
Solution 2 - C#markgView Answer on Stackoverflow
Solution 3 - C#BFreeView Answer on Stackoverflow