How to get the name of current function?

Jack picture Jack · Apr 12, 2012 · Viewed 47.6k times · Source

Possible Duplicate:
Can you use reflection to find the name of the currently executing method?
C# how to get the name of the current method from code

For example:

void foo() {
    Console.Write(__MYNAME__);
}

print: foo

it's possible do it in C#?

Answer

Raphaël Althaus picture Raphaël Althaus · Apr 12, 2012

Try this:

System.Reflection.MethodBase.GetCurrentMethod().Name