Environment.NewLine Egenskap

Definition

Hämtar den nya strängen som definierats för den här miljön.

public:
 static property System::String ^ NewLine { System::String ^ get(); };
public static string NewLine { get; }
static member NewLine : string
Public Shared ReadOnly Property NewLine As String

Egenskapsvärde

\r\n för icke-Unix-plattformar eller \n för Unix-plattformar.

Exempel

I följande exempel visas två rader avgränsade med en ny rad.

// Sample for the Environment.NewLine property
using System;

class Sample
{
    public static void Main()
    {
        Console.WriteLine();
        Console.WriteLine($"NewLine: {Environment.NewLine}  first line{Environment.NewLine}  second line");
    }
}

/*
This example produces the following results:

NewLine:
  first line
  second line
*/
// Sample for the Environment.NewLine property
open System

printfn $"\nNewLine: {Environment.NewLine}  first line{Environment.NewLine}  second line"

// This example produces the following results:
//     NewLine:
//       first line
//       second line
' Sample for the Environment.NewLine property
Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Console.WriteLine($"NewLine:{Environment.NewLine}  first line{Environment.NewLine}  second line")
   End Sub
End Class

'This example produces the following results:
'
'NewLine:
'  first line
'  second line
'

Kommentarer

Egenskapsvärdet för NewLine är en konstant anpassad specifikt för den aktuella plattformen och implementeringen av .NET Framework. Mer information om escape-tecknen i egenskapsvärdet finns i Teckenflykter.

Funktionerna som tillhandahålls av NewLine är ofta vad som menas med termerna newline, line feed, line break, carriage return, CRLF och end of line.

NewLine kan användas tillsammans med språkspecifikt stöd för newline, till exempel escape-tecknen\roch\ni Microsoft C# och C/C++, eller vbCrLf i Microsoft Visual Basic.

NewLine läggs automatiskt till i text som bearbetas av Console.WriteLine metoderna och StringBuilder.AppendLine .

Gäller för