Arithmetic Operators and Numerical Expressions

You have already seen numerous examples of how C# performs arithmetic calculations by evaluating arithmetic expressions, such as the following:

  • 100 * Constants.MassOfElectron

  • ((distance1 + distance2) / 2)

These examples give you a general idea of how a correct expression is put together and how it is evaluated. However, you can only create expressions that efficiently solve the computational problems of your particular program, if you know the different underlying building blocks of a C# expression and how these are combined to form valid expressions. The following sections are aimed at providing you with this knowledge.

Arithmetic operators (such as addition (+), subtraction (-), multiplication ( ...

Get C# Primer Plus now with O’Reilly online learning.

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