Which is better? array, ArrayList or List (in terms of performance and speed)

前端 未结 3 1400
南笙
南笙 2020-12-31 00:32

I require a fast speed in processing my page. The count of the values to be added will be dynamic.

Which one of the above is preferred? Support with a valid reason.<

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-31 01:10

    List should generally be preferred over ArrayList

    • faster for value types as it avoids boxing.
    • strongly typed elements

    If you want lists you expose to callers to be immutable, this is supported by both List and ArrayList:

    List.AsReadOnly()
    ArrayList.ReadOnly(ArrayList list);
    

    Your question asks about choosing between ArrayList and List, but your example shows an array, which is neither.

提交回复
热议问题