Environment.NewLine 屬性

定義

取得為這個環境定義的新行字串 (Newline String)。

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

屬性值

String

\r\n 適用于非 Unix 平臺或 \n Unix 平臺。

範例

下列範例會顯示以分行符號分隔的兩行。

// Sample for the Environment::NewLine property
using namespace System;

int main()
{
   Console::WriteLine();
   Console::WriteLine("NewLine: {0}  first line {0}  second line", Environment::NewLine);
}

/*
This example produces the following results:

NewLine:
first line
second line
*/
// 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',或在 vbCrLf Microsoft Visual Basic 中使用。

NewLine會自動附加至 和 StringBuilder.AppendLine 方法所 Console.WriteLine 處理的文字。

適用於