A StackFrame is created and pushed on the call stack for every function call made during the execution of a thread. The stack frame always includes MethodBase information, and optionally includes file name, line number, and column number information.

Source: MSDN

1
2
3
System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame();
System.Reflection.MethodBase mb = sf.GetMethod();
Console.WriteLine(mb.Name);

This code can be used to get the name of the current class.

string ClassName = this.GetType().Name;

Note: This code can only be called inside a non-static method/function. This is because a static method cannot put into use the instance retriever – this keyword.

No votes yet.
Please wait...