Total .NET Analyzer Rule Documentation  

UnusedAssignment Rule

The assignment is not being used.

Remarks

Assignments to value types are only necessary when they affect the outcome or functionality of the application. Assigning values to types unnecessarily can detrimentally affect performance, and make code difficult to understand and maintain.

In the following example, the variable "result" is assigned a value that is never used:


' VB
Function AddNums(ByVal num1 As Double, ByVal num2 As Double) As Double
Dim result As Double = num1 + num2
Return num1 + num2
End Function

//C#
double AddNums(double num1, double num2)
{
double result = num1 + num2;
return num1 + num2;
}

Resolution

Review unused assignments to determine whether they represent a coding error, or whether they can be removed.

See Also