8.1. Arithmetic Operators

Although arithmetic operators are traditionally used on numeric data types, they can also be used in the context of other nonnumeric data types. The following discussion assumes that we are dealing with numeric data types. We discuss the meaning of these operators in nonnumeric contexts in Section 8.18.

The +, -, /, *, and % operators have the same meaning in C# as they have in Java. In the context of two numeric operands the +, -, /, *, and % operators add, subtract (the right-hand side [RHS] operand from the left-hand side [LHS] operand), divide (the LHS operand by the RHS), multiply the two operands, and calculate the remainder of dividing the LHS operand by the RHS. Listing 8.1 shows these operators in action.

Get .NET for Java Developers: Migrating to C# 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.