1 DotNet
1 DotNet
Worksho
Discuss
se”
“Intellisen
2) Run the app by “Start” or F5 i th
feature w
r
3) Discuss the code statements. the traine
TASK # 4 – Noticing the Errors p
Worksho
o e s the
D eth od
dm
secon e any
hav ge ?
nta
adva
Integer types in C#
TASK # 17 – Integer values in C# Worksho
p
1) Declare few variables of the data types of your choice from
the list below. Initialize them with values. Print
•Used to
• do arithmetic calculations
• take decisions
• assign data to memory areas
Types of OPERATORS
•Arithmetic Operators
• Binary
• Unary
•Assignment Operators
•Relational Operators
•Logical Operators
Binary
Arithmetic
Operators
Binary
Arithmetic
Operators are
symbols used to
perform
mathematical
operations on
numbers.
Binary
Arithmetic
Operators
require two
operands to
function.
Operator Description Example Result
+ Addition x=2 4
x+2
- Subtraction x=2 3
5-x
* Multiplication x=4 20
x*5
/ Division 15/5 3
5/2 2.5
% Modulus 5%2 1
(division 10%8 2
remainder) 10%2 0
TASK # 18 - Learning about Arithmetic Operators Workshop
Example 1 :
int x ;
x = -3 ;
Negation Operator (-)
Example 2 :
int new, old = 5 ;
new = -old ;
Increment (++) and Decrement (--)
Example 1 :
stdNo = stdNo + 1 ; //can also be
written as
stdNo++ ; //Or
++stdNo ;
//Same applicable for decrement
Pre-fixing and Post-fixing Operators
//Prefixing operator
++StdNo ;
--StdNo ;
//PostFixing Operator
StdNo++ ;
StdNo-- ;
Pre-fixing
and
Post-fixing
Operators
In case of Pre-Fixing Operator, the
increment or decrement takes place
first, followed by the Operand value
being used.
Example 1 :
a = 10 ; b = 5 ;
c = a * ++b ;
//C will be 60
In case of Post fixing Operator, the
increment or decrement takes place
later after the Operand is used.
Example 1 :
a = 10 ; b = 5 ;
c = a * b++ ;
//C will be 50 and b will be 6
TASK # 19- Learning about Pre-fixing and post-fixing operators
1. Type the following code. Workshop
2. Discuss the result
WORD
Assignment
Operator
Used to assign
values to
variables.
Used with any valid C expression.
•Syntax is :
•variable name = expression ;
•Here, the expression can be a simple
constant or a complex expression
Assignment Operator
Examples :
var = 1 // simple constant
var = another_var // assigning a
variable
var = value1 + value2 + var1 / var2 //
arithmetic expression
Negation Operator (-)
Example 2 :
int new, old = 5 ;
new = -old ;
Increment (++) and Decrement (--)
Example 1 :
stdNo = stdNo + 1 ; //can also be
written as
stdNo++ ; //Or
++stdNo ;
//Same applicable for decrement
TASK # 20- Learning about Assignment Operators Worksho
p
Operator Meaning
== Equal to
> Greater Than
< Less Than
!= Not Equal to
>= Greater Than or Equal to
<= Less than or Equal to
TASK # 21- Learning about Relational Operator Worksho
p
Type the program. Discuss
the
What does )
== b
express (a
return ?
TASK # 22- Learning about Relational Operator Worksho
p
Type the program. Discuss
the
What does
!=b)
express (a
return ?
TASK # 23 - Learning about Relational Operator Worksho
p
-- ITERATION
CONSTRUCTS --
A loop is a mechanism that
enables you to execute the
same sequence of statements
repeatedly until a condition is
met.
The statements inside a loop
are sometimes called
ITERATION statements.
do
{
statement 1;
statement n ;
}while (test condition)
TASK # 33 - do..while Workshop
Condition Checking
Incrementing or Decrementing of a
variable for iteration
Syntax of FOR loop
Part 1 Part 2
(Initialization) (condition) Part 3
Declaration and (iteration
Initialization expression)
allowed together (No semi-colon)
TASK # 34 - For….Loop Workshop