0

I don't understand why I have the output S3112#

using System;
using static B;


public class A { public A() { Console.Write("1"); } }
public class B : A
{
    public class C : A { static C() { Console.Write("3");} }
    public B() : base() { Console.Write("2");  }
    private C c = new C();
}

public class Z
{
    static Z() { Console.Write("S"); }
    public static void Main()
    {
        B b = new B();
        Console.WriteLine("#");
    }
}

As far as I understand the private C c = new C(); line is invoked before base() constructor in the B class but I don't understand why?

  • Also https://stackoverflow.com/questions/3681055/is-the-order-of-static-class-initialization-in-c-sharp-deterministic for static constructors – Charlieface Jun 27 '23 at 00:44

0 Answers0