Binary Operators
This lesson takes a look at the binary operators in C# in detail using coding examples.
We'll cover the following...
We'll cover the following...
In the previous lesson you studied unary operators, in addition to those C# has binary operators as well that form expressions of two variables. The example below shows how to use the binary operators.
Binary Operators Example
Code Explanation
The example above shows several examples of binary operators. As you might expect, the results of
- addition (
+) - subtraction (
-) - multiplication (
*) - division (
/)
produce the expected mathematical results.
-
In the code the
resultvariable is a floating point type. -
We explicitly cast the integer variables
xandyto calculate a floating point value in line 25. -
There is also an example of the remainder(
%) operator.- It performs a division operation on two values and returns the remainder.
-
The last ...