博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
StackTrace
阅读量:6900 次
发布时间:2019-06-27

本文共 786 字,大约阅读时间需要 2 分钟。

 我们在学习函数调用时,都知道每个函数都拥有自己的栈空间。一个函数被调用时,就创建一个新的栈空间。那么通过函数的嵌套调用最后就形成了一个函数调用堆栈。在c#中,使用StackTrace记录这个堆栈。你可以在程序运行过程中使用StackTrace得到当前堆栈的信息。

class
 Program
    
{
        
static void Main(string[] args)
        
{
            Program a 
= new Program();
            a.FuncA();
            Console.ReadLine();
        }
        
int FuncA()
        
{
            FuncB();
            
return 0;
        }
        
private void FuncB()
        
{
            MethodInfo method0 
= (MethodInfo)(new StackTrace().GetFrame(0).GetMethod());
            MethodInfo method1 
= (MethodInfo)(new StackTrace().GetFrame(1).GetMethod());
            MethodInfo method2 
= (MethodInfo)(new StackTrace().GetFrame(2).GetMethod());
            
            Console.WriteLine(
"Current Method is : {0}",method0.Name);
            Console.WriteLine(
"Parent Method is : {0}", method1.Name);
            Console.WriteLine(
"GrandParent Method is : {0}", method2.Name);
        }
    }

转载于:https://www.cnblogs.com/yongtaiyu/archive/2013/02/06/2904043.html

你可能感兴趣的文章
日志分析工具ELK(二)
查看>>
js中eval详解
查看>>
软件设计
查看>>
HDU 5753 Permutation Bo
查看>>
【问题集】VS新建项目——失败——弹出“未将对象引用设置到对象的实例”...
查看>>
blog.yiz96.com
查看>>
centos 创建桌面双击启动程序(更改图标)
查看>>
jq 的grep(); 数组筛选方法
查看>>
[BZOJ] 1059: [ZJOI2007]矩阵游戏
查看>>
HTTP状态码
查看>>
DataGridView key points
查看>>
STL中map与hash_map容器的选择
查看>>
PagedGeometry 笔记02
查看>>
游戏launch界面
查看>>
web前端免费资源集
查看>>
sql 分组后查询出排序字段
查看>>
函数调用机制
查看>>
BZOJ 2001 线段树+LCT (TLE)
查看>>
POJ 2229 DP
查看>>
SVN简介
查看>>