An expression statement evaluates a given expression. The value computed by the expression, if any, is discarded. Not all expressions are permitted as statements. In particular, expressions such as x
+
y
and x
==
1
that have no side effects, but merely compute a value (which will be discarded), are not permitted as statements.
The example
using System; class Test { static int F() { Console.WriteLine("Test.F"); return 0; } static void Main() { F(); } }
shows an expression statement. The call to the function F
made from Main
constitutes an expression statement. The value that F
returns is simply discarded.