---
title: "Getting current class name including parent class name"  
description: "Getting current class name including parent class name"  
author: "Jayden Bell"  
published: 2014-03-29  
updated: 2014-03-29  
canonical: https://www.mindstick.com/forum/1997/getting-current-class-name-including-parent-class-name  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Getting current class name including parent class name

If I have a [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) B and C which [inherits](https://www.mindstick.com/interview/85/what-is-a-subclass) from A, is there something simpler than using StackFrame's GetFileName() (then [parse](https://www.mindstick.com/forum/12870/how-to-parse-json-array-using-newtonsoft) out the ClassName.cs [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp))?

If I use this.GetType().Name, it won't return "A" when the [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) is executing in the [parent](https://www.mindstick.com/blog/154/how-to-find-parent-of-control-in-wpf) class.

## [Sample](https://www.mindstick.com/news/2174/mars-mission-by-nasa-prepares-for-tests) Code

```
namespace StackOverflow.Demos{    class Program    {        public static void Main(string[] args)        {            B myClass = new C();            string containingClassName = myClass.GetContainingClassName();           
Console.WriteLine(containingClassName); //should output
StackOverflow.Demos.B            Console.ReadKey();        }    } public class A {public A() { } } public class B : A
{ public B() { } } public class C : B
{ public C() { } }}
```

## Replies

### Reply by Pravesh Singh

Hi Jayden,

When you say GetType(), or equivalently this.GetType(), you get the actual type of the class. For example

```
class A{  public void Test()  {   
Console.WriteLine(GetType().Name);  }}class B : A{}
```

and later:

var myB = new B();

myB.Test(); // writes B to the console

I guess that's what polymorphism is all about.

If you want always A, no polymorphism, simply say:

```
class A{  public void Test()  {   
Console.WriteLine(typeof(A).Name);  }}class B : A{}
```


---

Original Source: https://www.mindstick.com/forum/1997/getting-current-class-name-including-parent-class-name

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
