Environment.NewLine 屬性

定義

取得為此環境定義的換行字串。

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

屬性值

\r\n 適用於非 Unix 平台,或 \n 用於 Unix 平台。

範例

以下範例顯示兩行之間由一條換行分隔。

// 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
'

備註

NewLine 的屬性值是針對當前平台與 .NET Framework 實作特別客製化的常數值。 欲了解更多關於屬性值中逃脫字元的資訊,請參見「字元逃脫」。

NewLine 提供的功能通常就是換行、換行、換行、回車、CRLF 和行尾等術語所指的。

NewLine 可搭配語言特定的換行碼支援使用,例如 Microsoft C# 和 C/C++ 中的轉義字元 '\r'和 '\n',或 Microsoft Visual Basic 中的 vbCrLf

NewLine 會自動附加到由 Console.WriteLine and StringBuilder.AppendLine 方法處理的文字中。

適用於