Quick Answer

Fix expression statements.

Understanding the Issue

Occurs when using expressions as statements without side effects. Only assignments, method calls, and object creation are valid standalone statements.

The Problem

This code demonstrates the issue:

Csharp Error
public void Test() {
    1 + 1; // Error
}

The Solution

Here's the corrected code:

Csharp Fixed
// Valid statements:
int x = 1 + 1; // Assignment
Console.WriteLine(x); // Method call
new object(); // Object creation
x++; // Increment

// Expression with side effect
_ = Task.Run(() => {}); // Discard pattern

// Full property access
public int Value { get; set; }
Value = 5; // Valid assignment

Key Takeaways

Ensure statements perform meaningful work.