Export (0) Print
Expand All

MatchCollection.GetEnumerator Method

Provides an enumerator that iterates through the collection.

Namespace:  System.Text.RegularExpressions
Assembly:  System (in System.dll)

public IEnumerator GetEnumerator()

Return Value

Type: System.Collections.IEnumerator
An object that contains all Match objects within the MatchCollection.

Implements

IEnumerable.GetEnumerator()

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 EachNext 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.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft