TextEffectCollection.GetEnumerator TextEffectCollection.GetEnumerator TextEffectCollection.GetEnumerator TextEffectCollection.GetEnumerator Method

定义

返回一个可循环访问集合的枚举数。Returns an enumerator that can iterate through the collection.

public:
 System::Windows::Media::TextEffectCollection::Enumerator GetEnumerator();
public System.Windows.Media.TextEffectCollection.Enumerator GetEnumerator ();
member this.GetEnumerator : unit -> System.Windows.Media.TextEffectCollection.Enumerator
Public Function GetEnumerator () As TextEffectCollection.Enumerator

返回

注解

枚举器仅允许读取集合中的数据。Enumerators only allow reading the data in the collection. 枚举器不能用于修改基础集合。Enumerators cannot be used to modify the underlying collection.

最初, 枚举器位于集合中第一项之前。Initially, the enumerator is positioned before the first item in the collection. Reset 也会将枚举器放回此位置。Reset also brings the enumerator back to this position. 在此位置, 调用Current会引发异常。At this position, calling Current throws an exception. 因此, 在读取的MoveNext Current值之前, 必须调用以将枚举器前进到集合的第一项。Therefore, you must call MoveNext to advance the enumerator to the first item of the collection before reading the value of Current.

在调用 CurrentMoveNext 之前,Reset 返回同一对象。Current returns the same object until either MoveNext or Reset is called. MoveNext设置Current为下一项。MoveNext sets Current to the next item.

在传递集合的末尾后, 枚举数将定位到集合中的最后一项之后, 然后调用MoveNext返回。 falseAfter the end of the collection is passed, the enumerator is positioned after the last item in the collection, and calling MoveNext returns false. 如果最后一次调用MoveNext返回false, 则Current调用会引发异常。If the last call to MoveNext returned false, calling Current throws an exception. 若要Current再次将设置为集合的第一项, 可以调用Reset后跟MoveNextTo set Current to the first item of the collection again, you can call Reset followed by MoveNext.

只要集合保持不变,枚举数就保持有效。An enumerator remains valid as long as the collection remains unchanged. 如果对集合所做的更改 (如添加、修改或删除项), 则枚举器将失效且不可恢复, 并且MoveNextReset或的InvalidOperationException下一个调用将引发。If changes are made to the collection, such as adding, modifying or deleting items, the enumerator is irrecoverably invalidated and the next call to MoveNext or Reset throws an InvalidOperationException. 如果在和MoveNext Current之间修改集合, Current则将返回其设置为的项, 即使枚举器已失效。If the collection is modified between MoveNext and Current, Current will return the item that it is set to, even if the enumerator is already invalidated.

枚举数没有对集合的独占访问权;因此,从头到尾对一个集合进行枚举在本质上不是一个线程安全的过程。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 either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.

适用于