Environment.NewLine 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取为此环境定义的换行字符串。
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 和 StringBuilder.AppendLine 方法处理的文本。