Skip to main content

CRR0049 - Environment.NewLine can be used

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

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;
}

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

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;
}

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