Compiler Error CS0201
Only assignment, call, increment, decrement, and new object expressions can be used as a statement
The compiler generates an error when it encounters an invalid statement. An invalid statement is any line or series of lines ending in a semicolon that does not represent an assignment (=), method call (), new, -- or ++ operation. For more information, see Statements and Operators and expressions.
Example 1
The following sample generates CS0201 because 2 * 3 is an expression, not a statement. To make the code compile, try assigning the value of the expression to a variable.
// CS0201.cs
public class MainClass
{
public static void Main()
{
2 * 3; // CS0201
// Try the following line instead.
// int i = 2 * 3;
}
}
Example 2
The following sample generates CS0201 because checked by itself is not a statement, even though it is parameterized by an increment operation.
// CS0201_b.cs
// compile with: /target:library
public class MyList<T>
{
public void Add(T x)
{
int i = 0;
if ( (object)x == null)
{
checked(i++); // CS0201
// OK
checked {
i++;
}
}
}
}
See also
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for