Windows apps
Collapse the table of content
Expand the table of content
Information
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.

StringBuilder::Chars Property (Int32)

 

Gets or sets the character at the specified character position in this instance.

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

public:
property wchar_t default[
	int index
] {
	wchar_t get(int index);
	void set(int index, wchar_t value);
}

Parameters

index
Type: System::Int32

The position of the character.

Property Value

Type: System::Char

The Unicode character at position index.

Exception Condition
ArgumentOutOfRangeException

index is outside the bounds of this instance while setting a character.

IndexOutOfRangeException

index is outside the bounds of this instance while getting a character.

The index parameter is the position of a character within the StringBuilder. The first character in the string is at index 0. The length of a string is the number of characters it contains. The last accessible character of a StringBuilder instance is at index Length - 1.

Chars is the default property of the StringBuilder class. In C#, it is an indexer. This means that individual characters can be retrieved from the Chars property as shown in the following example, which counts the number of alphabetic, white-space, and punctuation characters in a string.

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

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2017 Microsoft