字符串声明"A"+"B"vs"AB"

Ruu*_*jah -3 c# string

代替

string someString = "AB";
Run Code Online (Sandbox Code Playgroud)

我偶然发现了

string someString = "A" + "B";
Run Code Online (Sandbox Code Playgroud)

是否有任何技术解释使第二种方式更有利?

Sco*_*ain 6

var answer = "The only thing advantageous is readability, if you have large " +
             "amounts of text it can be useful to break up the text inside the " +
             "source code for better readability. The compiler will turn it " +
             "in to a single string at compile time anyway";
Run Code Online (Sandbox Code Playgroud)

  • @HenkHolterman但是如果你不希望*渲染的字符串有这些换行符,那么这是一个问题. (4认同)