What Are Expressions?

A key ingredient to every programming language’s expressiveness stems from the use of expressions. In fact, some languages are (almost) entirely based on this concept. C# isn’t that extreme though. But what are expressions? According to the language specification:

An expression is a sequence of operators and operands.

First, it’s important to notice expressions typically denote a value by means of some computation. This is achieved by having operators operate on one or more operands, carrying out the desired computation. Because expressions represent a value, they also do have a type.

Examples of operators include arithmetic operators, comparison operators, and so on. Operands can be variables, literals, or even other expressions. ...

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.