Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

Q3W1

Operators
What is An Operator On C#
 What are the roles of Operators on C#?
 What are the Different type of Operators?
What is an operator?
 An operator is a symbol used to tell the program that a calculation is to be
performed.
 Operators are combined with operands to produce new values or information.
 In C# programming aside from arithmetic operators such as +,-,* and/, some of the
operators are used @, <, >, %. &, and many more.
Here are the different types
of operators:
 Assignment – Used to assign a value to a variable

 Arithmetic – Used to process arithmetic computations

 Relational/Comparison – Used to compare two or more literals and/or


variables
 Logical – Used to identify the result of a Boolean data type

 Binary – Used to perform an operation on the binary representation of


numeric data.
Assignment Operators
Operator Symbol
Assignment Operators are used to assign a value to a variable
Assignment =
Syntax:
Add AND +=
Variable = Value Subtract AND -=
A + A = ___
Example 5+5 = ___ Multiply AND *=
A= 5
Divide AND /=
This Statement assigns the value of 5 to variable A. An Assignment operator Modulus AND %=
Assigns an initial Value of the Variable and is replaced by another value
during program execution.
 Assignment operators can also be entered in short forms. The expression a=a+1 is similar to a+=1.

 Answer 6?

 Assignment by addition (+=), Assignment by difference (-=), assignment by product (*=), and
assignment by quotient (/=) are called Shorthand assignment operators.

 In the example below, Variable x is assigned with the value of 6, while hellostring variable is
assigned with the value of Hello String, and lastly, Variable y is assigned with the value of X (which is
6). Assigning a variable to another variable only means that the value of y is the same as the value
of X.

 Example
Int x = 6;

 String helloString = “Hello String”;

 Int y = x;
Arithmetic Operators Operator Symbol

Addition +
Modulus is the operation that gives the remainder of a division of two
Subtraction -
values.
Increment is the process of increasing by a specific amount, or the
Multiplication *
amount by which something increases.
Decrement To subtract a number from another number. Decrementing a Division /
counter means to subtract 1 or some other number from its current value.
Modulus %
Loop statement
Increment ++
x5
-- Decrement --
A = 5 --
4
3
2
1
0
SCAN for more Info
 https://www.youtube.com/watch?v=SvD3m4apJZ4 Operators

 https://www.youtube.com/watch?v=49WGI5wN2Js Shorthand Operators


 Q3 W1 Activity

 Assignment and Arithmetic Operators


A. Convert the following statements to their correct expressions:
 1. add the values of b and c, then multiply the sum by the value of a.

 SAMPLE: b + c (*a)

 2. Add the Values of b and c and multiply the sum by the value of a. then assign the result.

 3. Divide the value of b by the value of C.

 4. Decrement the Value of a or decrease the value of a by 1.

 5. Get the remainders of 8 and 2, then store the remainder to A.

You might also like