What is the difference between ArrayList
and List<>
in C#?
Is it only that List<>
has a type while ArrayLis
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