(论坛答疑点滴)如何得知调用当前方法的方法名?

using System;
using System.Diagnostics;

namespace StackTraceTest
{
 
/// <summary>
 
/// Class1 的摘要说明。
 
/// </summary>

 class Class1
 
{
  
/// <summary>
  
/// 应用程序的主入口点。
  
/// </summary>

  [STAThread]
  
static void Main(string[] args)
  
{
   method2();
   
//输出method2
  }

  
  
static private void method1()
  
{
   StackTrace st
=new StackTrace(true);
   Console.WriteLine(st.GetFrame(
1).GetMethod().Name.ToString());   
  }


  
static private void method2()
  
{
         method1(); 
   Console.ReadLine();
  }

 }

}


原文地址:https://www.cnblogs.com/lovecherry/p/135175.html