Pure speed efficiency, then the first will win, especially since the second cannot be made const
, and then cannot be compiled.
Nevertheless, the second will be very darn, and I do not care.
More importantly, these are simply not the same thing.
It boils down to "why are you using \ r \ n \ t"?
If you use \ r \ n \ t because you are on Windows, and on Windows newlines are usually \ r \ n, then you should definitely use:
internal static readonly string segment = Environment.NewLine + "\t";
Using another would be wrong and could introduce errors that you won't see for years to come.
If you use \ r \ n because you are working with a specification that says βindividual segments with CRLF followed by a tabβ, you should definitely use:
internal const string segment = "\r\n\t";
Using another would be wrong.
This is what really bites people. Windows people write HTTP code that is simply used to use a new line of Windows between the headers between the headers and the body. Then it wraps to where the new line \ n is and it breaks because the HTTP credential \ r \ n no matter what system was used. The same thing happens and vice versa.
(Under a strict / permissive principle, it might also be a good idea to assume that other code there will continue to be wrong and take all the different forms of the new line there).
Jon hanna
source share