首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >静态构造函数是如何工作的?

静态构造函数是如何工作的?
EN

Stack Overflow用户
提问于 2012-02-23 00:10:17
回答 10查看 10.5K关注 0票数 82
代码语言:javascript
运行
复制
namespace MyNameSpace
{
    static class MyClass
    {
        static MyClass()
        {
            //Authentication process.. User needs to enter password
        }

        public static void MyMethod()
        {
            //Depends on successful completion of constructor
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            MyClass.MyMethod();
        }
    }
}

下面是我假设的序列

static constructor

  • End of static constructor

  • Start of
  1. Start of MyMethod
  2. End of main

现在,在任何情况下,如果4在2之前开始,我就完蛋了。有可能吗?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9398509

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档