StackTrace.GetFrames Method

Definition

Returns a copy of all stack frames in the current stack trace.

C#
public System.Diagnostics.StackFrame[] GetFrames();
C#
public virtual System.Diagnostics.StackFrame[] GetFrames();
C#
public virtual System.Diagnostics.StackFrame?[] GetFrames();
C#
[System.Runtime.InteropServices.ComVisible(false)]
public virtual System.Diagnostics.StackFrame[] GetFrames();

Returns

An array of type StackFrame representing the function calls in the stack trace.

Attributes

Examples

The following code example demonstrates enumerating the frames in a StackTrace.

C#
StackTrace st = new StackTrace(1, true);
StackFrame [] stFrames = st.GetFrames();

foreach(StackFrame sf in stFrames )
{
   Console.WriteLine("Method: {0}", sf.GetMethod() );
}

Remarks

Use the returned StackFrame array to enumerate and examine function calls in the StackTrace. The length of the returned array is equal to the FrameCount property value.

The StackFrame array elements are in reverse chronological order. The StackFrame at array index 0 represents the most recent function call in the stack trace and the last frame pushed onto the call stack. The StackFrame at array index FrameCount minus 1 represents the oldest function call in the stack trace and the first frame pushed onto the call stack.

Use the GetFrames method to obtain all stack frames in a stack trace; use the GetFrame method to obtain a specific stack frame in a stack trace. The StackFrame indexes are ordered alike by the two methods. For example, the StackFrame at index 0 in the array returned by GetFrames is equivalent to the StackFrame returned by GetFrame with an input index of 0.

Applies to

Tuote Versiot
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

See also