An expression essentially denotes a value. The simplest kinds of expressions are constants and variables. Expressions can be transformed and combined using operators. An operator takes one or more input operands to output a new expression.
Here is an example of a constant expression:
We can use the * operator to combine two operands (the literal expressions
12 * 30
Complex expressions can be built because an operand
may itself be an expression, such as the operand
in the following example:
1 + (12 * 30)
Operators in C# are classed as unary, binary, or ternary— depending on the number of operands they work on (one, two, or three). The binary operators always use infix notation, where the operator is placed between the two operands.
Primary expressions include expressions composed of operators that are intrinsic to the basic plumbing of the language. Here is an example:
This expression is composed of two primary expressions. The first expression performs a member-lookup (with the . operator), and the second expression performs a method call (with the () operator).
A void expression is an expression that has no value. For example:
A void expression—because it has no value—cannot be used as an operand to build more complex expressions:
1 + Console.WriteLine(1) // Compile-time error
An assignment expression uses the = operator to assign a variable ...