Export (0) Print
Expand All

Environment.NewLine Property

Gets the newline string defined for this environment.

[Visual Basic]
Public Shared ReadOnly Property NewLine As String
[C#]
public static string NewLine {get;}
[C++]
public: __property static String* get_NewLine();
[JScript]
public static function get NewLine() : String;

Property Value

A string containing "\r\n".

Remarks

The property value is a constant customized specifically for the current platform.

This value is automatically appended to text when using WriteLine methods, such as Console.WriteLine.

Example

[Visual Basic] 
' 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
'

[C#] 
// 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
*/

[C++] 
// Sample for the Environment::NewLine property
#using <mscorlib.dll>

using namespace System;

int main() {
   Console::WriteLine();
   Console::WriteLine(S"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
*/

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

Environment Class | Environment Members | System Namespace

Show:
© 2014 Microsoft