4.0: Operators
In this module we'll discuss the various operators in C#.
File Location
Right click on the solution you made in the first module, go to Add > New Project.
Select Console App (.NET Framework).
Name it
04_Operators
.Write your code for this module within
Program.cs
of that project.
Math Operators
The first thing to know is that C# uses common math using the operators + - * /
. Ones you should already know. For example, add the following code:
There is another common operator called the modulus
operator - %
. This is not a percentage, but the remainder when two numbers are divided. For example:
%
can be used to easily determine if a number is even or odd, even numbers % 2 are always 0.
To learn the modulus, the best thing to do is problems in your head. What is the result of the following:
In your Program.cs
check on the answers above, and then practice using the different operators by logging a few things to the console, especially the modulus operator.
Last updated