Emerging Technologies (IT-3302)
Week 02
Usman Akbar
[email protected]
FB Group - SuperiorUniversity2016
Lecture Content
Last lecture review
C# Operators
ET Home Tasks
Questions Session
References
EMERGING TECHNOLOGIES ( USMAN AKBAR ) 2
Review
.NET Framework
.NET Core / XAMARIN
CLS ….?
CLR ….?
EMERGING TECHNOLOGIES ( USMAN AKBAR ) 3
C# - Operators
An operator is a symbol that tells the compiler to perform specific
mathematical or logical manipulations. C# has rich set of built-in operators
and provides the following type of operators
Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
EMERGING TECHNOLOGIES ( USMAN AKBAR ) 4
Arithmetic Operators
Following table shows all the arithmetic operators supported by C#
Assume variable A holds 10 and variable B holds 20 then
Operato
Description Example
r
+ Adds two operands A + B = 30
- Subtracts second operand from the first A - B = -10
* Multiplies both operands A * B = 200
/ Divides numerator by de-numerator B/A=2
Modulus Operator and remainder of
% B%A=0
after an integer division
Increment operator increases integer
++ A++ = 11
value by one
Decrement operator decreases integer
-- A-- = 9
value by one
EMERGING TECHNOLOGIES ( USMAN AKBAR ) 5
Relational Operators
Following table shows all the relational operators supported by C#. Assume variable A holds 10
and variable B holds 20,
Operator Description Example
Checks if the values of two operands are equal or not, if
== yes then condition becomes true.
(A == B) is not true.
Checks if the values of two operands are equal or not, if
!= values are not equal then condition becomes true.
(A != B) is true.
Checks if the value of left operand is greater than the
> value of right operand, if yes then condition becomes (A > B) is not true.
true.
Checks if the value of left operand is less than the value
< of right operand, if yes then condition becomes true.
(A < B) is true.
Checks if the value of left operand is greater than or
>= equal to the value of right operand, if yes then condition (A >= B) is not true.
becomes true.
Checks if the value of left operand is less than or equal
<= to the value of right operand, if yes then condition
EMERGING TECHNOLOGIES ( USMAN AKBAR )
(A <= B) is true.
6
becomes true.
Logical Operators
Following table shows all the logical operators supported by C#. Assume
variable A holds Boolean value true and variable B holds Boolean value false,
then
Operator Description Example
Called Logical AND operator. If both the operands
&& are non zero then condition becomes true.
(A && B) is false.
Called Logical OR Operator. If any of the two
|| operands is non zero then condition becomes (A || B) is true.
true.
Called Logical NOT Operator. Use to reverses the
! logical state of its operand. If a condition is true !(A && B) is true.
then Logical NOT operator will make false.
EMERGING TECHNOLOGIES ( USMAN AKBAR ) 7
There are following assignment operators supported by C#
Operator Description Example
= Simple assignment operator, Assigns values from right C = A + B assigns value of A +
side operands to left side operand B into C
+= Add AND assignment operator, It adds right operand to C += A is equivalent to C = C +
the left operand and assign the result to left operand A
-= Subtract AND assignment operator, It subtracts right
C -= A is equivalent to C = C -
operand from the left operand and assign the result to left
A
operand
*= Multiply AND assignment operator, It multiplies right
C *= A is equivalent to C = C *
operand with the left operand and assign the result to left
A
operand
/= Divide AND assignment operator, It divides left operand
C /= A is equivalent to C = C /
with the right operand and assign the result to left
A
operand
EMERGING TECHNOLOGIES ( USMAN AKBAR ) 8
Class Task
Write a C# console program to make mathematical
expressions to perform all Arithmetic Operators.
EMERGING TECHNOLOGIES ( USMAN AKBAR ) 9
Question
Questions….?
References
C# 6 for Programmers ( Chapter 03 )
https://www.tutorialspoint.com/csharp
https://www.visualstudio.com
Social Community Help ….!
https://code.msdn.microsoft.com/
https://www.codeproject.com/
http://stackoverflow.com/
EMERGING TECHNOLOGIES ( USMAN AKBAR ) 11