Why does 'only assignment, call, increment, decrement, await, and new object expressions can be used as a statement' error occur in c#?

This error appears when you use an expression that doesn't do anything meaningful on its own.

Example:


int x;
x + 1;

Solution:


int x;
x = x + 1;
Always ensure that expressions in your code are doing something useful, such as being assigned to a variable.

Beginner's Guide to C#