A value is assigned to a local variable, but either that variable is never read later on, or its value is always overwritten before being read. This means that the original assignment has no effect, and could indicate a logic error or incomplete code.

Ensure that you check the program logic carefully. If a value is really not needed, consider omitting the assignment. Be careful, though: if the right-hand side has a side effect (like performing a method call), it is important to keep this to preserve the overall behavior.

The following example shows six different types of assignments to local variables whose value is not read:

The revised example eliminates the unread assignments.

  • Wikipedia: Dead store.
  • MSDN, Code Analysis for Managed Code, CA1804: Remove unused locals.
  • Microsoft: What's new in C# 7 - Discards.