How to insert newline in string literal?

前端 未结 12 741
没有蜡笔的小新
没有蜡笔的小新 2020-12-07 09:07

In .NET I can provide both \\r or \\n string literals, but there is a way to insert something like \"new line\" special character like Enviro

12条回答
  •  囚心锁ツ
    2020-12-07 09:58

    newer .net versions allow you to use $ in front of the literal which allows you to use variables inside like follows:

    var x = $"Line 1{Environment.NewLine}Line 2{Environment.NewLine}Line 3";
    

提交回复
热议问题