Export (0) Print
Expand All

String.GetEnumerator Method

Retrieves an object that can iterate through the individual characters in this string.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

member GetEnumerator : unit -> CharEnumerator

Return Value

Type: System.CharEnumerator
An enumerator object.

TipTip

Rather then calling the GetEnumerator method to retrieve a CharEnumerator object that you then use to enumerate a string, you should instead use your language's iteration construct (foreach in C#, for each in C++/CLR, and For Each in Visual Basic).

This method enables you to iterate the individual characters in a string. For example, the Visual Basic For Each and C# foreach statements invoke this method to return a CharEnumerator object that can provide read-only access to the characters in this string instance.

The following example iterates the characters in several strings and displays information about their individual characters. It uses the language iteration construct rather than a call to the GetEnumerator method.

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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft