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# 中内联或在静态构造函数中初始化静态变量的区别

        Difference initializing static variable inline or in static constructor in C#(在 C# 中内联或在静态构造函数中初始化静态变量的区别)

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

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                  Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                  How to store delegates in a List(如何将代表存储在列表中)
                  How delegates work (in the background)?(代表如何工作(在后台)?)
                  C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                  Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                  <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>

                            <tbody id='jd1gb'></tbody>

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

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