Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Item Property
Collapse the table of content
Expand the table of content

MatchCollection.Item Property

Gets an individual member of the collection.

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

public virtual Match this [
	int i
] { get; }
/** @property */
public Match get_Item (int i)

Not applicable.

Parameters

i

Index into the Match collection.

Property Value

The captured substring at position i in the collection.

Exception typeCondition

ArgumentOutOfRangeException

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

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

The following example parses the first sentence of Nathaniel Hawthorne's House of the Seven Gables and returns a MatchCollection object that contains all words that begin with either an uppercase or lowercase "h". The Item property is then used to retrieve each word and display it to the console.

The example produces the following output:

Half
house
huge

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2015 Microsoft