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

来源:岁月联盟 编辑:zhu 时间:2005-05-12
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();
  }
 }
}