Environment.NewLine 属性

获取为此环境定义的换行字符串。

**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public Shared ReadOnly Property NewLine As String
用法
Dim value As String

value = Environment.NewLine
public static string NewLine { get; }
public:
static property String^ NewLine {
    String^ get ();
}
/** @property */
public static String get_NewLine ()
public static function get NewLine () : String

属性值

包含“\r\n”的字符串,用于非 Unix 平台, 或 包含“\n”的字符串,用于 Unix 平台。

备注

NewLine 的属性值是一个专门为当前平台和 .NET Framework 实现而自定义的常数。有关属性值中转义字符的更多信息,请参见 字符转义

NewLine 提供的功能常常是换行符 (newline)、换行符 (line feed)、分行符、回车符、CRLF 和行尾等术语表示的含义。

NewLine 可以与语言特定的换行支持一起使用,如 Microsoft C# 和 C/C++ 中的“\r”和“\n”,或 Microsoft Visual Basic 中的 vbCrLf

NewLine 自动附加到 System.Console.WriteLineSystem.Text.StringBuilder.AppendLine 方法处理的文本。

示例

下面的代码示例显示由换行符分隔的三行。

' Sample for the Environment.NewLine property
Imports System

Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Console.WriteLine("NewLine: {0}  first line{0}  second line{0}  third line", _
                             Environment.NewLine)
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'NewLine:
'  first line
'  second line
'  third line
'
// Sample for the Environment.NewLine property
using System;

class Sample 
{
    public static void Main() 
    {
    Console.WriteLine();
    Console.WriteLine("NewLine: {0}  first line{0}  second line{0}  third line",
                          Environment.NewLine);
    }
}
/*
This example produces the following results:

NewLine:
  first line
  second line
  third line
*/
// Sample for the Environment::NewLine property
using namespace System;
int main()
{
   Console::WriteLine();
   Console::WriteLine( "NewLine: {0}  first line {0}  second line {0}  third line", Environment::NewLine );
}

/*
This example produces the following results:

NewLine:
first line
second line
third line
*/
// Sample for the Environment.NewLine property
import System.*;

class Sample
{
    public static void main(String[] args)
    {
        Console.WriteLine();
        Console.WriteLine("NewLine: {0}  first line{0}  second line{0}"
            + "  third line", Environment.get_NewLine());
    } //main
} //Sample
/*
This example produces the following results:

NewLine:
  first line
  second line
  third line
*/

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Environment 类
Environment 成员
System 命名空间