Access method name in the method itself

  • Thread starter Thread starter Mukesh
  • Start date Start date
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
 
methodname = new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name;

Ciaran O'Donnell
 
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.
 
Back
Top