NewLine Constant

  • Thread starter Thread starter Jim Heavey
  • Start date Start date
J

Jim Heavey

If I have a "long" string variable which is a I break up into a multiline
value, I get a "Newline Constant" error in the compiler. If I make it all
a single line, then it has no problem.

In VB, you would use a "_" to create a continuation to the next line. I
did not think "C#" used a continuation character and that it looked for a
";" to terminate a line.

So why does it not like when I create a multiline variable?

Thanks in advance for your assistance!!!!!!
 
You can either embed \n in your string or escape the string with a @ and
enter your newlines.
e.g.
private string whatever = @"This is the first line.
This is the second line.
This is the third line.";

or
private string whatever = "This is the first line.\nThis is the second
line.\nThis is the third line.";
 
Jim,
If I have a "long" string variable which is a I break up into a multiline
value, I get a "Newline Constant" error in the compiler. If I make it all
a single line, then it has no problem.

In VB, you would use a "_" to create a continuation to the next line. I
did not think "C#" used a continuation character and that it looked for a
";" to terminate a line.

So why does it not like when I create a multiline variable?

Try this:

System.String aVariable =
"This is line 1\n"
+ "This is line 2\n"
+ "This is line 3\n";

Does that help? I can't tell what your real problem is. You might want to
post the line of code that is causing the problem.

Regards,

Randy
 
Back
Top