SynchronizedReadOnlyCollection<T> SynchronizedReadOnlyCollection<T> SynchronizedReadOnlyCollection<T> SynchronizedReadOnlyCollection<T> Class

定义

提供一个线程安全的只读集合,该集合包含泛型参数指定为元素的类型的对象。Provides a thread-safe, read-only collection that contains objects of a type specified by the generic parameter as elements.

generic <typename T>
public ref class SynchronizedReadOnlyCollection : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::IList<T>, System::Collections::IList
[System.Runtime.InteropServices.ComVisible(false)]
public class SynchronizedReadOnlyCollection<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IList<T>, System.Collections.IList
type SynchronizedReadOnlyCollection<'T> = class
    interface IList<'T>
    interface ICollection<'T>
    interface seq<'T>
    interface IList
    interface ICollection
    interface IEnumerable
Public Class SynchronizedReadOnlyCollection(Of T)
Implements ICollection(Of T), IEnumerable(Of T), IList, IList(Of T)

类型参数

T

包含在线程安全只读集合中作为项的对象的类型。The type of object contained as items in the thread-safe, read-only collection.

继承
SynchronizedReadOnlyCollection<T>SynchronizedReadOnlyCollection<T>SynchronizedReadOnlyCollection<T>SynchronizedReadOnlyCollection<T>
属性
实现

注解

SynchronizedReadOnlyCollection<T> 将数据存储在 IList<T> 容器中,它提供一个对象,该对象可进行设置,可用于同步对集合的访问,以使其成为线程安全集合。The SynchronizedReadOnlyCollection<T> stores data in an IList<T> container and provides an object that can be set and used to synchronize access to the collection so that it is thread safe. 使用 IList<T> 属性可以恢复 Items 容器。The IList<T> container can be recovered using the Items property. 使用 ICollection.SyncRoot 属性可以恢复同步对象。The synchronized object can be recovered using the ICollection.SyncRoot property. 只能通过采用 syncRoot 参数的构造函数之一对其进行设置。It can only be set using one of the constructors that take the syncRoot parameter.

构造函数

SynchronizedReadOnlyCollection<T>() SynchronizedReadOnlyCollection<T>() SynchronizedReadOnlyCollection<T>() SynchronizedReadOnlyCollection<T>()

初始化 SynchronizedReadOnlyCollection<T> 类的新实例。Initializes a new instance of the SynchronizedReadOnlyCollection<T> class.

SynchronizedReadOnlyCollection<T>(Object) SynchronizedReadOnlyCollection<T>(Object) SynchronizedReadOnlyCollection<T>(Object) SynchronizedReadOnlyCollection<T>(Object)

使用对线程安全只读集合的访问进行同步的对象,初始化 SynchronizedReadOnlyCollection<T> 类的新实例。Initializes a new instance of the SynchronizedReadOnlyCollection<T> class with the object used to synchronize access to the thread-safe, read-only collection.

SynchronizedReadOnlyCollection<T>(Object, IEnumerable<T>) SynchronizedReadOnlyCollection<T>(Object, IEnumerable<T>) SynchronizedReadOnlyCollection<T>(Object, IEnumerable<T>) SynchronizedReadOnlyCollection<T>(Object, IEnumerable<T>)

使用指定的可枚举元素列表和用于对线程安全的只读集合的访问进行同步的对象来初始化 SynchronizedReadOnlyCollection<T> 类的新实例。Initializes a new instance of the SynchronizedReadOnlyCollection<T> class from a specified enumerable list of elements and with the object used to synchronize access to the thread-safe, read-only collection.

SynchronizedReadOnlyCollection<T>(Object, List<T>, Boolean) SynchronizedReadOnlyCollection<T>(Object, List<T>, Boolean) SynchronizedReadOnlyCollection<T>(Object, List<T>, Boolean) SynchronizedReadOnlyCollection<T>(Object, List<T>, Boolean)
SynchronizedReadOnlyCollection<T>(Object, T[]) SynchronizedReadOnlyCollection<T>(Object, T[]) SynchronizedReadOnlyCollection<T>(Object, T[]) SynchronizedReadOnlyCollection<T>(Object, T[])

使用指定的元素数组和用于对线程安全只读集合的访问进行同步的对象,初始化 SynchronizedReadOnlyCollection<T> 类的新实例。Initializes a new instance of the SynchronizedReadOnlyCollection<T> class from a specified array of elements and with the object used to synchronize access to the thread-safe, read-only collection.

属性

Count Count Count Count

获取线程安全只读集合中所含元素的数目。Gets the number of elements contained in the thread-safe, read-only collection.

Items Items Items Items

获取线程安全的只读集合中所含元素的列表。Gets the list of elements contained in the thread-safe, read-only collection.

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

获取线程安全的只读集合中具有指定索引的元素。Gets an element from the thread-safe, read-only collection with a specified index.

方法

Contains(T) Contains(T) Contains(T) Contains(T)

确定集合是否包含具有特定值的元素。Determines whether the collection contains an element with a specific value.

CopyTo(T[], Int32) CopyTo(T[], Int32) CopyTo(T[], Int32) CopyTo(T[], Int32)

从特定索引处开始,将集合中的元素复制到指定的数组。Copies the elements of the collection to a specified array, starting at a particular index.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

返回循环访问同步的只读集合的枚举器。Returns an enumerator that iterates through the synchronized, read-only collection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
IndexOf(T) IndexOf(T) IndexOf(T) IndexOf(T)

返回某个值在集合中的第一个匹配项的索引。Returns the index of the first occurrence of a value in the collection.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

显式界面实现

ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32)

从特定索引处开始,将集合中的元素复制到指定的数组。Copies the elements of the collection to a specified array, starting at a particular index.

ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

此属性总是返回 true,这是因为集合是线程安全集合。This property always returns true because the collection is thread safe.

ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

获取用于对线程安全只读集合的访问进行同步的对象。Gets the object used to synchronize access to the thread-safe, read-only collection.

ICollection<T>.Add(T) ICollection<T>.Add(T) ICollection<T>.Add(T) ICollection<T>.Add(T)

如果调用,会引发 NotSupportedExceptionThrows a NotSupportedException if called.

ICollection<T>.Clear() ICollection<T>.Clear() ICollection<T>.Clear() ICollection<T>.Clear()

如果调用,会引发 NotSupportedExceptionThrows a NotSupportedException if called.

ICollection<T>.IsReadOnly ICollection<T>.IsReadOnly ICollection<T>.IsReadOnly ICollection<T>.IsReadOnly

此属性总是返回 true,这是因为集合是只读的。This property always returns true because the collection is read-only.

ICollection<T>.Remove(T) ICollection<T>.Remove(T) ICollection<T>.Remove(T) ICollection<T>.Remove(T)

在所有情况下均引发 NotSupportedExceptionThrows a NotSupportedException in all cases.

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

返回循环访问同步的只读集合的枚举器。Returns an enumerator that iterates through the synchronized, read-only collection.

IList.Add(Object) IList.Add(Object) IList.Add(Object) IList.Add(Object)

将一个元素添加到集合中。Adds an element to the collection.

IList.Clear() IList.Clear() IList.Clear() IList.Clear()

不能清除只读集合中的项。Items cannot be cleared from a read-only collection.

IList.Contains(Object) IList.Contains(Object) IList.Contains(Object) IList.Contains(Object)

检查集合中是否存在指定的对象。Checks whether the specified object exists in the collection.

IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object)

获取指定项的索引。Gets the index of the specified item.

IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object)

不能向只读集合插入项。Items cannot be inserted into a read-only collection.

IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize

此属性返回 true,这是因为只读集合的大小始终是固定的。This property returns true because the read-only collection is always fixed in size.

IList.IsReadOnly IList.IsReadOnly IList.IsReadOnly IList.IsReadOnly

此属性总是返回 true,这是因为集合是只读的。This property always returns true because the collection is read-only.

IList.Item[Int32] IList.Item[Int32] IList.Item[Int32] IList.Item[Int32]

获取位于从零开始的指定索引处的项。Gets the item at a specified zero-based index.

IList.Remove(Object) IList.Remove(Object) IList.Remove(Object) IList.Remove(Object)

从集合中检索指定的元素。Retrieves the specified element from the collection.

IList.RemoveAt(Int32) IList.RemoveAt(Int32) IList.RemoveAt(Int32) IList.RemoveAt(Int32)

不能移除只读集合中的项。Items cannot be removed from a read-only collection.

IList<T>.Insert(Int32, T) IList<T>.Insert(Int32, T) IList<T>.Insert(Int32, T) IList<T>.Insert(Int32, T)

如果调用,会引发 NotSupportedExceptionThrows a NotSupportedException if called.

IList<T>.Item[Int32] IList<T>.Item[Int32] IList<T>.Item[Int32] IList<T>.Item[Int32]

返回集合中具有指定 index 的对象。Returns the object in the collection that has the specified index.

IList<T>.RemoveAt(Int32) IList<T>.RemoveAt(Int32) IList<T>.RemoveAt(Int32) IList<T>.RemoveAt(Int32)

如果调用,会引发 NotSupportedExceptionThrows a NotSupportedException if called.

扩展方法

CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>)

在给定其泛型参数 TDataTable 的输入 DataRow 对象的情况下,返回包含 IEnumerable<T> 对象副本的 DataRowReturns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>)

返回元素集合,其中包含源集合中每个节点的上级。Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName)

返回经过筛选的元素集合,其中包含源集合中每个节点的上级。Returns a filtered collection of elements that contains the ancestors of every node in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子代节点的集合。Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>)

返回元素集合,其中包含源集合中每个元素和文档的子代元素。Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName)

返回经过筛选的元素集合,其中包含源集合中每个元素和文档的子代元素。Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>)

返回源集合中每个元素和文档的子元素的集合。Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName)

返回源集合中经过筛选的每个元素和文档的子元素集合。Returns a filtered collection of the child elements of every element and document in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>)

返回节点集合(其中包含源集合中的所有节点),并按文档顺序排列。Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子节点集合。Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>)

将源集合中的每个节点从其父节点中移除。Removes every node in the source collection from its parent node.

适用于