dbnex14 dbnex14 - 1 year ago 173
C# Question

Get Current Class Name

In Android, if I need to get name of current class, i can do something like:

private final _TAG = DummyActivity.this.getClass().getSimpleName();

this would return "DummyActivity"

I want to do same in C# WPF app code-behind. How do I get the name of current class?

this.GetType().Name; //this works only on instances of a class

Looks like the only option is to hard-code it in C# like this:

private const string _TAG = "DummyWindow";

Answer Source

An instance would exactly be "current", the concept does not make much sense otherwise. If you just want the name of a known type that would be typeof(Class).Name.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download