How does a static constructor work?

前端 未结 10 1325
迷失自我
迷失自我 2020-12-04 06:03
namespace MyNameSpace
{
    static class MyClass
    {
        static MyClass()
        {
            //Authentication process.. User needs to enter password
                


        
10条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-04 06:55

    The #3 is actually #1: static initialization does not start until the first use of the class to which it belongs.

    It is possible if MyMethod is called from the static constructor or a static initialization block. If you do not invoke MyMethod directly or indirectly from your static constructor, you should be fine.

提交回复
热议问题