Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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.
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;
}
}
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++;
}
}
}
}
.NET feedback
.NET is an open source project. Select a link to provide feedback: