Environment.NewLine 属性
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取为此环境定义的换行字符串。
public:
static property System::String ^ NewLine { System::String ^ get(); };
C#
public static string NewLine { get; }
member this.NewLine : string
Public Shared ReadOnly Property NewLine As 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
*/
C#
// 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 自动追加到由 Console.WriteLine 和 StringBuilder.AppendLine 方法处理的文本。
产品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |