MatchCollection Class

MatchCollection Class

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

Represents the set of successful matches found by iteratively applying a regular expression pattern to the input string.

System::Object
  System.Text.RegularExpressions::MatchCollection

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

No code example is currently available or this language may not be supported.

The MatchCollection type exposes the following members.

  NameDescription
Public propertyCountGets the number of matches.
Public propertyIsReadOnlyGets a value that indicates whether the collection is read only.
Public propertyIsSynchronizedGets a value indicating whether access to the collection is synchronized (thread-safe).
Public propertyItemGets an individual member of the collection.
Public propertySyncRootGets an object that can be used to synchronize access to the collection.
Top

  NameDescription
Public methodCopyToCopies all the elements of the collection to the given array starting at the given index.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetEnumeratorProvides an enumerator in the same order as Item.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public Extension MethodAsQueryableConverts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodCast<TResult>Converts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodOfType<TResult>Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top

The collection is immutable (read-only) and has no public constructor. The Regex::Matches method returns a MatchCollection object.

When applying a regular expression pattern to a particular input string, the regular expression engine uses either of two techniques to build the MatchCollection object:

  • Direct evaluation.

    The MatchCollection object is populated all at once with all matches resulting from a particular call to the Regex::Matches method. This technique is used when the collection's Count property is accessed. It typically is the more expensive method of populating the collection and entails a greater performance hit.

  • Lazy evaluation.

    The MatchCollection object is populated as needed on a match-by-match basis. It is equivalent to the regular expression engine calling the Regex::Match method repeatedly and adding each match to the collection. This technique is used when the collection is accessed through its GetEnumerator method, or when it is accessed using the foreach statement (in C#) or the For Each...Next statement (in Visual Basic).

The following example code illustrates the use of the MatchCollection class to interrogate a set of Match instances.

No code example is currently available or this language may not be supported.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Show:
© 2017 Microsoft