Re: \n in C#?

Tech-Archive recommends: Fix windows errors by optimizing your registry



Mmm Jon,

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?

Scott

"Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> wrote in message
news:MPG.1dbbfcd1b10cf47298c90b@xxxxxxxxxxxxxxxxxxxxxxx
> Michael A. Covington <look@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>> 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.
>
> 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.
>
> --
> Jon Skeet - <skeet@xxxxxxxxx>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too


.



Relevant Pages

  • Re: in C#?
    ... > public static string get_NewLine ... in terms of the compiler of a program which *uses* ... So a program like the following, compiled on Windows but run on Linux, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: This doesnt feel right
    ... > public static string ChannelType = "If a measurement point is AC or DC> coupled then this> field has no effect"; ... > Compiler didn't complain at first, as I had to fix other bits of code. ... It complained that it needed const rather than static. ...
    (microsoft.public.dotnet.languages.csharp)