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

This however works fine:

ShippingConfirmationLabel.Text = "Using " + ShippingTypeRadioButtonList.SelectedValue + "
shipping to:<br>";

Sorry if this question has been asked earlier however upon searching nothing concrete came up for this. For some reason that code doesn't let me compile in VS.

Cheers Andrew

Andrew
  • 156
  • 2
  • 3
  • 12
  • may duplicate of http://stackoverflow.com/a/4086203/1495442 – Ria Aug 02 '12 at 08:33
  • Please see this screen shot. I am studying towards MCTS and it had it in the book : http://www.flickr.com/photos/79621732@N03/7696708028/ – Andrew Aug 02 '12 at 08:33
  • 1
    @Andrew this is an error in your book; as Steve already said, there is no line continuation character; further, your second sample won't compile unless you add @ in front of the opening double quote (see link from Ria's comment) – Markus Bruckner Aug 02 '12 at 08:40
  • It is surely a typo to be corrected in your book. In C# there is no need for line continuation since a line is not considered over until you reach a semi colon (";"). – Steve Aug 02 '12 at 08:43
  • I think your book has the `_` as an indicator that the line continues to aid the reader of the printed material. It's a bit confusing though, I agree. – Dervall Aug 02 '12 at 09:04
  • Thanks all for your assistance in this. – Andrew Aug 02 '12 at 20:04

2 Answers2

10

There is no Line Continuation Character in C# like in VB.NET
In C# exist the ; to delimit the end of an instruction.
This means that there is no need for a line continuation character since a line is not considered over until you reach a semi colon (";").

The + is the string concatenation operator and it does not means Line Continuation Character

ShippingConfirmationLabel.Text = 
            "Using " + 
            ShippingTypeRadioButtonList.SelectedValue + 
            "shipping to:<br>"; 

As you can see, you could break the line at every point you like (of course not in the middle of a keyword or identifier) and close it with the ; terminator.

Sometimes, for legibility or other reasons, you want to break apart a single string on different lines.
In this case you could use the string concatenation operator.

Steve
  • 213,761
  • 22
  • 232
  • 286
3

C# does not have line continuations. Just use a normal line break and the code should work just fine.

C# in comparison to VB uses ; as a statement terminator, which allows you to format the code however you like without indicating that the code continues on the next line.

_ in C# is a normal character, and could be used for variable names and such.

Dervall
  • 5,736
  • 3
  • 25
  • 48
  • You can't just use a normal line break and have the code work just fine, the compiler doesn't like it and gives the error 'new line in constant'. – chipples Nov 14 '16 at 16:47