zoukankan      html  css  js  c++  java
  • EffectiveC#11--选择foreach循环

    1.C#的foreach语句可以为你的任何集合产生最好的迭代代码

       不推荐如下写法(?原因未明白 作者意思是阻碍jit边界检测)

    int len = foo.Length;
     for ( int index = 0; index < len; index++ ) 
    Console.WriteLine( foo[index].ToString( ));

    2. 二维数组循环翻译人建议还是如下写法,而不是使用foreach写

    private Square[,] _theBoard = new Square[ 8, 8 ]; 
    for ( int i = 0; i < _theBoard.GetLength( 0 ); i++ )
     for( int j = 0; j < _theBoard.GetLength( 1 ); j++ ) 
           _theBoard[ i, j ].PaintSquare( );
    

      作者建议foreach

    foreach( Square sq in _theBoard ) 
        sq.PaintSquare( );
    

    3.注意数组与集合的区别。数组是一次性分配的连续内存,集合是可以动态添加与修改的,一般用链表来实现。

    4.

  • 相关阅读:
    Core Java 5
    pyDay11
    c++第二十一天
    pyDay10
    c++第二十天
    RadioButton控件
    ListBox控件
    Image控件
    FileUpload控件
    DropDownList控件
  • 原文地址:https://www.cnblogs.com/tiantianle/p/4883907.html
Copyright © 2011-2022 走看看