C# Compiler Error
CS0201 – Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Reason for the Error
You will receive this error when you have an invalid statement in your C# code. For example, you have an statement that end with a semicolon and doesnot have =, () , new — or ++ operation in it.
For example, try to compile the below code snippet.
namespace DeveloperPubNamespace { class Program { static void Main(string[] args) { 8 * 2; } } }
This will result with the error code CS0201 as you have used 8 * 2 in a statement but doesnot contain any assignment operation.
Error CS0201 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement ConsoleApp3 C:\Users\SenthilBalu\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 7 Active
Solution
To fix the error code CS0201, you will need to ensure that the statement is valid. You can fix the above code by using the assignment operation.
namespace DeveloperPubNamespace { class Program { static void Main(string[] args) { int i = 8 * 2; } } }