Csharp/CSharp Tutorial/Development/StackTrace

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Stack frames

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.rupilerServices;
using System.Security.Principal;
public class MainClass
{
    internal static void A()
    {
        B(10, 50);
    }
    internal static void B(int x, int y)
    {
        C("Hello", x * y);
    }
    internal static void C(string label, int num)
    {
        StackTrace trace = new StackTrace();
        Console.WriteLine(trace.ToString());
    }
    public static void Main()
    {
        A();
    }
}

StackTrace and StackFrame

using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
public sealed class MainClass
{
    static void Main()
    {
        StackTrace creationStackTrace = new StackTrace(1, true);
        for( int i = 0;i < creationStackTrace.FrameCount; ++i ) {
             StackFrame frame =  creationStackTrace.GetFrame(i);
             Console.WriteLine( "   {0}", frame.ToString() );
        }    
    }
}
US format: (1.12346 1.12346)
DE format: (1,12346 1,12346)
Object.ToString(): (1.12345678 1.12345678)