Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Provides an enumerator that iterates through the collection.
Namespace: System.Text.RegularExpressions
Assembly: System.Text.RegularExpressions (in System.Text.RegularExpressions.dll)
Syntax
'Declaration
Public Function GetEnumerator As IEnumerator
public IEnumerator GetEnumerator()
public:
virtual IEnumerator^ GetEnumerator() sealed
abstract GetEnumerator : unit -> IEnumerator
override GetEnumerator : unit -> IEnumerator
public final function GetEnumerator() : IEnumerator
Return Value
Type: System.Collections. . :: . .IEnumerator
An object that contains all Match objects within the MatchCollection.
Implements
IEnumerable. . :: . .GetEnumerator() () () ()
Exceptions
Exception | Condition |
---|---|
RegexMatchTimeoutException | A time-out occurred. |
Remarks
Instead of calling the GetEnumerator method to retrieve an enumerator that lets you iterate through the Match objects in the collection, you should use the group iteration construct (such as foreach in C# and For Each…Next in Visual Basic) provided by your programming language.
Iterating the members of the MatchCollection object using the GetEnumerator method (or the foreach statement in C# and the For Each...Next statement in Visual Basic) causes the regular expression engine to populate the collection on an as needed basis using lazy evaluation. This is analogous to repeatedly calling the Regex..::..Match method, and then adding the resulting match to the MatchCollection object. In contrast, the regular expression engine uses direct evaluation to populate the collection all at once when the Count property is accessed. This can be a much more expensive method of building the collection than lazy evaluation.
Because the MatchCollection object is generally populated by using lazy evaluation, trying to navigate to the next member of the collection may throw a RegexMatchTimeoutException exception. This exception can be thrown if a time-out value for matching operations is in effect, and the attempt to find the next match exceeds that time-out interval.
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see dd66cd4c-b087-415f-9c3e-94e3a1835f74.