Count Property
Collapse the table of content
Expand the table of content

MatchCollection.Count Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets the number of matches.

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

'Declaration
Public ReadOnly Property Count As Integer

Property Value

Type: System.Int32
The number of matches.

Implements

ICollection.Count

Accessing individual members of the MatchCollection object by retrieving the value of the collection's Count property causes the regular expression engine to populate the collection all at once using direct evaluation. In contrast, calling the GetEnumerator method (or using 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. Direct evaluation can be a much more expensive method of building the collection than lazy evaluation.

The following example code illustrates the use of this property.


' Report the number of matches found.
outputBlock.Text &= String.Format("{0} matches found in:", matches.Count) & vbCrLf
outputBlock.Text &= String.Format("   {0}", text) & vbCrLf


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft