ArrayList vs List<> in C#

后端 未结 12 2133
深忆病人
深忆病人 2020-11-22 04:10

What is the difference between ArrayList and List<> in C#?

Is it only that List<> has a type while ArrayLis

12条回答
  •  余生分开走
    2020-11-22 05:14

    Another difference to add is with respect to Thread Synchronization.

    ArrayList provides some thread-safety through the Synchronized property, which returns a thread-safe wrapper around the collection. The wrapper works by locking the entire collection on every add or remove operation. Therefore, each thread that is attempting to access the collection must wait for its turn to take the one lock. This is not scalable and can cause significant performance degradation for large collections.

    List does not provide any thread synchronization; user code must provide all synchronization when items are added or removed on multiple threads concurrently.

    More info here Thread Synchronization in the .Net Framework

提交回复
热议问题