Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# System.Diagnostics.StackTrace或System.Diagnostics.StackFrame是否用于调试?为什么?_C#_Debugging_Logging_Error Handling - Fatal编程技术网

C# System.Diagnostics.StackTrace或System.Diagnostics.StackFrame是否用于调试?为什么?

C# System.Diagnostics.StackTrace或System.Diagnostics.StackFrame是否用于调试?为什么?,c#,debugging,logging,error-handling,C#,Debugging,Logging,Error Handling,这个代码是: System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame(); System.Reflection.MethodBase methodBase = stackFrame.GetMethod(); stackFrame.GetFileName(); stackFrame.GetFileLineNumber(); 与使用System.Diagnostics.StackTrace进行调试相比

这个代码是:

System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame();
System.Reflection.MethodBase methodBase = stackFrame.GetMethod();
stackFrame.GetFileName();
stackFrame.GetFileLineNumber();

与使用System.Diagnostics.StackTrace进行调试相比,StackTrace更好地在内部使用StackFrame,默认构造函数将为您解决这一问题,并设置列号

我会坚持使用StackTrace,除非您需要有限数量的帧或减少堆栈跟踪(可能是出于性能原因)