1. <tfoot id='NFidQ'></tfoot>

        • <bdo id='NFidQ'></bdo><ul id='NFidQ'></ul>
        <i id='NFidQ'><tr id='NFidQ'><dt id='NFidQ'><q id='NFidQ'><span id='NFidQ'><b id='NFidQ'><form id='NFidQ'><ins id='NFidQ'></ins><ul id='NFidQ'></ul><sub id='NFidQ'></sub></form><legend id='NFidQ'></legend><bdo id='NFidQ'><pre id='NFidQ'><center id='NFidQ'></center></pre></bdo></b><th id='NFidQ'></th></span></q></dt></tr></i><div id='NFidQ'><tfoot id='NFidQ'></tfoot><dl id='NFidQ'><fieldset id='NFidQ'></fieldset></dl></div>
        <legend id='NFidQ'><style id='NFidQ'><dir id='NFidQ'><q id='NFidQ'></q></dir></style></legend>

        <small id='NFidQ'></small><noframes id='NFidQ'>

      1. 在 C# 中内联或在静态构造函数中初始化静态变量的区别

        时间:2023-11-10

          <bdo id='7n5s5'></bdo><ul id='7n5s5'></ul>

              <tbody id='7n5s5'></tbody>
            <tfoot id='7n5s5'></tfoot>
            • <small id='7n5s5'></small><noframes id='7n5s5'>

                <legend id='7n5s5'><style id='7n5s5'><dir id='7n5s5'><q id='7n5s5'></q></dir></style></legend>
                  <i id='7n5s5'><tr id='7n5s5'><dt id='7n5s5'><q id='7n5s5'><span id='7n5s5'><b id='7n5s5'><form id='7n5s5'><ins id='7n5s5'></ins><ul id='7n5s5'></ul><sub id='7n5s5'></sub></form><legend id='7n5s5'></legend><bdo id='7n5s5'><pre id='7n5s5'><center id='7n5s5'></center></pre></bdo></b><th id='7n5s5'></th></span></q></dt></tr></i><div id='7n5s5'><tfoot id='7n5s5'></tfoot><dl id='7n5s5'><fieldset id='7n5s5'></fieldset></dl></div>
                • 本文介绍了在 C# 中内联或在静态构造函数中初始化静态变量的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

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

                  I would like to know what is the difference between initializing a static member inline as in:

                  class Foo
                  {
                      private static Bar bar_ = new Bar();
                  }
                  

                  或在静态构造函数中对其进行初始化,如下所示:

                  or initializing it inside the static constructor as in:

                  class Foo
                  {
                      static Foo()
                      {
                          bar_ = new Bar();
                      }
                      private static Bar bar_;
                  }
                  

                  推荐答案

                  如果你的类型中有一个静态构造函数,它会因为 beforefieldinit 标志不再被应用.

                  If you have a static constructor in your type, it alters type initialization due to the beforefieldinit flag no longer being applied.

                  它也会影响初始化顺序 - 变量初始化器都在静态构造函数之前执行.

                  It also affects initialization order - variable initializers are all executed before the static constructor.

                  据我所知就是这样.

                  这篇关于在 C# 中内联或在静态构造函数中初始化静态变量的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将字节数组初始化为某个值,而不是默认的null? 下一篇:C# 语法通过数组中的构造函数参数初始化自定义类/对象?

                  相关文章

                  <legend id='jd1gb'><style id='jd1gb'><dir id='jd1gb'><q id='jd1gb'></q></dir></style></legend>
                  <i id='jd1gb'><tr id='jd1gb'><dt id='jd1gb'><q id='jd1gb'><span id='jd1gb'><b id='jd1gb'><form id='jd1gb'><ins id='jd1gb'></ins><ul id='jd1gb'></ul><sub id='jd1gb'></sub></form><legend id='jd1gb'></legend><bdo id='jd1gb'><pre id='jd1gb'><center id='jd1gb'></center></pre></bdo></b><th id='jd1gb'></th></span></q></dt></tr></i><div id='jd1gb'><tfoot id='jd1gb'></tfoot><dl id='jd1gb'><fieldset id='jd1gb'></fieldset></dl></div>

                      <small id='jd1gb'></small><noframes id='jd1gb'>

                    1. <tfoot id='jd1gb'></tfoot>
                      • <bdo id='jd1gb'></bdo><ul id='jd1gb'></ul>