C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Tip: For some programmers, using Environment.NewLine is more descriptive, in that it indicates exactly what it is.
Info: In most cases, there is no functional difference between Environment.NewLine and alternative representations.
VB.NET program that uses Environment.NewLine
Module Module1
Sub Main()
' Create two-line string.
Dim value As String = "[First" + _
Environment.NewLine + _
"Second]"
' Write to console.
Console.WriteLine(value)
End Sub
End Module
Output
[First
Second]
Here: We use the & operator on the string literal. Its effect is equivalent to the + operator shown in the first example.
VB.NET program that uses vbCrLf
Module Module1
Sub Main()
' Use vbCrLf.
Dim value As String = "[First" & vbCrLf & "Second]"
' Write to console.
Console.WriteLine(value)
End Sub
End Module
Output
[First
Second]
Next: This is the relevant instruction from the intermediate language: The string is "\r\n".
IL for vbCrLf
L_0001: ldstr "[First\r\nSecond]"
Note: These developers would be wise to choose Environment.NewLine to preserve their sanity.