public static int Insert(int i)
    {   
        //在这里得到这个方法的名称为 Insert
    }谢谢

解决方案 »

  1.   


    Class1   myClass   =   new   Class1();   
      try     
      {   
              myClass.MyMethod();   
      }   
      catch   (Exception)     
      {   
               //   Display   file   and   line   information,   if   available.   
              StackTrace   st   =   new   StackTrace(new   StackFrame(true));   
              Console.WriteLine("   StackTrace:   "   +   st.ToString());   
              Console.WriteLine("   Line   Number   :   "   +   
                              st.GetFrame(0).GetFileLineNumber().ToString());   
              Console.WriteLine("-------------------------------------------------\n");   
      }   试试~~
      

  2.   

    Environment.StackTrace 可以取到当前运行层次
    里面有函数名
      

  3.   

    可以用foreach循环
    不知道到,看下面有没有人解决
      

  4.   

    Type   t   =   typeof(YourTypeName);   
      foreach(MethodInfo   m   in   t.GetMethods())   
      {   
        Console.WriteLine(m.Name);   
      }
      

  5.   

    另外一个宏   __FUNCTION__   是未转换的函数名,__FUNCDNAME__   是转换后的函数名,例如下面程序   
        
      #include   <iostream>   
      using   namespace   std;   
        
      void   func()   
      {   
      cout   <<   __FUNCDNAME__   <<   endl;   
      cout   <<   __FUNCTION__     <<   endl;   
      }   
        
      void   main()   
      {   
      func();   
      } 这个是c++里面的,c#的还不知道
      

  6.   

    获取Environment.StackTrace属性来分析一下吧,应该可以的
      

  7.   

    得到的是这些:
       在 System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
       在 System.Environment.get_StackTrace()
       在 _Default.Page_Load(Object sender, EventArgs e) 位置 e:\公司项目\胜道商城预定网\admin\Default.aspx.cs:行号 12
       在 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
       在 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       在 System.Web.UI.Control.OnLoad(EventArgs e)
       在 System.Web.UI.Control.LoadRecursive()
       在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       在 System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       在 System.Web.UI.Page.ProcessRequest()
       在 System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
       在 System.Web.UI.Page.ProcessRequest(HttpContext context)
       在 ASP.default_aspx.ProcessRequest(HttpContext context) 位置 c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\908c3fe2\81b8b544\App_Web_48jb0v48.2.cs:行号 0
       在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       在 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
       在 System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(Exception error)
       在 System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
       在 System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)
       在 System.Web.HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr)
       在 System.Web.Hosting.ISAPIRuntime.ProcessRequest(IntPtr ecb, Int32 iWRType)这样怎么能`绝对正确的得得他的方法名呢?
      

  8.   

    using System.Diagnostics;static void A()
            {
                StackTrace st = new StackTrace();
                Console.WriteLine(st.GetFrame(0).GetMethod().Name);
            }
            static void B()
            {
                StackTrace st = new StackTrace();
                Console.WriteLine(st.GetFrame(0).GetMethod().Name);
            }        static void Main(string[] args)
            {            A();
                B();
            }
      

  9.   

    最简单的方法:            MethodBase mb = MethodBase.GetCurrentMethod();
                Console.WriteLine(mb.Name);
      

  10.   

    StackTrace stackTrace = new StackTrace(); 
        StackFrame stackFrame = stackTrace.GetFrame(1); 
        MethodBase methodBase = stackFrame.GetMethod();     Console.WriteLine( " Method Name {0} ", methodBase.Name );