J
James
Hi all,
Probably the first thing most of you learn, but I don't know the
newline character for C#.
Thanks,
James
Probably the first thing most of you learn, but I don't know the
newline character for C#.
Thanks,
James
This will work cross platform, as well as the first line of code above.
Don't hardcode in specific newline sequences such as \n, \r\n, or \r.
Hi all,
Probably the first thing most of you learn, but I don't know the
newline character for C#.
Thanks,
James
Probably the first thing most of you learn, but I don't know the
newline character for C#.
JS said:The newline character is O/S dependent. I would use the
Environment.NewLine, as others have already suggested. However, if you
are
determined to use a character sequence...
\r = newline for macintosh
\r\n = newline for windows
\n = newline for UNIX based systems
Michael A. Covington said:This is the kind of thing that ought to be built into the language as
something more concise than Environment.NewLine. Maybe define \N as the
OS-dependent newline, known to the compiler.
Scott Coonce said:Pardon my confusion, but was interested in such a long thread about such a
simple topic (at first glance). Reflector gives the following code:
public static string get_NewLine()
{
return "\r\n";
}
Isn't this the compiler hard coding the newline string?
Jon Skeet said:No - precisely because it's *not* known to the compiler. The compiler
doesn't know what platform the code is going to *run* on, it only knows
the platform it's being *compiled* on.
Michael A. Covington said:OK, then, the compiler should insert some code to insert the correct value
at run time.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.