FUNDAMENTALS
OF
PROGRAMMING
USING
By:
NILDA N. DELA CRUZ, MIT
Course Instructor
Outline:
1. Arithmetic Operators
2. Assignment Operators
3. Comparison Operators
4. Logical Operators
C# Operators
❑ are used to perform operations on variables and values.
Arithmetic Operators
Arithmetic operators are used to perform common mathematical operations:
Operator Name Description Exa
mple
+ Addition Adds together two values x+y
- Subtraction Subtracts one value from another x-y
* Multiplication Multiplies two values x*y
/ Division Divides one value by another x/y
% Modulus Returns the division remainder x%y
++ Increment Increases the value of a variable by 1 x++
-- Decrement Decreases the value of a variable by 1 x--
Assignment Operators
Assignment operators are used to assign values to variables:
Operator Name Same As
= x=5 x=5
+= x += 3 x=x+3
-= x -= 3 x=x-3
*= x *= 3 x=x*3
/= x /= 3 x=x/3
%= x %= 3 x=x%3
Comparison Operators
Comparison operators are used to compare two values:
Note: The return value of a comparison is either True or False
Operator Name Example
== Equal to x == y
!= Not equal x != y
> Greater than x>y
< Less than x<y
>= Greater than or equal to x >= y
<= Less than or equal to x <= y
Logical Operators
Logical operators are used to determine the logic between variables and values:
Operator Name Description Example
&& Logical AND Returns True if both x < 5 && x < 10
statements are true
|| Logical OR Returns True if one of the x < 5 || x < 4
statements is true
! Logical NOT Reverse the result, returns !(x < 5 && x < 10)
False if the result is true