Method Calls

Methods are the main way of performing operations. While method calls embody a type of expression, they’re often used without caring about the return value (if any). That’s a typical case of using an expression as a statement.

Side Effects Everywhere?

One concrete proof of this lies in the existence of the void type that can be used as the return type of a method. Clearly, calling such a method is useful only for the side effects it exposes, not for some value it returns:

Console.WriteLine("Hello World");

We’re lucky we have those side effects at our service. How would we print to the screen otherwise? The preceding code line actually is a statement formed out of an invocation expression, the sole difference being the occurrence ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.