StringBuilder.ToString 方法
定義
將 StringBuilder 的值轉換為 String。Converts the value of a StringBuilder to a String.
多載
ToString() |
將這個執行個體的值轉換為 String。Converts the value of this instance to a String. |
ToString(Int32, Int32) |
將這個執行個體的子字串值轉換為 String。Converts the value of a substring of this instance to a String. |
ToString()
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 方法,將 StringBuilder 物件轉換為物件,然後才能將 String 物件所代表的字串傳遞 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)
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
這個執行個體中的子字串開始位置。The starting position of the substring in this instance.
- length
- Int32
子字串的長度。The length of the substring.
傳回
字串,此字串值與這個執行個體的指定子字串值相同。A string whose value is the same as the specified substring of this instance.
例外狀況
startIndex
或 length
小於零。startIndex
or length
is less than zero.
-或--or-
startIndex
和 length
總計大於目前執行個體的長度。The sum of startIndex
and length
is greater than the length of the current instance.
備註
您必須先呼叫 ToString 方法,將 StringBuilder 物件轉換為物件,然後才能將 String 物件所代表的字串傳遞 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.