CopyOnWriteArrayList version in C#


Java has CopyOnWriteArrayList, but C# does not have it. For that, the SynchronizedCollection Class in C#, should be preferred.

The SyncronizedCollection has a thread-safe collection containing objects of a type. Here is the syntax.

public class SynchronizedCollection<T> : IList<T>, ICollection<T>,
IEnumerable<T>, IEnumerable, IList, ICollection

Above, T is the type of object.

The following are the properties of the SyncronizedCollection class in C# −

Sr.No.Property Name & Description
1Count
Counts the number of elements in the thread-safe collection.
2Item[Int32]
Gets an element from the thread-safe collection with a specified index.
3Items
Gets the list of elements contained in the thread-safe collection.
4SyncRoot
Gets the object used to synchronize access to the thread-safe collection.

Updated on: 22-Jun-2020

121 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements