---
title: Remove Unused Variables
impact: MEDIUM
impactDescription: improves code maintainability and reduces clutter
tags: csharp, clean-code, maintainability
---

## Remove Unused Variables

Unused variables reduce code readability and may indicate logic errors.

**Incorrect:**

```csharp
public void CalculateTotal()
{
    int unused = 10; // C022: variable 'unused' is assigned but its value is never used
    var total = 100;
    Console.WriteLine($"Total: {total}");
}
```

**Correct:**

```csharp
public void CalculateTotal()
{
    var total = 100;
    Console.WriteLine($"Total: {total}");
}
```

**Tools:** Roslyn Analyzers, SonarQube (S1481)
