Gendarme.Rules.Performance.RemoveUnusedLocalVariablesRule Class
This rule looks for unused local variables inside methods. This can leads to larger code (IL) size and longer JIT time, but note that some optimizing compilers can remove the locals so they won't be reported even if you can still see them in the source code. This could also be a typo in the source were a value is assigned to the wrong variable.

See Also: RemoveUnusedLocalVariablesRule Members

Syntax

[Gendarme.Framework.FxCopCompatibility("Microsoft.Performance", "CA1804:RemoveUnusedLocals")]
[Gendarme.Framework.Problem("This methods contains unused local variables.")]
[Gendarme.Framework.Solution("Remove unused variables to reduce the method's size.")]
public class RemoveUnusedLocalVariablesRule : Gendarme.Framework.Rule, Gendarme.Framework.IMethodRule

Remarks

This rule is available since Gendarme 2.0

Example

Bad example:

Example

            bool DualCheck ()
            {
            	bool b1 = true;
            	bool b2 = CheckDetails ();
            	if (b2) {
            		// typo: a find-replace changed b1 into b2
            		b2 = CheckMoreDetails ();
            	}
            	return b2 && b2;
            }
            

Example

Good example:

Example

            bool DualCheck ()
            {
            	bool b1 = true;
            	bool b2 = CheckDetails ();
            	if (b2) {
            		b1 = CheckMoreDetails ();
            	}
            	return b1 && b2;
            }
            

Requirements

Namespace: Gendarme.Rules.Performance
Assembly: Gendarme.Rules.Performance (in Gendarme.Rules.Performance.dll)
Assembly Versions: 2.8.0.0