The requested page is not available for the requested platform. You are viewing the content for Default platform.

Can inline temporary variable

CodeRush Classic shows the Can inline temporary variable code issue if an expression assigned to a variable is used only once.

Fix

Inline the variable value and delete the variable.

Purpose

Helps you to find and remove redundant variables to improve the readability of your code.

Example

public void WriteStringToFile(string data)
{
    string fileName = "MyText.txt";
    StreamWriter sWriter = File.CreateText(fileName);
    sWriter.Write(data);
    sWriter.Dispose();
}

Fix:

public void WriteStringToFile(string data)
{
    StreamWriter sWriter = File.CreateText("MyText.txt");
    sWriter.Write(data);
    sWriter.Dispose();
}