ArrangedElementCollection.GetEnumerator 方法

定義

傳回整個集合的列舉值。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

傳回

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.

適用於

另請參閱