C# Error CS0201 – Only assignment, call, increment, decrement, and new object expressions can be used as a statement

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

C# Error CS0201 - Only assignment, call, increment, decrement, and new object expressions can be used as a statement

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;
        }
    }

}

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...