Why doesn't the CLR always call value type constructors

前端 未结 7 844
情深已故
情深已故 2020-12-13 08:52

I have a question concerning type constructors within a Value type. This question was inspired by something that Jeffrey Richter wrote in CLR via C# 3rd ed,

相关标签:
7条回答
  • 2020-12-13 09:51

    Another interesting sample:

       struct S
        {
            public int x;
            static S()
            {
                Console.WriteLine("static S()");
            }
            public void f() { }
        }
    
        static void Main() { new S().f(); }
    
    0 讨论(0)
提交回复
热议问题