Use const internally in corelib for Environment.NewLine by stephentoub · Pull Request #27013 · dotnet/coreclr (original) (raw)

Anywhere Environment.NewLine was being used internal to corelib, instead changes it to use an internal Environment.NewLineConst, which is just a const string. The main benefit of that is places where it's then concatenated with another const allows the C# compiler to do the concat at compile time rather than at run time.

Where I was already touching the code, fixed a few places where additional strings were being created unnecessarily, e.g. s += a; s += b; will do two string.Concat calls each with two arguments, whereas s += a + b; will do just one string.Concat call with three arguments.