Compartir a través de


MatchCollection.Count Property

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

Gets the number of matches.

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

Syntax

'Declaration
Public ReadOnly Property Count As Integer
public int Count { get; }

Property Value

Type: System.Int32
The number of matches.

Implements

ICollection.Count

Remarks

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.

Examples

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
// Report the number of matches found.
outputBlock.Text += String.Format("{0} matches found in:\n   {1}",
                  matches.Count,
                  text) + "\n";

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.