Access method name in the method itself

M

Mukesh

Hi,

Could I write a code that will get the method name within which the
code is written.
like I want

void showMethodName(){
string method;
method=Need a method here to get the method name which contains this
code. In this case it is "showMethodName"
}

Thanks
Chakravarti Mukesh
 
G

Guest

methodname = new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name;

Ciaran O'Donnell
 
J

Jon Skeet [C# MVP]

Mukesh said:
Could I write a code that will get the method name within which the
code is written.
like I want

void showMethodName(){
string method;
method=Need a method here to get the method name which contains this
code. In this case it is "showMethodName"
}

Ciaran showed you a way, but it should be noted that this is quite
expensive, and should almost always be avoided.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top