• Dictionary is not like a array


    As the title, everybody knows that, a dictionary is not a array, and not a arraylist, neither two array or two arraylist.

    Then there is a problem:

    I use this to iterate the array(arr_tmp):

    for(int i = 0; i < arr.length; i++){
        sum += arr[i];
    }

    I use this to iterate the arraylist(arrlst_tmp):

    for(int i = 0; i < arrlst_tmp.count; i++){
        sum += arrlst_tmp[i];
    }

    and I use the same thing to iterate the dictionary(dic_tmp):

    for(int i = 0; i < dic_tmp.count; i++){
        sum += dic_tmp.ElementAt(i).Value;
    }

    But one day I read some thing from another one, it tells about the run time and the efficiency of the iterate takes, then he recommended this:

    foreach (KeyValuePair<int, int> pair in dic_tmp)
    {
        sum += pair.Value;
    }

    TKS that you tell me I'm foolish, and it will take time and will take long time for me to be a programmer.

  • 相关阅读:
    图象处理算法(一)
    使用自定义类实现工程多语言
    SQL的数据类型
    SQL LEFT JOIN
    TADOCommand
    如何获得活动的数据
    TDateTime
    类定义(一)
    mxOutlookBar组件安装和使用
    TADOQuery
  • 原文地址:https://www.cnblogs.com/henyihanwobushi/p/3098530.html
Copyright © 2020-2023  润新知