• <small id='ZYtDF'></small><noframes id='ZYtDF'>

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

    <tfoot id='ZYtDF'></tfoot>

    <legend id='ZYtDF'><style id='ZYtDF'><dir id='ZYtDF'><q id='ZYtDF'></q></dir></style></legend>
      <bdo id='ZYtDF'></bdo><ul id='ZYtDF'></ul>

        在循环中执行 array.length 或 list.count 成本高吗

        Is it costly to do array.length or list.count in a loop(在循环中执行 array.length 或 list.count 成本高吗)
          <bdo id='swWTc'></bdo><ul id='swWTc'></ul>

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

                  <tfoot id='swWTc'></tfoot>

                  <i id='swWTc'><tr id='swWTc'><dt id='swWTc'><q id='swWTc'><span id='swWTc'><b id='swWTc'><form id='swWTc'><ins id='swWTc'></ins><ul id='swWTc'></ul><sub id='swWTc'></sub></form><legend id='swWTc'></legend><bdo id='swWTc'><pre id='swWTc'><center id='swWTc'></center></pre></bdo></b><th id='swWTc'></th></span></q></dt></tr></i><div id='swWTc'><tfoot id='swWTc'></tfoot><dl id='swWTc'><fieldset id='swWTc'></fieldset></dl></div>
                    <tbody id='swWTc'></tbody>
                1. <legend id='swWTc'><style id='swWTc'><dir id='swWTc'><q id='swWTc'></q></dir></style></legend>
                2. 本文介绍了在循环中执行 array.length 或 list.count 成本高吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我知道在 JavaScript 中,创建这样的 for 循环:for(int i = 0; i < arr.length; i++) 成本很高,因为它每次都会计算数组长度.对于列表和数组,这种行为在 c# 中是否也很昂贵.还是在编译时进行了优化?还有Java等其他语言呢,这是怎么处理的?

                  I know that in JavaScript, creating a for loop like this: for(int i = 0; i < arr.length; i++) is costly as it computes the array length each time. Is this behavior costly in c# for lists and arrays as well. Or at compile-time is it optimized? Also what about other languages such as Java, how is this handled?

                  推荐答案

                  在 C# 中成本很高.一方面,没有计算":由于内联,查询长度基本上是一个基本操作.其次,因为(根据其开发人员的说法),编译器会识别这种访问模式,实际上会优化任何(冗余)边界检查以访问数组元素.

                  It is not costly in C#. For one thing, there is no "calculation": querying the length is basically an elementary operation thanks to inlining. And secondly, because (according to its developers), the compiler recognizes this pattern of access and will in fact optimize any (redundant) boundary checks for access on array elements.

                  顺便说一句,我相信现代 JavaScript 虚拟机也有类似的情况,如果现在还没有,那么很快就会出现,因为这是一个微不足道的优化.

                  And by the way, I believe that something similar is true for modern JavaScript virtual machines, and if it isn't already, it will be very soon since this is a trivial optimization.

                  这篇关于在循环中执行 array.length 或 list.count 成本高吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)
                    <bdo id='re5Fc'></bdo><ul id='re5Fc'></ul>
                    <legend id='re5Fc'><style id='re5Fc'><dir id='re5Fc'><q id='re5Fc'></q></dir></style></legend>

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

                      <tbody id='re5Fc'></tbody>

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

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