Renas R. Rekany Object-Oriented-Programming
1
Programming Language with
C_Sharp
Object-Oriented-Programming
Renas R. Rekany
Renas R. Rekany Object-Oriented-Programming
2
Introduction to C#
Comments
1- Single Line ( // )
Ex: Int x,y,s;
S=x+y; // the sum of x,y
2- Multiple Line (/* */)
Ex: Int x,y,s;
S=x+y; /* the sum
of x,y */
Arithmetic Operations
Operations Arithmetic in c#
Addition +
Subtraction -
Multiplication *
Division /
Modulus %
Precedence of Arithmetic Operations
( )
*,/,%
+,-
<,<=,>,>=
==,!=
=
Renas R. Rekany Object-Oriented-Programming
3
Ex z = p * r ٪ q + w / x – y
(6) (1) (2) (4) (3) (5)
Ex y = a * x * x + b * x + c
(6) (1) (2) (4) (3) (5)
Equality and Relational Operator
Standard Operator C# Operator Ex in C#
= == If (x==y)
≠ != If (x!=y)
> > If (x>y)
≥ >= If (x>=y)
< < If (x<y)
≤ <= If (x<=y)
Assignment operations
Int c;
c=c+3; c+=3;
c ‫ــ‬ =3;
c*=3;
c/=3;
(var) = (var) (operator) (expiration)
If true
(var) (operator) = (expiration)
Renas R. Rekany Object-Oriented-Programming
4
Increment and Decrement Operator
Operator Call Ex
++ Pre Increment ++ a
++ Post Increment a++
-- Pre Decrement --b
-- Post Decrement b--
Ex : int c=5;
MessageBox.Show(c); //5
MessageBox.Show(c++); // 5
MessageBox.Show(++c); // 6
C=5;
MessageBox.Show(c); // 5
MessageBox.Show(++c); // 6
MessageBox.Show(c); // 6
Renas R. Rekany Object-Oriented-Programming
5
Loop Statement In C#
For While Do-While
For (int ; condition ; increment)
Ex :
For (int i=0;i<=5;i++)
Textbox1.text=textbox1.text+i;
0
1
2
3
4
5
While (condition)
State;
Ex :
Int i=0;
While (i<=5)
{
Textbox1.text=textbox1.text+ i;
i i =i+1;
}
0
1
2
3
4
5
Do
{ State}
While (condition);
Ex :
int i=0;
do
{
Textbox1.text=textbox1.text+ i;
i++;
} While (i<=5);
0
1
2
3
4
5

C# p2

  • 1.
    Renas R. RekanyObject-Oriented-Programming 1 Programming Language with C_Sharp Object-Oriented-Programming Renas R. Rekany
  • 2.
    Renas R. RekanyObject-Oriented-Programming 2 Introduction to C# Comments 1- Single Line ( // ) Ex: Int x,y,s; S=x+y; // the sum of x,y 2- Multiple Line (/* */) Ex: Int x,y,s; S=x+y; /* the sum of x,y */ Arithmetic Operations Operations Arithmetic in c# Addition + Subtraction - Multiplication * Division / Modulus % Precedence of Arithmetic Operations ( ) *,/,% +,- <,<=,>,>= ==,!= =
  • 3.
    Renas R. RekanyObject-Oriented-Programming 3 Ex z = p * r ٪ q + w / x – y (6) (1) (2) (4) (3) (5) Ex y = a * x * x + b * x + c (6) (1) (2) (4) (3) (5) Equality and Relational Operator Standard Operator C# Operator Ex in C# = == If (x==y) ≠ != If (x!=y) > > If (x>y) ≥ >= If (x>=y) < < If (x<y) ≤ <= If (x<=y) Assignment operations Int c; c=c+3; c+=3; c ‫ــ‬ =3; c*=3; c/=3; (var) = (var) (operator) (expiration) If true (var) (operator) = (expiration)
  • 4.
    Renas R. RekanyObject-Oriented-Programming 4 Increment and Decrement Operator Operator Call Ex ++ Pre Increment ++ a ++ Post Increment a++ -- Pre Decrement --b -- Post Decrement b-- Ex : int c=5; MessageBox.Show(c); //5 MessageBox.Show(c++); // 5 MessageBox.Show(++c); // 6 C=5; MessageBox.Show(c); // 5 MessageBox.Show(++c); // 6 MessageBox.Show(c); // 6
  • 5.
    Renas R. RekanyObject-Oriented-Programming 5 Loop Statement In C# For While Do-While For (int ; condition ; increment) Ex : For (int i=0;i<=5;i++) Textbox1.text=textbox1.text+i; 0 1 2 3 4 5 While (condition) State; Ex : Int i=0; While (i<=5) { Textbox1.text=textbox1.text+ i; i i =i+1; } 0 1 2 3 4 5 Do { State} While (condition); Ex : int i=0; do { Textbox1.text=textbox1.text+ i; i++; } While (i<=5); 0 1 2 3 4 5