如何使用行继续符,在C#中使用下划线(_)

And*_*rew 5 c#

ShippingConfirmationLabel.Text = _
string.Format("Using {0} shipping to:<br>", _
ShippingTypeRadioButtonList.SelectedValue);
Run Code Online (Sandbox Code Playgroud)

然而,这工作正常:

ShippingConfirmationLabel.Text = "Using " + ShippingTypeRadioButtonList.SelectedValue + "
shipping to:<br>";
Run Code Online (Sandbox Code Playgroud)

对不起,如果之前已经问过这个问题,那么在搜索时没有任何具体内容可以提出.出于某种原因,代码不允许我在VS中编译.

干杯安德鲁

Ste*_*eve 8

Line Continuation Character在VB.NET中没有像C#那样的
C#存在;用于分隔指令的结尾.
这意味着不需要换行符,因为在到达分号(";")之前不考虑换行.

+是字符串连接运算符,它并不意味着Line Continuation Character

ShippingConfirmationLabel.Text = 
            "Using " + 
            ShippingTypeRadioButtonList.SelectedValue + 
            "shipping to:<br>"; 
Run Code Online (Sandbox Code Playgroud)

如您所见,您可以在您喜欢的每个点(当然不在关键字或标识符的中间)中断行,并使用;终止符关闭它.

有时,出于易读性或其他原因,您希望在不同的行上拆分单个字符串.
在这种情况下,您可以使用字符串连接运算符.