MatchCollection.Item[Int32] Property

Definition

Gets an individual member of the collection.

public:
 virtual property System::Text::RegularExpressions::Match ^ default[int] { System::Text::RegularExpressions::Match ^ get(int i); };
public virtual System.Text.RegularExpressions.Match this[int i] { get; }
member this.Item(int) : System.Text.RegularExpressions.Match
Default Public Overridable ReadOnly Property Item(i As Integer) As Match

Parameters

i
Int32

Index into the Match collection.

Property Value

The captured substring at position i in the collection.

Implements

Exceptions

i is less than 0 or greater than or equal to Count.

A time-out occurred.

Remarks

In C#, the Item[Int32] property is an indexer; it is not explicitly referenced in code, but instead allows the MatchCollection to be accessed as if it were an array.

Typically, individual items in the MatchCollection 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 or the foreach 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.

Applies to

See also