Dead stores refer to assignments made to local variables that are subsequently never used or immediately overwritten. Such assignments are
unnecessary and don’t contribute to the functionality or clarity of the code. They may even negatively impact performance. Removing them enhances code
cleanliness and readability. Even if the unnecessary operations do not do any harm in terms of the program’s correctness, they are - at best - a waste
of computing resources.
Exceptions
No issue is reported when
- the analyzed method body contains
try
blocks
- a lambda expression captures the local variable
- the variable is unused (case covered by Rule S1481)
- it’s an initialization to
-1
, 0
, 1
, null
, true
, false
,
""
or string.Empty