FixedLengthString.ToString 方法

定義

FixedLengthString 轉換成 String

C#
public override string ToString ();

傳回

String,包含 FixedLengthString 的值。

範例

下列範例示範如何宣告和使用 FixedLengthString

VB
Private Sub DemoFixedLengthString()  
    ' Declare a string that has a length of 7 characters and assign the  
    ' initial string. The additional 5 positions will be padded with  
    ' spaces.  
    Dim fixedString As New FixedLengthString(7, "He")  
    ' Display the string in a message box.  
    MsgBox(fixedString.ToString)  
    ' Assign a new value to the string.  
    fixedString.Value = "Hello World"  
    ' Display again. Note that only the first 7 characters are shown.  
    MsgBox(fixedString.ToString)  
End Sub  

備註

類別 FixedLengthString 可用來模擬 Visual Basic 6.0 字串的行為,這可讓您宣告長度固定的字串。 FixedLengthString無法轉換成 String;您必須參考 Value 屬性,或呼叫 ToString 方法來轉換型別。

注意

Microsoft.VisualBasic.Compatibility.VB6 命名空間中的函式和物件都是供這些工具使用,以便從 Visual Basic 6.0 升級至 Visual Basic 2008。 在大多數情況下,這些函式和物件會複製在 .NET Framework 其他命名空間中可以找到的功能。 只有當 Visual Basic 6.0 程式碼模型與 .NET Framework 實作有顯著差異時,才會需要這些函式和物件。

適用於

產品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1