ArrangedElementCollection.GetEnumerator ArrangedElementCollection.GetEnumerator ArrangedElementCollection.GetEnumerator ArrangedElementCollection.GetEnumerator Method

定义

返回一个用于访问整个集合的枚举数。Returns an enumerator for the entire collection.

public:
 virtual System::Collections::IEnumerator ^ GetEnumerator();
public virtual System.Collections.IEnumerator GetEnumerator ();
abstract member GetEnumerator : unit -> System.Collections.IEnumerator
override this.GetEnumerator : unit -> System.Collections.IEnumerator
Public Overridable Function GetEnumerator () As IEnumerator

返回

一个用于访问整个集合的 IEnumeratorAn IEnumerator for the entire collection.

实现

注解

通常, 枚举器不具有对集合的独占访问权限;因此, 枚举集合本质上不是线程安全的过程。Typically the enumerator does not have exclusive access to the collection; therefore, enumerating through a collection is intrinsically not a thread-safe procedure. 即使集合是同步的, 其他线程仍可以修改集合, 这会导致枚举器引发异常。Even when a collection is synchronized, other threads could still modify the collection, which causes the enumerator to throw an exception. 若要保证枚举过程中的线程安全, 可以遵循以下策略之一:To guarantee thread safety during enumeration, you can follow one of the following strategies:

  • 使用在整个枚举过程中锁定集合MonitorLock the collection during the entire enumeration using a Monitor.

  • 捕获并处理由其他线程进行的更改所导致的异常。Catch and handle the exceptions that result from changes made by other threads.

适用于

另请参阅