Back to Devexpress

CRR0049 - Environment.NewLine can be used

coderushforroslyn-401175-static-code-analysis-analyzers-library-crr0049-environment-new-line-can-be-used.md

latest1.3 KB
Original Source

CRR0049 - Environment.NewLine can be used

  • Feb 28, 2025

This analyzer identifies “\r\n” string values which can be converted to Environment.NewLine to improve code readability and portability.

csharp
public string MakeText(params string[] data) {
    string result = data[0];
    for (int i = 1; i < data.Length; i++)
        result += "\r\n" + data[i];
    return result;
}
vb
Dim hello As String = "Hello World !!!" & "\r\n"

To fix the issue, convert the “\r\n” string value to Environment.NewLine :

csharp
public string MakeText(params string[] data) {
    string result = data[0];
    for (int i = 1; i < data.Length; i++)
        result += Environment.NewLine + data[i];
    return result;
}
vb
Dim hello As String = "Hello World !!!" & Environment.NewLine

Call the Use Environment.NewLine refactoring to replace the “\r\n” string with an Environment.NewLine property value.

See Also

Suppress Analyzers