MatchCollection.IEnumerable<Match>.GetEnumerator 方法

定義

傳回逐一查看集合的列舉值。

 virtual System::Collections::Generic::IEnumerator<System::Text::RegularExpressions::Match ^> ^ System.Collections.Generic.IEnumerable<System.Text.RegularExpressions.Match>.GetEnumerator() = System::Collections::Generic::IEnumerable<System::Text::RegularExpressions::Match ^>::GetEnumerator;
System.Collections.Generic.IEnumerator<System.Text.RegularExpressions.Match> IEnumerable<Match>.GetEnumerator ();
abstract member System.Collections.Generic.IEnumerable<System.Text.RegularExpressions.Match>.GetEnumerator : unit -> System.Collections.Generic.IEnumerator<System.Text.RegularExpressions.Match>
override this.System.Collections.Generic.IEnumerable<System.Text.RegularExpressions.Match>.GetEnumerator : unit -> System.Collections.Generic.IEnumerator<System.Text.RegularExpressions.Match>
Function GetEnumerator () As IEnumerator(Of Match) Implements IEnumerable(Of Match).GetEnumerator

傳回

可用來逐一查看集合的列舉值。

實作

例外狀況

集合是唯讀的。

備註

傳回 IEnumerator<T> 的功能可讓您藉由公開屬性 來逐一 Current 查看集合。您可以使用列舉值來讀取集合中的數據,但不能修改集合。 一開始,列舉程式位在集合中的第一個項目之前。 在這個位置上,Current 並未定義。 因此,您必須先呼叫 MoveNext 方法,將列舉值前移至集合的第一個專案,然後再讀取 的值 CurrentCurrent 會傳回相同的物件,直到 MoveNext 再次呼叫 為 MoveNext 下一個項目的設定 Current 為止。 如果 MoveNext 傳遞集合結尾,列舉值會放在集合的最後一個專案後面,並 MoveNextfalse回 。 當列舉值位於這個位置時,後續呼叫 MoveNext 也會傳回 false。 如果最後一 MoveNext 次呼叫傳 false回 , Current 則為未定義。 您不能再次將 Current 設定為集合的第一個項目;您必須建立新的列舉值執行個體。 如果對集合進行變更,例如新增、修改或刪除專案,則列舉值的行為是未定義的。 列舉值沒有集合的獨佔存取權,因此只要集合保持不變,列舉值就會保持有效。 如果對集合進行變更,例如新增、修改或刪除專案,列舉值就會失效,而且您可能會得到非預期的結果。 此外,列舉集合不是安全線程的程式。 若要保證線程安全,您應該在列舉值期間鎖定集合,或在集合上實作同步處理。 命名空間中 System.Collections.Generic 集合的預設實作不會同步處理。

適用於