List<T>.ICollection.IsSynchronized 属性


获取一个值,该值指示是否同步对 ICollection 的访问(线程安全)。Gets a value indicating whether access to the ICollection is synchronized (thread safe).

property bool System::Collections::ICollection::IsSynchronized { bool get(); };
bool System.Collections.ICollection.IsSynchronized { get; }
member this.System.Collections.ICollection.IsSynchronized : bool
 ReadOnly Property IsSynchronized As Boolean Implements ICollection.IsSynchronized


如果对 true 的访问是同步的(线程安全),则为 ICollection;否则为 falsetrue if access to the ICollection is synchronized (thread safe); otherwise, false. List<T> 的默认实现中,此属性始终返回 falseIn the default implementation of List<T>, this property always returns false.



System.Collections.Generic 命名空间中集合的默认实现是不同步的。Default implementations of collections in the System.Collections.Generic namespace are not synchronized.

枚举整个集合本质上不是一个线程安全的过程。Enumerating through a collection is intrinsically not a thread-safe procedure. 在具有写入访问的枚举竞争的罕见情况下,可以在整个枚举过程中锁定集合。In the rare case where enumeration contends with write accesses, you can lock the collection during the entire enumeration. 若要允许多个线程访问集合以进行读写操作,则必须实现自己的同步。To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.

SyncRoot 返回一个对象,该对象可用于同步对 ICollection的访问。SyncRoot returns an object that can be used to synchronize access to the ICollection. 仅当所有线程在访问集合之前锁定此对象时,同步才有效。Synchronization is effective only if all threads lock this object before accessing the collection.

检索此属性的值的运算复杂度为 O(1)。Retrieving the value of this property is an O(1) operation.