Adding two consecutive new lines in a C# statement

Hi,

I need to add two consecutive new lines in a statement as in the code below.

I used Enviroment.NewLine + Enviroment.NewLine and got an error.
Can you show me how to go about doing it. Thanks?


string Note_Text = " On " + NoteDate + " " + "at " + NoteTime + " " + NoteOwner + "  " + "wrote :" + Environment.NewLine + Environment.NewLine + getTheNote.NoteText;

Open in new window

adamtraskAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale BurrellDirectorCommented:
What was the error?
baretreeCommented:
as dale said, what's the error you're receiving?
anyway... I remember one time I had to use a constant for that

public static string sReturn = System.Environment.NewLine;

and then in my strings use the sReturn, because I was getting an error but can't recall if it was exactly because of the two consecutive newlines... I find that odd...
anyway, I have a project in where I have a string like

strMessage = "blah blah blah " + sReturn + sReturn + "more blah blah blah";

and it works perfectly

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
adamtraskAuthor Commented:
The name Environment doesn't exist in the current content
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

adamtraskAuthor Commented:
Thank you baretree:

It worked just as string variable:

string sReturn = System.Environment.NewLine;
Dale BurrellDirectorCommented:
Try fully qualifying it (or make sure the system namespace is included) e.g. System.Environment.NewLine
käµfm³d 👽Commented:
You might find string.Format a tad easier to work with (and read!!) than normal string concatnation. Using string.Format, you line above could be written as:

string Note_Text = string.Format(" On {0} at  {1} {2} wrote : {3}{3}{4}", NoteDate, NoteTime, NoteOwner, Environment.NewLine, getTheNote.NoteText);

Open in new window


Notice there are placeholders in the above string. The placeholders are of the form "{N}", where "N" is a number, starting at zero. Just like array indexes, format placeholders start at zero, and each placeholder that represents a different object gets a new number--incremented by one from the last number used. For the above, "{0}" corresponds to "NoteDate", since "NoteDate" is the first parameter to string.Format after the initial string, "{1}" corresponds to "NoteTime", "{2}" corresponds to "NoteOwner", both "{3}" correspond to "Environment.NewLine", and "{4}" corresponds to "getTheNote.NoteText". Using something like the above makes it a tad easier to debug improperly output strings you are building in your code.
Dale BurrellDirectorCommented:
It worked because you fully qualified it e.g. System.Environment.NewLine - you won't need to make it a local variable.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.