Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

String.Chars Property

Gets the character at a specified character position in the current String object.

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

public char this [
	int index
] { get; }
/** @property */
public char get_Chars (int index)

Not applicable.



A character position in the current String object.

Property Value

A Unicode character.

Exception typeCondition


index is greater than or equal to the length of this object or less than zero.

The index parameter is zero-based.

This property returns the Char at the position specified by the index parameter. However, a Unicode character might be represented by more than one Char. Use the System.Globalization.StringInfo class to work with each Unicode character instead of each Char.

The following code example demonstrates how you can use this indexer in a routine to validate a string.

Console.Write("Type a string : ");
string myString = Console.ReadLine();
for (int i = 0; i < myString.Length; i ++)
       Console.WriteLine("{0} is a hexadecimal digit.", myString[i]); 
   Console.WriteLine("{0} is not a hexadecimal digit.", myString[i]); 

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

© 2017 Microsoft