How to insert newline in string literal?

前端 未结 12 795
没有蜡笔的小新
没有蜡笔的小新 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:54

    I like more the "pythonic way"

    List lines = new List {
        "line1",
        "line2",
        String.Format("{0} - {1} | {2}", 
            someVar,
            othervar, 
            thirdVar
        )
    };
    
    if(foo)
        lines.Add("line3");
    
    return String.Join(Environment.NewLine, lines);
    

提交回复
热议问题