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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.