Gets an individual member of the collection.
Assemblies: System.Text.RegularExpressions (in System.Text.RegularExpressions.dll)
System (in System.dll)
In C#, the property is an indexer; it is not explicitly referenced in code, but instead allows the MatchCollection collection to be accessed as if it were an array.
Typically, individual items in the MatchCollection object are accessed by their index only after the total number of items in the collection has been determined from the Count property. However, accessing the Count property causes the regular expression engine to use direct evaluation to build the collection all at once. This is typically more expensive than iterating the collection using the GetEnumerator method, the C# foreach statement, or the Visual Basic For Each...Next statement.
Because the MatchCollection object is generally populated by using lazy evaluation, trying to navigate to a specific match 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 a specific match exceeds that time-out interval.
The following example parses the first sentence of Nathaniel Hawthorne's House of the Seven Gables and returns a MatchCollection object that contains all words that begin with either an uppercase or lowercase "h". The property is then used to retrieve each word and display it to the console.
The example produces the following output:
Half house huge
.NET FrameworkSupported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
XNA FrameworkSupported in: 3.0, 2.0, 1.0
Portable Class LibrarySupported in: Portable Class Library
Supported in: Windows Phone 8.1
Supported in: Windows Phone Silverlight 8.1
Supported in: Windows Phone Silverlight 8