I try to understand, why there is different behavior.
Code 1 different from Code 2 just with comment line Console.WriteLine(h.ToString());.
But in this case Console.Beep(); in Code 1 executes before static void Main(string[] args) finished.
In Code 2 Console.Beep(); executes only when static void Main(string[] args) finished (process terminated?).
Can you please explain me, why is it so?
I tried to call codes with [+/-] Optimization setting- looks like it doesn't depend on it.
Right now i dont have WinDbg,- mb the answer in decompiled code.
Code 1:
class Program
{
    static void Main(string[] args) {
        var h = new Haha();
        // Console.WriteLine(h.ToString());
        GC.Collect();
        GC.WaitForPendingFinalizers();
        /* Console.Beep() calls here */
        Console.ReadKey();
    }
}
public class Haha
{
    ~Haha() {
        Console.Beep();
    }
}
Code 2:
class Program
{
    static void Main(string[] args) {
        var h = new Haha();
        Console.WriteLine(h.ToString());
        GC.Collect();
        GC.WaitForPendingFinalizers();
        Console.ReadKey();
        /* Console.Beep() calls here */
    }
}
public class Haha
{
    ~Haha() {
        Console.Beep();
    }
}
 
     
    