How to use escape characters with string interpolation in C# 6?

后端 未结 7 549
孤街浪徒
孤街浪徒 2020-12-03 06:42

I\'ve been using string interpolation and loving it, however I have an issue where I am trying to include a backslash in my output, but am not able to get it to work.

7条回答
  •  天命终不由人
    2020-12-03 07:09

    You can use this -

    'First, declare the curley braces as chars
            Dim LeftBrace As Char = "{"
            Dim RightBrace As Char = "}"
    
            'Then in your string, use like this-
            Dim myStr As String = $"This is a {LeftBrace}String{RightBrace}"
    
            'Now, the output will be
            ' This is a {string}code here
    

提交回复
热议问题