Skip to main content

Environment.NewLine can be used

In This Article

CodeRush Classic shows the Environment.NewLine can be used code issue if it finds the “\r\n” string value in your code.

#Fix

Convert the “\r\n” string value to an Environment.NewLine call.

#Purpose

Environment.NewLine can be used directs your attention to the “\r\n” string values, which can be converted to Environment.NewLine calls to improve your code readability and portability.

#Example

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

Fix:

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