How to get the name of the calling method in C# and VB.NET

To get the name of the calling method in C# and VB.NET you can use the snippet below.

Sample C#

public static string GetCallingMethodName()
{
	var stackTrace = new StackTrace();
	return stackTrace.GetFrame(1).GetMethod().Name;
}

Sample VB.NET

Public Shared Function GetCallingMethodName() As String
	Dim stackTrace = New StackTrace()
	Return stackTrace.GetFrame(1).GetMethod().Name
End Function

Please Share us:
Please rate this snippet

3 thoughts on “How to get the name of the calling method in C# and VB.NET

Leave a Reply