StringBuilder.ToString StringBuilder.ToString StringBuilder.ToString StringBuilder.ToString Method

定义

StringBuilder 的值转换为 StringConverts the value of a StringBuilder to a String.

重载

ToString() ToString() ToString() ToString()

将此实例的值转换为 StringConverts the value of this instance to a String.

ToString(Int32, Int32) ToString(Int32, Int32) ToString(Int32, Int32) ToString(Int32, Int32)

将此实例中子字符串的值转换为 StringConverts the value of a substring of this instance to a String.

ToString() ToString() ToString() ToString()

将此实例的值转换为 StringConverts the value of this instance to a String.

public:
 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String

返回

其值与此实例相同的字符串。A string whose value is the same as this instance.

示例

下面的示例演示如何调用 ToString 方法。The following example demonstrates calling the ToString method. 此示例是为StringBuilder类提供的更大示例的一部分。This example is part of a larger example provided for the StringBuilder class.

// Display the number of characters in the StringBuilder
// and its string.
Console::WriteLine("{0} chars: {1}", sb->Length, sb->ToString());
// Display the number of characters in the StringBuilder and its string.
Console.WriteLine("{0} chars: {1}", sb.Length, sb.ToString());
' Display the number of characters in the StringBuilder and its string.
Console.WriteLine("{0} chars: {1}", sb.Length, sb.ToString())

注解

必须先ToString调用方法将String StringBuilder对象转换为对象, 然后才能将StringBuilder对象表示的字符串传递给具有String参数或在用户界面中显示它的方法。You must call the ToString method to convert the StringBuilder object to a String object before you can pass the string represented by the StringBuilder object to a method that has a String parameter or display it in the user interface.

ToString(Int32, Int32) ToString(Int32, Int32) ToString(Int32, Int32) ToString(Int32, Int32)

将此实例中子字符串的值转换为 StringConverts the value of a substring of this instance to a String.

public:
 System::String ^ ToString(int startIndex, int length);
public string ToString (int startIndex, int length);
override this.ToString : int * int -> string
Public Function ToString (startIndex As Integer, length As Integer) As String

参数

startIndex
Int32 Int32 Int32 Int32

此实例内子字符串的起始位置。The starting position of the substring in this instance.

length
Int32 Int32 Int32 Int32

子字符串的长度。The length of the substring.

返回

一个字符串,其值与此实例的指定子字符串相同。A string whose value is the same as the specified substring of this instance.

异常

startIndexlength 小于零。startIndex or length is less than zero.

- 或 --or- startIndexlength 之和大于当前实例的长度。The sum of startIndex and length is greater than the length of the current instance.

注解

必须先ToString调用方法将String StringBuilder对象转换为对象, 然后才能将StringBuilder对象表示的字符串传递给具有String参数或在用户界面中显示它的方法。You must call the ToString method to convert the StringBuilder object to a String object before you can pass the string represented by the StringBuilder object to a method that has a String parameter or display it in the user interface.

适用于