相关疑难解决方法(0)

在C#中初始化静态变量内联或静态构造函数的差异

我想知道初始化内联静态成员有什么区别,如:

class Foo
{
    private static Bar bar_ = new Bar();
}
Run Code Online (Sandbox Code Playgroud)

或者在静态构造函数中初始化它,如:

class Foo
{
    static Foo()
    {
        bar_ = new Bar();
    }
    private static Bar bar_;
}
Run Code Online (Sandbox Code Playgroud)

.net c# static constructor initialization

18
推荐指数
1
解决办法
1万
查看次数

标签 统计

.net ×1

c# ×1

constructor ×1

initialization ×1

static ×1