Answers for "how to get the calling method c#"

C#
2

c# get calling method name

//using System.Runtime.CompilerServices;
public void SendError(string Message, [CallerMemberName] string callerName = "") 
{ 
    Console.WriteLine(callerName + "called me."); 
} 
// You can also get the [CallerFilePath] and [CallerLineNumber].
Posted by: Guest on November-27-2020
2

c# call method

// Call method using 'static':
class ClassA
{
	static void Main(string[] args)
    {
    	ClassB.Method1();
    }
}

class ClassB
{
	public static void Method1()
    {
    	// do something...
    }
}

// Call method using an object:
class ClassC
{
	static void Main(string[] args)
    {
    	ClassD loadMethod = new ClassD();
      	loadMethod.Method1();
    }
}
  
class ClassD
{
	public void Method1()
    {
    	// do something...
    }
}
Posted by: Guest on July-23-2021

Code answers related to "how to get the calling method c#"

C# Answers by Framework

Browse Popular Code Answers by Language