c# 如何获取当前方法的调用堆栈
2021-01-26 00:13
标签:ack result bsp http 图片 trace test line main c# 调试程序时常常需要借助 call stack 查看调用堆栈,实际上通过code也可以获取: 结果: c# 如何获取当前方法的调用堆栈 标签:ack result bsp http 图片 trace test line main 原文地址:https://www.cnblogs.com/chenyingzuo/p/12003646.html class Program
{
static void Main(string[] args)
{
Test();
}
private static void Test()
{
var result = Sum(1, 2);
}
private static int Sum(int num1, int num2)
{
var stacktrace = new StackTrace();
for (var i = 0; i )
{
var method = stacktrace.GetFrame(i).GetMethod();
Console.WriteLine(method.Name);
}
return num1 + num2;
}
}