2

举这个例子。

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");

但我想知道“是否有一些转义字符可以在没有字符串连接的情况下完成?”

4

4 回答 4

3

你可以这样做(注意你不能缩进第二行,否则缩进将成为字符串的一部分):

MessageBox.Show(@"You cannot create an incident and also provide a Case Number
Please choose one or the other");

但实际上您不必担心使用+字符串连接,因为编译器会将其优化掉

于 2012-12-10T15:29:48.283 回答
3

您可以将其设为逐字字符串:

string msg = @"You cannot create an incident and also provide a Case Number
Please choose one or the other";
MessageBox.Show( msg );
于 2012-12-10T15:29:49.570 回答
1

干得好

MessageBox.Show(@"You cannot create an incident and also provide a Case Number 
Please choose one or the other");
于 2012-12-10T15:30:16.787 回答
-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,但系统是相同的。

于 2012-12-10T15:31:40.057 回答