• Home   /  
  • Archive by category "1"

Only Assignment Call Increment Decrement And New Object Expressions

View Issue Details [ Jump to Notes ][ Issue History ][ Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0003874opensim[REGION] Scripting Enginepublic2009-07-08 14:312010-01-27 08:24
Assigned Tojustincc 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0003874: CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement.
DescriptionAs already reported in issue 0003042, there is a problem with lone assignments.
The code below still does not compile. Unfortunately, the LSLPlus plugins generates statements with parentheses, like for ((i = 0); (i < 10); (++i))
which don't compile on Mono/C#

Revision 9807 of of /trunk/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs did not fix the problem.
Additional Informationdefault
        integer i = (2 + 3); // OK

        for ((i = 0); (i < 10); (++i)) { // Error compiling script: Line (7,14): Error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
            llSay(0, (string) i);
        for (i = 0; i < 10; ++i) { // OK
            llSay(0, (string) i);
TagsNo tags attached.
Git Revision or version number
Run ModeStandalone (1 Region)
Physics EngineODE
EnvironmentMono / OSX
Mono Version2.4
Attached Files


2009-11-20 10:43

Should be fixed in r8f0db68424af as of today in git master. Please test

 Issue History
Date Modified Username Field Change
2009-07-08 14:31 Nathiel New Issue
2009-07-08 14:31 Nathiel SVN Revision => 9807
2009-07-08 14:31 Nathiel Run Mode => Standalone (1 Region)
2009-07-08 14:31 Nathiel Physics Engine => ODE
2009-07-08 14:31 Nathiel Environment => Mono / OSX
2009-07-08 14:31 Nathiel Mono Version => 2.4
2009-11-20 10:43 justincc Status new => resolved
2009-11-20 10:43 justincc Resolution open => fixed
2009-11-20 10:43 justincc Assigned To => justincc
2009-11-20 10:43 justincc Note Added: 0014202
2010-01-27 08:24 justincc Status resolved => closed
 Issue History

Copyright © 2000 - 2012 MantisBT Group

Published on 26 March 2009 by Michiel van Oosterhout4 min read

When I first learned how to program I was using a programming language (Java) without really understanding the basic grammar. I was taught the principles of Object Oriented programming, the difference between a class and an object, value types, reference types and boxing, namespaces and packages and other high-level aspects of programming. Of course the low-level concerns like control flow, variables, assignment and method calls were also taught, but I don’t remember ever getting down to the absolute basics of the language: statements and expressions. And I have never missed it, I could write software without knowing about it. But there is value in learning the distinction, it will help you write more concise code.

The difference between expressions and statements

Expressions and statements are the building blocks of your software. But what is the difference between these two constructs? Simply put, an expression is a construct that evaluates to a value, a statement is a unit of execution. Let’s illustrate:

Console.WriteLine(); int ;

The whole first line is a statement and so is the second line, they are both a unit of execution. The highlighted parts are expressions, the first expression evaluates to the value of type , the second expression evaluates to the value of type . Expressions that evaluate to the same type of value can be combined to create compound expressions, so this is a valid expression: . If you put that on a line and try to compile your program, the compiler will complain about a missing semicolon (compiler error CS1002):

; expected

If you add the semicolon at the end of the expression and compile, the compiler will still complain (compiler error CS0201):

Only assignment, call, increment, decrement, and new object expressions can be used as a statement

So expressions can be used as statements simply by putting a semicolon at the end of it, but this is only valid for certain types of expressions. According to MSDN is a meaningless statement! The meaningful statements that the compiler does accept are called expression statements (yes, confusing). Then there are declaration statements and empty statements:

To complete our understanding, block statements are collections of statements inside balanced braces. They can be used anywhere a single statement can be used.

So what?

So far, it is all theory, and no practice. Like I said, it’s possible to program in C# without knowing exactly the difference between expressions and statements. But have you ever wondered about the difference between the conditional operator and the if-else construction? The conditional operator is an expression (it evaluates to a value) whereas the if-else construction is a statement (a control flow statement to be precise, the last type of statement). This means that we can use the conditional operator anywhere we can use expressions, for instance as the parameter to a method:


You obviously can’t do that with an if-else statement. You knew this, but you may not have known exactly why. Now that you do, you can start using expressions more consciously, like in the following example where we initialize a collection to prevent a null reference exception when accessing the property:

We use the null-coalescing operator to test the value of the private field for null. This operator will return the left-hand operand if it is not null, and the right-hand operand otherwise. For the right-hand operand we use an expression to initialize the private field. Since it is an expression it has a value. This value becomes the right-hand operator and is thus the result of the operator and is returned (and thus becomes the parameter value for the method). We can use the operator in the previous example as well:


In this post I explained the difference between expressions and statements. Expressions have a value, statements are a unit of execution. We have seen that when you understand the value of expressions, you can start using them more consciously to write more elegant and concise code.


One thought on “Only Assignment Call Increment Decrement And New Object Expressions

Leave a comment

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *