07 Aug, 2007 · 1 minute read
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
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 – thiskeyword.