举个例子。
MessageBox.Show("You cannot create an incident and also provide a Case Number\nPlease choose one or the other");
我想在这两行中使用它,但没有+运算符
MessageBox.Show("You cannot create an incident and also provide a Case Number\n" +
"Please choose one or the other");
但是我想知道“在没有字符串连接的情况下,我可以做一些转义字符吗?”
答案 0 :(得分:3)
你可以这样做(注意你不能缩进第二行,否则缩进将成为字符串的一部分):
MessageBox.Show(@"You cannot create an incident and also provide a Case Number
Please choose one or the other");
但实际上您不应该担心将+
字符串连接用作the compiler will optimize it away。
答案 1 :(得分:3)
您可以将其设为verbatim字符串:
string msg = @"You cannot create an incident and also provide a Case Number
Please choose one or the other";
MessageBox.Show( msg );
答案 2 :(得分:1)
你去吧
MessageBox.Show(@"You cannot create an incident and also provide a Case Number
Please choose one or the other");
答案 3 :(得分:-2)
使用以下内容:
MessageBox.Show(string.Format("This is my first line. {0} This is my second line. {0}" +
"And this is my third line.", Environment.NewLine));
请记住,这仅适用于某些情况。例如,在HTML中,您需要使用<br />
而不是Environment.NewLine
,但系统是相同的。