共用方式為


$ (Visual Basic 參考)

將字串文本標識為 內插字串。 內插字串是類似範本的字串,其中包含文本文本和 內插表達式。 內插表達式是生成要在結果字串中格式化的結果的表達式。 當解析內插字串時,例如在賦值語句或方法調用中,其內插表達式將替換為它們在結果字串中的字串表示形式。 內插字串是 .NET 支援的 複合格式字串 的替代品。

下面的範例使用該 $ 字元定義內插字串。

Public Module Example
   Public Sub Main()
      Dim name = "John"
      Dim greeting = $"Hello, {name}!"
      Console.WriteLine(greeting)
   End Sub
End Module
' The example displays the following output:
'       Hello, John!
                   

有關內插字串的更多資訊,請參閱 內插字串 主題。

另請參閱