MatchCollection.Count Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the number of matches.
public:
property int Count { int get(); };
public int Count { get; }
member this.Count : int
Public ReadOnly Property Count As Integer
Property Value
The number of matches.
Implements
Exceptions
A time-out occurred.
Remarks
Accessing the Count property causes the regular expression engine to populate the collection using direct evaluation. In contrast, calling the GetEnumerator() method (or using the foreach statement) causes the regular expression engine to populate the collection on an as-needed basis using lazy evaluation. Direct evaluation 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 determine the number of elements in the collection before it has been fully populated 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 single match exceeds that time-out interval.