C#

C#

Made by DeepSource

Result of an assignment expression is unused CS-W1082

Bug risk
Critical
Autofix

The result of an expression is assigned to a variable. However, the very subsequent statement is an assignment expression that does not use this previously computed value. This succeeding statement ends up overwriting the previously assigned value. Either this was not meant to happen or the previous assignment expression is actually useless and can be removed.

Bad Practice

i = 1;
i = j * 2;

Recommended

// Scenario 1:
i = 1;
i = i + j; // Reuse value from previous assignment expression

// Scenario 2:
i = i + j; // Previous assignment `i = 1` is removed as it is useless.