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

前端 未结 3 2032
我在风中等你
我在风中等你 2020-12-31 00:46

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:20

    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.

提交回复
热议问题