MatchCollection.GetEnumerator Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Provides an enumerator in the same order as Item.

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

Syntax

'Declaration
Public Function GetEnumerator As IEnumerator
public IEnumerator GetEnumerator()

Return Value

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

Implements

IEnumerable.GetEnumerator()

Remarks

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.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.