c# 调试程序时常常需要借助 call stack 查看调用堆栈,实际上通过code也可以获取:
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 < stacktrace.FrameCount; i++) { var method = stacktrace.GetFrame(i).GetMethod(); Console.WriteLine(method.Name); } return num1 + num2; } }
结果:
原文地址:https://www.cnblogs.com/chenyingzuo/p/12003646.html
时间: 2024-10-20 05:29:10