NewLine Property

Environment.NewLine Property


Gets the newline string defined for this environment.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

public static string NewLine { get; }

Property Value

Type: System.String

A string containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms.

The property value of NewLine is a constant customized specifically for the current platform and implementation of the .NET Framework. For more information about the escape characters in the property value, see Character Escapes in Regular Expressions.

The functionality provided by NewLine is often what is meant by the terms newline, line feed, line break, carriage return, CRLF, and end of line.

NewLine can be used in conjunction with language-specific newline support such as the escape characters '\r' and '\n' in Microsoft C# and C/C++, or vbCrLf in Microsoft Visual Basic.

NewLine is automatically appended to text processed by the Console.WriteLine and StringBuilder.AppendLine methods.

The following example displays three lines separated by newlines.

// Sample for the Environment.NewLine property
using System;

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

  first line
  second line
  third line

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
© 2015 Microsoft