Skip to content

unused-assignment

C#cleanupno fixdefault: offcsharp/roslynator

Reports a value stored in a local variable that no path reads before it is overwritten or the variable goes out of scope (a dead store). Variables that are captured or whose address is taken are not checked. A variable that is never read at all is unused-variable’s.

A dead store is a computation whose result is thrown away. It is often the sign of a bug: the value was meant to be used and a later line forgot it, or an earlier branch was changed.

To fix, use the value, or delete the assignment (keep the right side if it has a side effect).

Reported
class A { int F() { int n = 0; n = G(); return n; } int H() { int m = 0; m = 1; m = G(); return m; } int G() => 1; }
csharp:
lint:
rules:
unused-assignment: warn # off (default), warn, error

Enabled by the presets: csharp/roslynator.

Suppress one line with sudsy-disable-next-line unused-assignment in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
Roslynator RCS1179 full
Roslynator RCS1212 full