String.Chars Property

Gets the character at a specified character position in this instance.

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

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

JScript supports the use of indexed properties, but not the declaration of new ones.



A character position in this instance.

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++ )
   if ( Uri::IsHexDigit( myString[ i ] ) )
            Console::WriteLine( "{0} is a hexadecimal digit.", myString[ i ] );
            Console::WriteLine( "{0} is not a hexadecimal digit.", myString[ i ] );

Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0