I use Environment.NewLine, my colleagues use vbCrLf.
When I'm doing a code review for them I want something that I can point to to say "use Environment.NewLine instead of vbCrLf"
Or, am I just peeing in the wind, and it doesn't really matter ?
I use Environment.NewLine, my colleagues use vbCrLf.
When I'm doing a code review for them I want something that I can point to to say "use Environment.NewLine instead of vbCrLf"
Or, am I just peeing in the wind, and it doesn't really matter ?
Environment.NewLine is more portable, making to code easier to be read by someone coding in C#. Technically vbCrLf is a constant, where NewLine is not. This is because on a different OS, NewLine may not return CR/LF. On Unix it would just be LF.
Another point is that Environment.NewLine
expresses the intended meaning more clearly. In most cases, the goal is Place a newline in this string, not Place carriage-return and line-feed characters in this string. Environment.NewLine
states what to do, vbCrlf
states how to do it.
In most cases, either one will work correctly.
However, if you are developing on Mono and use Environment.NewLine on a Unix OS, then you will get different results (\n (LF) instead of \r\n (CRLF)).
In addition, if you ever want/need to port your code to C#, Environment.NewLine will not have to be updated whereas vbCrLf will.
Environment.NewLine
is portable in .NET and for someone unfamiliar with VB it is more readable than vbCrLf
.