You are on page 1of 165

#C

9362/9355/ 01

' " , - " -


) (2002" . " ,

: , ,


#C
" :

-' " .
, , , ,
, " -' "
,

2 C#

3/ C#

15

24

48

65

86

104

117

10 ,

127

11 Main -

138

' .NET -
' ASCII
' XML
' Debugger
'
'


,
.' ,
' .
' , ,
' , ,
.
.
. , ,
. ,
, .
.
.
. "
".
:
.1 , .
.2 , .
.3 .
.4 , .
.5 ,
' .

!
Visual Studio Microsoft
.Net 2005

' "

1
:


.NET -
.NET -
-


-
) .(Wikipedia
. ,
. ,
" "
. ,
.
,
. ,
. ) Compiler( .
.


) Compilation/( ) Compiler-(
"" . , Compiler.
Machine Language .Native Code
Compiler - ,
,EXE . ,
) (Windows .
exe ) (double click
.
) (Design time .
) (Run Time , .

' "

.NET -
) .NET - (dot net
. ) ,(C\C++ EXE - Compiler-
C# " EXE" . ) (EXE
C# Microsoft ) MSIL
.(Intermediate Language
MSIL .
,CLR (Common Language Runtime) -
.(Just In Time Compiler) JIT Compiler
,Cross Platform
) (.
.NET - C# ,MSIL
,.NET Cross
.Language
C#

VB
.NET

EXE - MSIL

JIT Compiler

-
.NET -

.NET -
,.NET - EXE -
, CLR - .
CLR - .NET Framework -
) .NET Framework - (CLR - :
.(http://www.microsoft.com) Microsoft
.(Windows Update) Windows
) Windows Vista (.

' "

-
,C# - - .
- , Compiler - . Compiler-
, ) (Syntax ,
) ( . Compiler-
) ( ,
, .
" " "."Compilation Error
, Compiler- , )(.
,
. .
" " "."Compilation Warning


) - (Algorithm .
:
. :
.1 .
.2 .
.3 .
.4 .
.5 .
.6 ...
:
2) 2 (5 :
,2*2*2*2*2 .
5

-
.
:
3 - ""
. .
,
. ,
.
) , '(.

' "

:
) 3 - ( 2
:
.1 3*3*3' .
, .
.2 , ,
. 3 -
, .
: ,
. , .

' "

2 C# -
:
Visual Studio .NET
C# -


C# -
) Syntax( C#

C# ) text ( .CS
C# - , Notepad - ,Windows
.(VS.NET) Visual Studio.NET ,Microsoft
, Visual Studio .NET
.
Microsoft Visual Studio : ,Microsoft
. 2005 Microsoft
.Visual C# Express ,Visual Studio Visual C# Express -
, 2006 Microsoft
, .
:
.Visual Studio .NET .Visual C# Express -
,
.Visual C# Express

Visual Studio.NET
, ,
.Visual Studio .NET :
Start -> All Programs -> Microsoft Visual Studio 2005 -> Microsoft Visual
Studio 2005
: ,Visual C# Express
:
Start -> All Programs -> Microsoft Visual C# 2005 Express Edition
, .
) ,(Recent Projects ) (MSDN: Visual Studio
).(Getting Started

' "

Visual Studio .NET 2005


, .
" File New Project .Ctrl+Shift+N
Create Project
. , :

"New Project" -

' "

"New Project" -
:
.1 ) Project Types - ( .Visual C# -
.2 ) Templates - ( .Console Application -
.3 - Name ) .(MyFirstApplication
.4 - Location ) .(Desktop -
.5 Create directory for solution .
: ,Visual C# Express New Project - ",
) .(Project Types ,
, 2 3- . ,Visual Studio .NET -
, .
OK :

, .
,
.C#

' "

C#
C# - :
)static void Main(string[] args
.Main -
;using System
;using System.Collections.Generic
;using System.Text
namespace MyFirstApplication
{
class Program
{
)static void Main(string[] args
{
. // .
}
}
}

: ,
.
, , Main -
:
)static void Main(string[] args
{
//
}

' "

.
.sln
) .(Visual Studio.NET
, .
) Solution Explorer -
,(View ) CS" .(Program.CS
2 .bin, obj
, .
Visual Studio.NET -
.
- bin ,debug
EXE - . exe -
.

: ,Visual C# Express - exe - Release


.

- Solution Explorer - .
' "

10


, .
Ctrl+Shift+B Build Solution
.Build ,EXE - .MSIL
: ,Visual C# Express - F6
Build Solution .Build
, .
:
.1 .Visual Studio.NET -
Ctrl+F5 Start Without Debugging
.Debug

Debug -> Start Without Debugging


.2 exe - . ,
.bin\debug
: .Visual Studio .NET -
,Visual C# Express exe - .Release

' "

11

! " .
) Visual Studio.NET - (1 ,
. ) exe -
,(2 ,
.

C# -
:Main -
;)"Console.WriteLine("This is my first application in c#
:
)static void Main(string[] args
{
;)"Console.WriteLine("This is my first application in c#
}

) ,(Ctrl+Shift+B ) .(Ctrl+F5
, .:

, " .
, , :
Press any key to continue
EXE - ,
. ,
) ( , , .

.Visual Studio .NET

' "

12

) Syntax( C#
C# - - );( .:
;)"Console.WriteLine("This is my first application in c#

. , .
,
- . , .
, C#
) ,(Case Sensitive Upper Case .Lower Case ,
) L( :
;)"Console.Writeline("This is my first application in c#


- "
.
, . ,
.
:
.
2 :
.1 ) (
) .(// 2 .
.2 )* (/ ) .(*/
.

' "

13

:
)static void Main(string[] args
{
)( Console.WriteLine //.
Console.WriteLine("This is my first application in
;)"c#
*/
*
*
*.
*/
}
- )( ,
, , . ,
.Tab - ,
.Shift+Tab
: . ,
, .

:
.1
.2
.3
.4
.5

.
2 - .
".
- , .
.

' "

14

3/ C# -
:

Text Formatting
Numeric Formatting


2 )( :

;)" - Console.Write("Text to print . ,


:
;)"Console.Write("This is my first line.
;)"Console.Write("This is my second line.

:
This is my first line.This is my second line.

;)" - Console.WriteLine("Text to print


.:
;)"Console.WriteLine("This is my first line.
;)"Console.WriteLine("This is my second line.

:
This is my first line.
This is my second line.
.
, ,
. ,
.

Text Formatting
)( Console.Write Console.WriteLine() - ," ," .
, ,
.Markers :
, .
, .

' "

15

:
Console.WriteLine("The Sum of {0} and {1} is {2}.", 12,
;)23, 12 + 23
:
The Sum of 12 and 23 is 35
} {0 ,12 } {1 23 } {2
.12+23
, ) }{2} ,{1} ,{0
'( , .
, {0} , ,12 } {1
23 } {2 .12+23
, , } {1
}:{0
Console.WriteLine("The Sum of {1} and {0} is {2}.", 12,
;)23, 12 + 23
:
The sum of 23 and 12 is 35
, :
Console.WriteLine("The Sum of {3} and {1} is
;){0}.",12,23,12+23
Markers - .
, } {1 } ,{2
}.{3
.
11,22,33 3:
Console.WriteLine("{0}, {1}, {2}, {0}, {1}, {2}, {0},
;){1}, {2}",11,22,33

' "

16

:
11, 22, 33, 11, 22, 33, 11, 22, 33
. , .
:
Total:{2}", 2,

}Console.WriteLine("Units:{0} Price:{1
;)23, 2 * 23
}Console.WriteLine("Units:{0} Price:{1
;)Total:{2}", 30, 10, 30 * 10

:
Units:2 Price:23 Total:46
Units:30 Price:10 Total:300
, , .Markers-
:
Total:{2,

}Console.WriteLine("Units:{0, 5} Price:{1, 5
;)5}", 2, 23, 2*23
}Console.WriteLine("Units:{0, 5
;)Price:{1, 5} Total:{2, 5}", 30, 10, 30*10

:
Units: 2 Price: 23 Total: 46
Units: 30 Price: 10 Total: 300
Markers - 5 ,
) ( .
:
} , {
, .
}Price:{1, -5
}Price:{1, -5

}Console.WriteLine("Units:{0, -5
;)Total:{2, -5}", 2, 23, 2*23
}Console.WriteLine("Units:{0, -5
;)Total:{2, -5}", 30, 10, 30*10

:
Total:46
Total:300

.

Price:23
Price:10

Units:2
Units:30

) ,(-

' "

17

Numeric Formatting
, )( Console.Write Console.WriteLine() -
.:

C , .
:
;)Console.WriteLine("A car costs {0:c}", 60000
:
A car costs $60,000.00
! " .
. ,
. " ".

F ) ( .
,"
.F:

Console.WriteLine("This is the same float number: {0:F},


;){0:F2}, {0:F6}", 71.1234
:
This is the same float number: 71.12, 71.12, 71.123400
: 71.12 . },{0:F
.

N :

commas:

with

number

big

is

Console.WriteLine("This
;){0:n}", 1000000000

:
This is a big number with commas: 1,000,000,000.00

:exponential -
;)Console.WriteLine("The number {0} = {0:E}.", 14200

' "

18

:
The number 14200 = 1.420000E+004.

is

:hexadecimal -
hexadecimal

in

}{0

number

Console.WriteLine("The
;){0:X}.", 174

:
The number 174 in hexadecimal is AE.


"-" ) ,(User -
. ,
, . .
, ,
.
)static void Main(string[] args
{
. //.name
;string name
" : //.".
;)"Console.WriteLine("Enter your name:
, //.name
;)(name = Console.ReadLine
//.name -
;)Console.WriteLine(name
}

":
.name
,
.
.
Enter- .name
.
.
! 4 ,name -
) name (
.name
' "

19

:
)static void Main(string[] args
{
. //:
//fname, lname
;string fname
;string lname
" : //.".
;)"Console.WriteLine("Enter your first name:
, //
//fname
;)(fname = Console.ReadLine
" : //.".
;)"Console.WriteLine("Enter your last name:
, //
//fname
;)(lname = Console.ReadLine
// -
//fname
;)Console.Write(fname
//
;)" "(Console.Write
// -
//lname
;)Console.WriteLine(lname
}

":
2 ) .(1,2

) fname .(3,4

) lname .(5,6
)
(7,8,9 .

' "

20


.
\ ).(Back Slash
\n
\b
\r
\t ) 8(
\\ \
"\ "
\ ) (.
:

\n
Console.WriteLine("This is one line.\nThis is a new
;)"line.
, .
:

This is one line.


This is a new line.
\b
;)"Console.WriteLine("12345\b67890
5 .
:
123467890

\r
;)"Console.WriteLine("12345\r67
5 .
:
67345

\t
;)"Console.WriteLine("Nadav\tYeheskel
;)"Console.WriteLine("Avi\tCohen
;)"Console.WriteLine("Moshiko\tLevi

' "

21

, 8.
. , \t
. , , \t -
.
:

Nadav
Yeheskel
Avi
Cohen
Moshiko Levi
\\
;)"Console.WriteLine("\\n
\ , \\ .
:
\n

"\
;)""\ Console.WriteLine("Print quotes:
)"( / ,
.
:
" Print quotes:

' "

22

:
.1 .
.2 .
.3 .
.4 .
.5 .
.6 .
.7 ! ) ( .
?
.8 2 - .
.
.9 aaa\bbb"ccc :
.10 :
;)"Console.Write("bbb\bbb\bbb\bbb

' "

23

4
:
?











?
.
) (.
2 -:
.1 .
) '( .
.
.
.2 .


.
.
:

' "

24

;int x

,
) ( .
, . ,
.
2 )( :
.1 )(.
.2 .
:
;int x
;x = 5
;)Console.Write(x
x ) int .(Integer
int
) (.
:
, )=(.
, )=( ,
)=( , . "
5 .x
! .
:
. ,
, , ,x .
, .5
;)Console.Write(x
:
5
:
//.
int // a, b, c
;int a
;int b
;int c
. c //
a// .b -
;a = 4
;b = 7
;c = a + b
, (4 + 7 = 11) a + b .c
' "

25

! :
;a
;b
;c
;4
;7
;b = c

int
int
int
= a
= b
a +

,
. , ,
)=( , .
c .a + b - -
a + b , "
.
:
.int ,a //
5 //.
;int a = 5
5 ,a , //.
;a = a + 1
(5 + 1 = 6) a + 1 a a .6
,
)=(.


:

.

, )( )_( .
)( )_(.
511 -.
) .(int
2 - ) (.

' "

26

:
. ,
.
,
. ,
firstName .x

.
.:
number, myNumber
. ,
, . , ,
.


, :
short, int, long :
)(float, double, decimal :
, ' .
" ) (.
short -32,768 ) 32,767 2
(.
int -2147483648 4) 2147483647 (
'.
,
.
,
:
int.MaxValue .int
int.MinValue .int
float.MinValue .float
float.MaxValue .float
...
:
Console.WriteLine("The lowest int value is: {0}",
;)int.MinValue
Console.WriteLine("The biggest int value
;)is: {0}", int.MaxValue

' "

27

:
The lowest int value is: -2147483648
The biggest int value is: 2147483647


, )(,
. Compiler -
, , .
, :

+
*
/
%

Addition -
Subtraction
Multiplication -
Division -
Modulus -

! .
) (short, int, long :
, , ,
.
:
, //.
;int num1 = 12
;int num2 = 8
//.
}Console.WriteLine("num1 = {0
;)num2={1}", num1, num2
//
Console.WriteLine("-------------------------------------;)"------
4 . //
, //.
Console.WriteLine("num1 / num2 = {0} with modulo of {1}",
;)num1 / num2, num1 % num2
;)Console.WriteLine("num1 * num2 = {0}", num1 * num2
;)Console.WriteLine("num1 - num2 = {0}", num1 - num2
;)Console.WriteLine("num1 + num2 = {0}", num1 + num2

' "

28

:
num1 = 12 num2=8
-------------------------------------------num1 / num2 = 1 with modulo of 4
num1 * num2 = 96
num1 - num2 = 4
num1 + num2 = 20
,
.
:float , ,
//. ,
float floatNum1 = 9;
float floatNum2 = 5;
//.
Console.WriteLine("floatNum1 = {0}
floatNum2={1}",
floatNum1, floatNum2);
//
Console.WriteLine("-------------------------------------------");
// . 4
// . ,
// ,
//.3 .
Console.WriteLine("floatNum1 / floatNum2 = {0:F3}",
floatNum1 / floatNum2);
Console.WriteLine("floatNum1 * floatNum2 = {0:F3}",
floatNum1 * floatNum2);
Console.WriteLine("floatNum1 - floatNum2 = {0:F3}",
floatNum1 - floatNum2);
Console.WriteLine("floatNum1 + floatNum2 = {0:F3}",
floatNum1 + floatNum2);
:
floatNum1 = 9 floatNum2=5
-------------------------------------------floatNum1 / floatNum2 = 1.800
floatNum1 * floatNum2 = 45.000
floatNum1 - floatNum2 = 4.000
floatNum1 + floatNum2 = 14.000

' "

29

:
* %,/, -,+
:
result ,12
.num2 / 2 ,num2 = 4 - .2 ,
.10 + 2 = 12 :num1
;int num1 = 10
;int num2 = 4
;int result = num1 + num2 / 2
. ,
result ) 6 num1 + num2 :(2
;int num1 = 10
;int num2 = 3
;int result = (num1 + num2) / 2

- ) , (.
, .string
, .
,string ,
.
:
;string str
;"str = "My name is avi, and my age is 5.
.
! ,Console - .
, .
, )( ,Console.WriteLine .string
: .string -
" .Console -

' "

30

," :
.str //.string
str !// bla bla
;"!string str = "Hello World
//.str
;"" = str
" :
;"!string str = "Hello World
//.str
;str = string.Empty


, , .
, ,
) int, float'( .
:
,
. ,
" .
, ,
. , ,
, ) 0 ,
(.
)( :
) ,( , .
2 ) ( ).(+
, ) (//.
;"string firstName = "Israel
;"string lastName = "Israeli
, //.
//.name -
;string name = firstName + " " + lastName
//.
;)Console.WriteLine("Full Name: " + name
:
Full Name: Israel Israeli

' "

31

,
):(+
;string s1
;string s2
;"s1 = "1
;"s2 = s1 + "2
s2 " "12 1.2 -


" )(.Console.ReadLine
" .string
) , , '(.
)( Console.ReadLine
.string
,
. , string
) )( ,(Console.ReadLine .
, ,Parse
. ,string
.
:
;string str
;"str = "10
;int x
;)x = int.Parse(str



string

) str (string ,int


.x ,int- x
.int

' "

32

, ,
Parse . ,
.
:
;string str
;"str = "5.5
;float fl
;)fl = float.Parse(str
! str ):
" "abc ( , "".

:
//.
;string input
;int x
" : "//.
;)"Console.WriteLine("Enter number:
.input //
Console.ReadLine() - //.string
;)(input = Console.ReadLine
input - .int - //.x -
;)x = int.Parse(input
,x //.x-
;x = x * 2
the

and

}{0

is

input

//
Console.WriteLine("The value of
;)value of x is {1}.",input,x

' "

33

, ) input x ,string .(int


,
.input
.string ,
,input , ) (
.x , .
,x- , x 2 -
.x x -
) ,(int .
.
, ,12 :
The value of input is 12 and the value of x is 24.

' "

34



, - . ,
.
, .
: , '.
:
.
.
)
(.
,
)_( DAYS_IN_WEEK :
const ,
, .:
PI ) double , (//.
;const double PI = 3.14
:
. //.
;const double PI
:
;const double PI = 3.14
. //.
;PI = 5

' "

35

:
)static void Main(string[] args
{
. PI //3.14
;const double PI = 3.14
. //
, //
//.
;double circleArea
;double radius
;string str
" : "//.
;)"Console.Write("Enter radius:
, //.str
;)(str = Console.ReadLine
str .double - //
double- )(// .double.Parse
;)radius = double.Parse(str
//.
;circleArea = PI * radius * radius
//.
;)Console.WriteLine("The Area is {0}",circleArea
}
.
.PI
,PI PI -
.

' "

36

:
)static void Main(string[] args
{
CENTIMETERS_IN_METER //
//.100
;const int CENTIMETERS_IN_METER = 100
//
;double height
//
Console.Write("Hello.\nPlease enter your height in
;)" centimeters:
.double - , //
)( Console.ReadLine //
. //
) string (//.
;))(height = double.Parse(Console.ReadLine
//.
Console.WriteLine("\nDid you know that in 1 Meter
;)the are {0} Centimeters?\n", CENTIMETERS_IN_METER
, //.
Console.WriteLine("Your height in Meters is {0}",
;)height / CENTIMETERS_IN_METER

.
, :
, .
,
.
, / .
:

, . ,
. , ,
, .
.
, Compiler- ,
. , ) (
) (.

' "

37


.
, .
, , .

.
. .
.
;int x,y,z
" :
;int x
;int y
;int z

.
. .
;int x = 5

;int x
;x = 5

2 "
:
;int x = 5 , y , z = 10


:
,
.
: 2 , 3 - '.
:
=+
=-
=*
=/
=%

' "

38

;= a + 5
;= a - 6
;= a * 3
;= a / 2
;= a % 4

a
a
a
a
a


;a += 5
;a -= 6
;a *= 3
;a /= 2
;a %= 4

;b
;b
;b
;b
;b

= a +
= a* = a
= a /
= a %

a
a
a
a
a


;a += b
;a -= b
;a *= b
;a /= b
;a %= b

" ,
) 1 - (:
++
--

Pre or Post Increment - Pre or Post Decrement

;A = a + 1
;A = a - 1

Post
;a++
;a--

Pre
;++a
;--a


;a += 1
;a -= 1

" , 2 :
Pre . ,
.1
:
. .
. ) 1-/(.
. .
. .
Post .
.2
, :
. .
. .
. ) 1-/(.
. .

' "

39

:
++) Post Increment ( .
,Post Increment - :
num . , .10
.1
,10 ,num .result
.2
num ,1 10-.11-
.3
.num
.4
.num
;int num = 10
;int result
;result = num++
;)Console.WriteLine("num = {0}", num
;)Console.WriteLine("result = {0}", result
:
num = 11
result = 10
, ++) Pre Increment
( . ,Pre Increment -
:
num . .10
.1
num ,1 10-.11-
.2
.num
.3
)( num .result
.4
.num
;int num = 10
;int result
;result = ++num
;)Console.WriteLine("num = {0}",num
;)Console.WriteLine("result = {0}",result
:
num = 11
result = 11

' "

40


C# ,
. .
:
,num "
. , ,
, .
;int num
. //:
'//Use of unassigned local variable 'num
;)Console.WriteLine("num = {0}",num
.
: .
, 0 .
;int num=0
;)Console.WriteLine("num = {0}",num
C# . )(
. , ,
.
2 .num1, num2 2 ,
) num2 - (.
)static void Main(string[] args
{
;int num1 = 10
. //.
;int num2 = 10
;num2 = 20
;num2 = 40
;)Console.WriteLine("num1 = {0}",num1
}

' "

41


,
string ,int
.
:
;string str
;"str = "10
;int x
;)x = int.Parse(str
,
,string ) (.
)(.ToString
) )(.(ToString
:
;string str
;int x = 10
;)(str = x.ToString




string

,(str) string (num) int


.50 - num )
.(2 str
) (.

' "

42

)static void Main(string[] args


{
//.
;string str = string.Empty
;int num = 50
num //.
num //.
;num = num * 2
num .string- //.str -
;)(str = num.ToString
. str- //
//.
;)Console.WriteLine("The number * 2 = " + str

:
The number * 2 = 100
) (.
) int ( double
) ( . double - int -
.
2 :
implicit casting .

, . .
short - int - ,
,short .int
: ' .
. ,
:
;short shortNum = 10
;int intNum
//.
;intNum = shortNum
explicit casting .

' "

43

,
) double -.(int -
.
Compiler - ,
. .
, ,
.
. ,
:
;double doubleNum = 10.5
;int intNum
;intNum = (int)doubleNum


.

.

" intNum 10 10.5


.
) ( ,
:
;double doubleNum = 10.5
;int intNum
//
, //:
//Cannot implicitly convert type 'double' to 'int'.
;intNum = doubleNum

' "

44

:float
, Compiler - .double -
, ,float .
:
//.
;float fl = 5.6
:
;float fl = (float)5.6
,
:
;float fl = 5.6f
:
;float fl = 5.6F

' "

45


, . ,
. ,
.
.Random //
//.
;)(Random rnd = new Random
//.
;int n1, n2, n3
.
,rnd.Next(0,100) -
0) 99 -(.
;)= rnd.Next(0, 100
;)= rnd.Next(0, 100
;)= rnd.Next(0, 100

//
//
//
n1
n2
n3

//
;)Console.WriteLine("n1 = {0}", n1
;)Console.WriteLine("n2 = {0}", n2
;)Console.WriteLine("n3 = {0}", n3
rnd ) Random
,
( . , .
Next ,
, 0) 100 - 0
.(100 )
n1 - n2 - .(n3 - ,
, .
.

' "

46

:
.1 . , .
.2 . . !
) (.
.3 3 .
.4 ) (.
.5 :
. .
. .
.

.8 -

. ) (.
. .
.
.6 : .
.7 A ,B ) (.
.8 . .
.9 .
) R , = ~3.14 .R2 , = * (.
.10 .
: ,88 ).1 hour(s) and 28 minute(s
.11 , 4 .
.
.12 , 4 .
.
.13 ) .(0
.14 .
.15 10 .99 .
: ,61 .16
.16 , .

' "

47

5
:

bool
if


! )(Not

switch

)(Boolean
.b = 9 ,a = 3 :
, .b ,
"" . " ,"
"" . ) (.
.
"" ) (true "" ).(false
, ,
, "" .
:

...
>
...
<
...
==
...
=!
... ...
=>
... ...
=<
:
int num1,num2:
;int num1 = 7
;int num2 = 4

' "

48

true
num1 > num2
true num2 <= num1
false
num1 > 10
true
num2 > -5
false
num2 < 4
true
num1 >= 7
false
num1 == 4
true
num1 != num2

bool
2 : ,.
.bool bool
true : .false bool .
:bool
//
;bool b1 = true
;bool b2 = false
//.
;)Console.WriteLine("b1 = {0}", b1
;)Console.WriteLine("b2 = {0}", b2
:
b1 = True
b2 = False
bool true ,false
.
) b (bool :x>=y

' "

49

//.int
;int x = 10, y = 13
//.
;bool b
.x >= y ) (//
//.b -
;b = x >= y
//
Console.WriteLine("The result of 'x >= y' is
;)'{0}'",b
:
'The result of 'x >= y' is 'False

if
, , Main
.
. .
if ,
).(Boolean
:
) (if
{
//
""//.
}
else
{
//
""//.
}

' "

50

:
;int num1 = 5
;int num2 = 8
num1 > num2 //
)if (num1 > num2
{
"" , //
num1 .num2 - , //
//.
;)"Console.WriteLine("num1 greater then num2
}
else
{
"" //.
Console.WriteLine("num1 lower then num2 or equals to
;)"num2
}
:
x lower then y or equals to y
" 2 int .
.num1 > num2 true ,
false . ,
5) false ,(8 - .else-
:
;"string password = "Nadav123
password//
//.
)"if (password == "Nadav123
{
//
"" . , //
Console.WriteLine("Password match. Access
;)"granted.
}
else
{
""//,
//.
Console.WriteLine("Password do not match! Access
;)"denied.
}

' "

51

:
Password match. Access granted.
string . ,
)" .("Nadav123 ,
. ,
, . , password ,
.
" :
bool true/false
.if
//.
;"string password = "Nadav123
;bool passwordsMatch

password //
)" .("Nadav123 //
//.passwordsMatch
;"passwordsMatch = password == "Nadav123
//
.passwordsMatch " ,"true //
//.true
)if (passwordsMatch
{
"" //
Console.WriteLine("Password match. Access
;)"granted.
}
else
{
Console.WriteLine("Password do not match! Access
;)"denied.
}
, , :
" ."if passwords match ,
.

' "

52

: " , passwordsMatch -
.b1 - ?
:
;int x = 5, y = 8
)if(x > y
;)"Console.WriteLine("x greater then y
else
;)"Console.WriteLine("x lower then y or equals to y
, if - else -
) ( . )(
if - ,else - . , ,
if - .else -
/ ,
. ,else -
.if
.else -
.
;int x = 5, y = 8
)if(x > y
;)"Console.WriteLine("x greater then y


,
. .
:

&&
||

) And( - ) Or(

&& ) (And ,
,true ) 2( .true
.false
|| ) (Or ,
) 2( .true 2 - ,
.false
:

' "

53

: num1,num2,num3 int
int num1 = 7;
int num2 = 4;
int num3 = -3;

True
num1 > num2 && num2 > num3
False num2 <= num1 && num3 >= num2
True
num1 > 10 || num2 < 5
False
num2 > -5 && num3 < -9
False
num2 < 4 || num3 > -3
True
num1 >= 7 && num3 != num1
True
num1 == num3 || num2 != num1
True
num1 < num2 || num3 < num2
:
//.
int dayOfWeek;
//" " :
Console.Write("Enter a number of a day of week:")
//,(Console.ReadLine())
//,(int.Parse(Console.ReadLine())) int -
//.dayOfWeek -
dayOfWeek = int.Parse(Console.ReadLine());
//.dayOfWeek <= 7 dayOfWeek >= 1
if (dayOfWeek >= 1 && dayOfWeek <= 7)
{
// ""
Console.WriteLine("Valid day number.");
}
else
{
// ""
Console.WriteLine("Not a valid day number.");
}
:
: ,( ) 1-7
Valid day number.
: ,
Not a valid day number.

' "

54

":


|| 1 2

&& 1 2

true

true

true

true

true

false

false

true

true

false

true

false

false

false

false

false

2 - :
2 - . 3
&& true .
3 || ,
.true
&& || , . &&
|| ) - ( .
" ) (.
:
|| 3 && 21
:
) || 3 && 2( 1
:
) || 3 && (21
: , . , :
)If (num1 > num2 && num2 > num3
.
.
.
:
))If ((num1 > num2) && (num2 > num3
.
.
.

' "

55


, . ,
, . ,
.:
. ,
. ? : num1
) num2 - ( , , num2 -
. num2 .
:
)static void Main(string[] args
{
//
;int num1,num2
" : "//
;)"Console.Write("Enter number1:
. //.num1-
;))(num1 = int.Parse(Console.ReadLine
" : "//
;)"Console.Write("Enter number2:
. //.num2-
;))(num2 = int.Parse(Console.ReadLine
)if(num1 > num2
{
num1 .num2 - //.num1
;)Console.WriteLine(num1
}
else
{
num1 , //.num2 -
num1 //.num2 -
)if(num1 < num2
{
num1 .num2 - //.num2
;)Console.WriteLine(num2
}
else
{
, //.
;)"Console.WriteLine("Equals
}
}

' "

56

2.
:
num1 ?num2 -
, .num1
, : num1 ?num2 -
, .num2
, "."Equals
else - if - ," ) num1 -
( else -.
if - ," num1 -
num1 . , .
: , , .
" , else - .

! )(Not
! true - false - .
! ,"
,
, .
:
;int x = 10, y = 13
;bool b
;)b = !(x >= y
Console.WriteLine("The result of '!(x >= y)' is '{0}'",
;)b
:
'The result of '!(x >= y)' is 'True
) !(:
;b = x < y
.
, , :
num , //.
))if ((num >= 0
{
;)"Console.WriteLine("Not negative
}

' "

57

:
num ) not (//.
))if (!(num < 0
{
;)"Console.WriteLine("Not negative
}
,
,bool
,false !.
//.
;bool validUser
.
.
.
validUser "//."false
;validUser = false
.
.
.
//.
validUser //.
, false -//.(not false) true-
)if (!validUser
{
,validUser = false //
//.validUser
;)"Console.WriteLine("You are NOT a valid user.
}
else
{
//.validUser = true
;)"Console.WriteLine("You are a valid user.
}

" :
)if(validUser == false
{
//
}

' "

58


,
. .
:

.false

; : ? ) ( =

.true

x , ""Positive
result " "Negative .result
.
;string result
;int x = -5
, " "false//
result "//."Negative
;"result = (x >= 0) ? "Positive" : "Negative
;)Console.WriteLine("{0} is {1}", x, result
:
-5 is Negative
:if
;string result
;int x = -5
)if (x >= 0
{
;"result = "Positive
}
else
{
;"result = "Negative
}
;)Console.WriteLine("{0} is {1}", x, result

' "

59

, . ,
,
.
) if (.
) (true/false
. if
.
.
.
.

switch
, .
if , .
switch .
:switch
)


(switch
{
: case 1
1
;break
: case 2
2
;break
: case 3
3
;break
.
.
.
.

default:

;break

' "

60

switch ) (
-case -.
case break -
.
.case
)-case( ,
.default -
default - .
,
) default - break -(.

,
) .(1-7 ) 2 .(Monday
) 1 - ,(7 -
"."Illegal day of week

' "

61

static void Main(string[] args)


{
int dayOfWeek;
// ,
//.dayOfWeek
Console.Write("Enter day of week:");
dayOfWeek = int.Parse(Console.ReadLine());
//.dayOfWeek
switch(dayOfWeek)
{
//."Sunday" ,1
case 1:
Console.WriteLine("Sunday");
break;
//."Monday" ,2
case 2:
Console.WriteLine("Monday");
break;
// ,"Tuesday" ,3
//.
case 3:
Console.WriteLine("Tuesday");
break;
case 4:
Console.WriteLine("Wednesday");
break;
case 5:
Console.WriteLine("Thursday");
break;
case 6:
Console.WriteLine("Friday");
break;
case 7:
Console.WriteLine("Saturday");
break;
//,case -
// .
default:
Console.WriteLine("Illegal day of week");
break;
}

' "

62

:
.1 " "Growing .
.2 .
.3 " "Even "Odd"- -.
.4 . . ,
.
.5 .
.6 " :"" ," "" .
.7 928 - .532 -
.8 ,10% -
6,000 -".
6,000 -" , 5%
.
.
.
.9 . " "Increasing ,
.
.10 .
.11 1 .9,999 .
.12 . 14 18
21 .26 , 182 .
) ( .
.13 1 10 ) , .( ,
.
.14 .

' "

63

.15 " "" ,


:
55 - .
55 64.
65 74 .
75 84.
85 94 .
95 .
.
.16 A F x- y- :

Ax+By=C
Dx+Ey=F

x y" :

CEBF

=x

AEBD
AFCD

=y

AEBD

A F .
0 - !
,0 . "."Equation has no solution

' "

64

6
:






breakcontinue -




. ) (loop .
) (iteration .
5 .
5 , 500 500
? ) :
( ,
?
, .


-
.
:while
) (while
{
, //
"" )//.(true
}
:
.

' "

65

:
num 0 .
while num ) .(,
num .1 - num ,10 -
0 - 9 ) .(9 -
0 num 9 - .
;int num=0
)while(num < 10
{
num , //.
;)Console.Write("{0}, ", num

num//.1-
;num++

:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
:while
.1 .num
.2 . :
) :(true ) .(3
) :(false
) .(4
.3 ) ( .2
.4 .
while ,
,
, .
while 1 - .
:
) ( .
,
, , , ... .
?
, .
.
.

' "

66

;int num
//.
;)"Console.Write("Enter a non negative number:
, int- //.num -
;))(num = int.Parse(Console.ReadLine
num //.0-
)while (num < 0
{
//.
;)"Console.Write("Enter a non negative number:
, // .num -
;))(num = int.Parse(Console.ReadLine
}
:
,2 , .
//.
;int num, powerCount=0
//.
;)"Console.Write("Enter a number:
, //.num -
;))(num = int.Parse(Console.ReadLine
num ,2- //.
)while(num >= 2
{
num .2- //2-
//.
;num /= 2
//.
//.
;powerCount++
}
//.
;)Console.WriteLine(powerCount

' "

67

. , :
- num .
- powerCount .2
, .num ,num
. - num
.2 -
, num powerCount .1 - ,
. ,
.
, , .powerCount
:
2 .1 -
: ,16 :
powerCount = 0 + 1
num = 16 / 2
,num = 8 :
powerCount = 1 + 1
num = 8 / 2
:
powerCount = 2 + 1
num = 4 / 2
:
powerCount = 3 + 1
num = 2 / 2
num = 1 .
4 powerCount - .4" 2 - 4
.16


" " ,
. ,
, , .
:dowhile
do
{
. , //
"" , //.
;) (}while
:
.
' "

68

:dowhile
.1 .
.2 ) (.
.3 :
) :(true .2
) :(false .4
.4 .
,while
.2 ,while dowhile
,
. dowhile
) .(while
,while .dowhile
.
) ( ,
. ,
.
dowhile ,
.
:while
;int num
//.
;)"Console.Write("Enter 0 or positive number:
. //.num-
;))(num = int.Parse(Console.ReadLine
num //.
)while (num < 0
{
//.
)"Console.Write("Enter 0 or positive number:
. //.num-
;))(num = int.Parse(Console.ReadLine
}
, .
.dowhile ,
. .

' "

69

:dowhile
;int num
, //.
do
{
//.
;)"Console.Write("Enter 0 or positive number:
. //.num-
;))(num = int.Parse(Console.ReadLine
" ,"true //.
;)} while (num < 0


- ,
.
.
.
" ,
. , ,
.
:for
) ; ; (for
{
. //
//.
}
:
.
, .while
, while 0 - ,9 .

' "

70

;int num=0
)while(num < 10
{
num , //.
;)Console.Write("{0}, ", num

num//.1-
;num++
}

:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
, 3 :
.1 num) 0 - (.
.2 num .10 -
.3 num .
,for :
;int num
)for(num=0 ; num < 10 ; num++
{
;)Console.Write("{0}, ", num
}

" .for
:for
.1 .
.2 .
.3 :
) :(true .4
) :(false .6
.4 .
.5 .3
.6 .
,while
,
.
.
.
,
. ,
, , .

' "

71

:
)for(int num=0 ; num < 10 ; num++
{
;)Console.Write("{0}, ", num
}

, for
. .
1 - :10
) 1 - (4! = 1*2*3*4 :
for . , //i
, ,j //.i
, //.j-
)for (int i = 1, j = 1 ; i <= 10; i++ , j*=i
{
;)Console.WriteLine("{0}! = {1}", i, j
}
:
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
10! = 3628800
) (i,j i
, j . i
,1 - j ,i - j
.i .
! , -
) for//( .
.

.10 ,
. , .

' "

72

//.
;)" Console.Write("Enter number:
. //.number -
;))(int number = int.Parse(Console.ReadLine

:5

)for (; number <= 10; number++


{
;)Console.Write("{0}, ", number
}
5, 6, 7, 8, 9, 10,

: ? 10 -
:
. ) " ("false
.



.if .
:
//.
;int num=-1, sum=0
//.
;)"Console.WriteLine("Enter 10 numbers. To stop enter 0:
10 . //
,0 ) ""(//.
)for (int i = 1; i <= 10 && num != 0; i++
{
;))(num = int.Parse(Console.ReadLine
;sum += num
}
//.
;)Console.WriteLine("Sum = {0}", sum
" 10 ,
. 10 -
, 0 .
10
.0

' "

73



. .
- .
:
. 4 .
5 . ,
:
5
5
5
5

4
4
4
4

3
3
3
3

2
2
2
2

1
1
1
1

1
2
3
4

. ,for
. 100
, 100 for .
, , , ) (.
:
//.
;const int rows = 4
;const int cols = 5
. //
, //.
)for (int i = 1; i <= rows; i++
{
//.
;)Console.Write("{0}: ", i
//.
)for (int j = 1; j <= cols; j++
{
; ;)Console.Write("{0} ", j
}
, //,
, //
//.
;)(Console.WriteLine
}

' "

74

:
1: 1 2 3 4 5
2: 1 2 3 4 5
3: 1 2 3 4 5
4: 1 2 3 4 5
1 - .5 4
" ," )( 4 .
) (:
.

breakcontinue -
C# " " .
,
, .
.
, .
- break / .
.
- continue .
) ( .
:break
//.
;int sum = 0
10//.
)for (int i = 0; i < 10; i++
{
//.i
;sum += i
i ,3- //.
)if (i == 3
{
//.
;break
}
}
//.
;)Console.WriteLine(sum

' "

75

:
6
0- ) 9( .
,break .
:break
//.
;int tmp, i, num
//.num
;)" Console.Write("Enter number:
;))(num = int.Parse(Console.ReadLine
2- num //.num-
)for (i = 2; i < num; i++
{
tmp - num//.i-
;tmp = num % i
)if (tmp == 0
{
num , //.
;break
}
}
num == i //
, //.
)if (i == num
{
. //.
;)Console.WriteLine("{0} is a prime number.", num
}
else
{
num //.
//.
;)Console.WriteLine("{0} isn't a prime number.", num
}

' "

76

" , )
1 - ( .
2 - ) ( .
,
) : 8 8
2 - ( . ,
) (
.
:continue
30 //.
)for (int i = 1; i <= 30; i++
{
//.
)if (i % 2 == 0
{
, //.
;continue
}
//.
;)Console.Write("{0}, ", i
}
:
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29,
1- .30 ,
. , , .

' "

77

:continue
//.
;int num = 0, sum = 0
//.
;)"Console.WriteLine("Enter 10 number:
)for (int i = 1; i <= 10; i++
{
//.num
;))(num = int.Parse(Console.ReadLine
, //.
)if (num < 0
{
//.
;continue
}
//.
;sum += num
}
//.
;)Console.WriteLine("Sum = {0}",sum
" 10 , .
,
) (.
break:continue -
, .
.
.
) break .(switch

' "

78


.
, ,
) ""( .
.
:
;int x = 0, num = 0
)while (x < 10
{
;num++
}
;)Console.WriteLine("num = {0}",num
) (x < 10 , x 0
. , x .10 -
.

' "

79


. ,
.
, .break
while :
)while (true
{
...
}

dowhile :

do
{

...
;)} while (true
for :
)for (int i = 0 ; ; i++
{
...
}
while ,dowhile " " ,
- false true false- .
,for- ,
,false " ".


- .
, )
( .
.
- );( .
:
; )( while
; ) ; ; ( for
: do..while while
.
' "

80

:
//.
;int num, res = 1
. //.num -
;)" Console.Write("Enter num:
;))(num = int.Parse(Console.ReadLine
. //
.i - );( //
//.
; )for (int i = 1; i < num; i++, res *= i
//.
;)Console.WriteLine("{0}! = {1}", num, res
" .
) (
.

' "

81

:
, .int
.1
.2
.3
.4

.top - 1 - ) top(.
) (.
, .
.num 0 - .num num -
.
max.num -
) max( .num - -
max .num -

...
.5 ,
.99 ) 99 - .(99
.6 ,
.0 ) 0 - .(0
.7 .0 )
(.
.8 .0 )
(.
.9 10 . .
...
.10 .
.11 .
.12 .
.13 : num .dig dig
.num -
.14 ) 1304 .(4031
.15 ,
) .(4774 ,12321 : , .
...
.16 . .
.17 .
.
.18 .
.

' "

82

.19 n 1 ) n(.
: 5 .5 4 3 2 1 = 120
2 .2 1 = 2
num . ! :
0 .1
.20 1%
. - 1% ,1000
990 .1010
'...
.21 ' :
.1
.1
.
, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89... :
. index index -) . (index>2
. .val ' .val -
...
.22 .
: 60 .1 ,2 ,3 ,4 ,5 ,6 ,10 ,12 ,15 ,20 ,30 ,60
61 .1, 61
.23 .
: 60 72.12 :
64 81.1 :
.24 "" " " ) .
.(1 -
.25 .
60 : .1 2 2 3 5 -
59 59) 1 59 - (.
...
.26 . .
.27 . .
.28 ) 30( 2000 ) 2001" 60
( . .2000
2001 .2000
.29 . .
.30 .
: ,5001 .0015
,48444 .44448
.31 . -
.
.32 .0 ':
1, 1, 2, 3, 5, 8, 13, 21...
' "

83

.33 .N N S! = 1*2*3*............*N :
.34 .N 1 - N 3 -
) : ,7 9 7 3 6 - .(3 -
.35 15 , ) , (......9 ,6 ,3 -
.
.36 20 . .
.37 20 . ) 6 ,4 , 2-'.(...
.38 .A 20
.A -
.39 ,N N . ,
.
.40 ,N N .
.
.41 10 )
( . " :" " : ".
.42 20 ,
. " ".
.43" 5 5.
5 - ,"
5 ' . ".
) " (.
.44 .N . :N = 4 -
1234

234
34
4
.45 :
4321
432
43
4

.46 10 .
: 9, 12, 8, 8
9, 10, 11, 12, 11, 10, 9, 8, 8
.47 . 5:3 -
***
***
***
***
***

' "

84

.48 .
.49 10 ,99 - .
.50 , 1 - 100 .
.51 - ,
, .
.52 200 :" 100 ," 50 ," 20 ," ,
10 :" 5 ," 1 ," 0.5 ," 10 , 5 , 1 ,.
, .
.53 .

' "

85

7
:









"" ,
.
,Enter - ,
, . )( Console.WriteLine
" ." , , .
.
.
, .
" "
. .
,
. .
, ,
. . ,
, . .
:
.1 "" .
.2 .
.3 .
. .
" "
. ,
. ! , ,
. ) ,
(

' "

86

. .NET - .
.
"" , "" ,
. .
:
, .
"".
.
!.


:C# -
)(void FuncName
{
. //
//.
}
:
class Program
{
)static void Main(string[] args
{
;)(PrintName
}
)(static void PrintName
{
;)"'Console.WriteLine("My name is 'Avi
}
}
, " .PrintName"
, ."My name is 'Avi'" :
)(static void PrintName
{
;)"'Console.WriteLine("My name is 'Avi
}
: ,static
, .

' "

87

! , .:
)static void Main(string[] args
{
)(//.PrintName
//.
, //.
;)(PrintName
}
:
'My name is 'Avi
:
)static void Main(string[] args
{
;)(PrintName
;)(PrintName
;)(PrintName
}
:
'My name is 'Avi
'My name is 'Avi
'My name is 'Avi
,
. .
, .
:
class Program
{
)static void Main(string[] args
{
;)(ReadAndPrintName
}
)(static void ReadAndPrintName
{
;string str
;)" Console.Write("Enter your name:
;)(str = Console.ReadLine
;)Console.WriteLine("Your name is '{0}'", str
}

' "

88

ReadAndPrintName
.
, .
Main .
,
) .(exe -
/ ) Main - (
.Class - .
class Program
{
//.
}
, \ ,
, .class -
:
class Program
{
//
//.Class Program
)static void Main(string[] args
{
;)(ReadAndPrintNameAndAge
}
)(static void ReadAndPrintNameAndAge
{
;)(ReadAndPrintName
;)(ReadAndPrintAge
}
)(static void ReadAndPrintName
{
;string str
;)" Console.Write("Enter your name:
;)(str = Console.ReadLine
;)Console.WriteLine("Your name is '{0}'", str
}
)(static void ReadAndPrintAge
{
;)" Console.Write("Enter your age:
;)(string str = Console.ReadLine
;)int age = int.Parse(str
;)Console.WriteLine("Your age is '{0}'", age
}

' "

89

" ReadAndPrintNameAndAge
ReadAndPrintName ReadAndPrintAge
2 , ) (.


"" ,
.
. .
.
, .
:
class Program
{
)static void Main(string[] args
{
;int num = 8
;)PrintNumbers(num
;)PrintNumbers(5
}
)static void PrintNumbers(int x
{
)for (int i = 1; i <= x; i++
;)Console.Write("{0},",i
;)(Console.WriteLine

}
}

:
1,2,3,4,5,6,7,8,
1,2,3,4,5,
PrintNumbers x .int
1 - .x
. ,
(num) 8 .5
x ,
x.
.

' "

90

:
class Program
{
)static void Main(string[] args
{
;"!string str = "Hello Class
;int num = 3
;)PrintString(str, num
}
)static void PrintString(string str, int x
{
)for (int i = 1; i <= x; i++
;)Console.WriteLine("{0}: {1},", i, str
}

:
!1: Hello Class
!2: Hello Class
!3: Hello Class
)( PrintString str string
, x int .
"! "Hello Class ,3
3.
, )
( .
, ) .(, ) (
, .
! .
, " :
) ( .
" , string .int
.
" , string " .int
.
" , .double
.
.

' "

91


, .
.
.
,
) .(void ,
.float , -
.void , void .
! , .
, return
.
,
)=(.
:
class Program
{
)static void Main(string[] args
{
//.
;int res
;int num = 5
Sum num//.
.Sum- Sum-// ,
res //.
;)res = Sum(num
//.
Console.WriteLine("Sum of 1 to {0} is {1}",
;)num, res
}
.Sum //
,int .int //,
1- //
// .
)static int Sum(int number
{
.s //
//.
;int s = 0

' "

92

1- //.number
number //.
)for (int i = 1; i <= number; i++
{
;s += i
}
//.s
;return s
}

:
Sum of 1 to 5 is 15
Sum 1 -
) .(number , -
.int Sum
.s Main - num
) (5
, .res res
).(15
.
. ,
)( .
Sum :
;)Sum(num
,
, .
, . ,
return return -
.

' "

93

:
class Program
{
)static void Main(string[] args
{
)( GetBig //.2, 3, 1
//.big
;)int big = GetBig(2, 3, 1
//.
;)Console.WriteLine("{0} is big", big

//.int
.int //
//.
)static int GetBig(int a, int b, int c
{
a b - a ,c - //.
)if (a > b && a > c
//.a
;return a
, a- //.
b //.c-
)if (b > c
b , //.
;return b
, //
a b // .
c . //.
;return c

:
3 is big
GetBig 3 .
a ) b - (c -
.
) (b>c a - ) else if -(
b.c -
b c - b .
) (false c .

' "

94

! return .:
class Program
{
)static void Main(string[] args
{
. str//.
;"" = string str
;int num = 3
)(//.PrintString
;)PrintString(str, num

)static void PrintString(string s, int x


{
, //.
)if (s == "" || x <= 0
, //.
;return
x//.
)for (int i = 1; i <= x; i++
;)Console.WriteLine("{0}: {1},", i, s
}
}
)( PrintString ) (s ) .(x
,0
, . ,
)( PrintString , .

' "

95


) "
" " "(.
: .
) (.
. ,
.
:
)static int GetBig(int a, int b, int c
{
...
}
":
)int GetBig(int a, int b, int c

' "

96


. ,
.
: "" ) (.
:
.1 )(:
) ( .
, .
, "" , .
.
.2 )(:
.
"
.
.3 :
.class -
" "" .
, "
" .
: :
.1 ) Class Program - (.
.2 static .
} { , ) for, if'( .
. )}( " " )
( .
) (.
) (
, .

' "

97

, Main - pow ,x
Power :
class Program
{
)static void Main(string[] args
{
, x//pow -
)(//.Power
;x = 5
;pow = 20
}
)static void Power(int x
{
;int pow = x * x
;)Console.WriteLine(pow
}
}
2 ) ( ,
.
, 2 - ) (Print1, Print2
:
class Program
{
)static void Main(string[] args
{
;)Print1(17
;)Print2(17
}
)static void Print1(int x
{
;int y = 1
Console.WriteLine("{0} + {1} = {2}", x, y,
;)x + y
}
)static void Print2(int x
{
;int y = 2
;)Console.WriteLine("{0}, {1}", x, y
}
}

' "

98


.
, .
class Program
{
)static void Main(string[] args
{
//.
;int a=10, b=20
//.
= Console.WriteLine("Before swap: a = {0}, b
;){1}", a, b
)(//.Swap
;)Swap(a, b

//.
= Console.WriteLine("After swap: a = {0}, b
;){1}", a, b

, //.
)static void Swap(int x, int y
{
//.
;int tmp = x
;x = y
;y = tmp
}
}
:
Before swap: a = 10, b = 20
After swap: a = 10, b = 20
" )( Swap .
,
,
"" .

' "

99


,
, .
, :
.1 .
.2 .
.3 .
Microsoft ,
.Visual Studio - ' .


.NET , .
, ,
. ,
. ,
) Visual studio.NET - ' " "(.
:
)( int.Parse
).(int
)( Console.WriteLine .
...
, Tool Tip -
) IntelliSense - .(Visual Studio -
, .
, , ,
.

' "

100

.Tool Tip - .

' "

101


, , .
, , , , ,
. ,
.
, ) ,(ReUse
, , , .
, .
,
, " "
. ,
" "
. ,
.

' "

102

:
.1
.2
.3
.4
.5
.6

.7
.8
.9

2 .
2 .
.
.
: ,
.
3 .

) . ,
(.
,
.
.
n :
. n = 4 - .
*
**
*
***
**
*
****
***
**
*

.10 n :
n = 4 -
****4444****4444****4444****4444
***333***333***333
**22**22
*1

' "

103

8
:



foreach



100 .
100 .
10,000 , 10,000 ?
. .
.
.
, ) ( .
.
, . ,
. .
, )( .


:
;]int[] arr = new int[5

' "

104

5 , .int
, .
":

5
Length

,0 1
, ) (Length .1
! .
, ,
/ .
, .
:
)( GetSize //.size
;)(int size = GetSize
//.size
;]int[] arr = new int[size
" .size
)( GetSize .size,
)( GetSize ,10 10
.int

' "

105

:

] [.
8 ) //.(0
;arr[0] = 8
13 ) //.(3
;arr[3] = 13
//.
;)]Console.WriteLine(arr[3
:
13
Length :
) ( //.
;)Console.WriteLine(arr.Length
:
5
! ,
) (arr[0] , , . ,
, .
:
] arr[2 ,int
,int , ,
, , '.
: , " ),(for
.

' "

106

:
.arr 7//
//.int
;]int[] arr = new int[7
//.for
)for (int i = 0; i < arr.Length ; i++
{
//.2
;arr[i] = i * 2
}
//.for
)for (int i = 0; i < arr.Length ; i++
{
//.
;)]Console.Write("{0},",arr[i
}
:
0,2,4,6,8,10,12,
" 7 , .int for
0 - 1 )" 7( .
, ) i*2 .(0 -
, i i
.
.
.
:
.students //4
//.
;]string[] students = new string[4
//.
;"students[0] = "Nadav
;"students[1] = "Shiran
;"students[2] = "Mor
;"students[3] = "Yair
//.for
)for (int i = 0; i < students.Length; i++
{
. //
. //
//.
;)"!" Console.WriteLine("Hello " + students[i] +
}
' "

107

:
!Hello Nadav
!Hello Shiran
!Hello Mor
!Hello Yair

4 , .
, for ) ( ,
. ,
.
: ,
) ( , Length
.
, ) ( . Length
, . ,
Length .


.
:1 , .
;]int[] arr = new int[5
)for (int i = 0; i < arr.Length ; i++
;)]Console.Write("{0},",arr[i
:
0,0,0,0,0,
,
. int ,0
.0
:2 .
;} int[] arr = new int[5] { 5, 8, -4, 6, 2
)for (int i = 0; i < arr.Length ; i++
;)]Console.Write("{0}, ",arr[i

' "

108

:
5, 8, -4, 6, 2,
, } {
. , '.
,
] [.
:3 .
;} int[] arr = new int[] { 5, 8, -4, 6, -2
)for (int i = 0; i < arr.Length ; i++
;)]Console.Write("{0}, ",arr[i
:
5, 8, -4, 6, -2,
, } {
. , '.
} {.
:4 .
;} int[] arr = { 5, 8, -4, 6, -2
)for (int i = 0; i < arr.Length ; i++
;)]Console.Write("{0}, ",arr[i
:
5, 8, -4, 6, -2,
, .

' "

109

foreach
, . ,
. .foreach
:foreach
)foreach (type name in arrayName
{
) (//.
}

:
type .
name .
in .
arrayName .

name ,
.for
:
, //.
;} int[] arr = new int[5] { 6, 9, 4, -1, 2
//.
)foreach (int number in arr
{
)//.(number
;)Console.Write("{0}, ",number
}
:
6, 9, 4, -1, 2,
number - ,
.arr number ,int
.
:foreach
.1 .for
.2 , .
.3 .
.4 .
foreach .
foreach ,
) for (.

' "

110


, .
, ] [
) ( .
) (.
:
)static void FuncName(int[] arr
{
}
,
) (.
:
;]int[] arr = new int[100
;)FuncName(arr
, , ,
, ) (
. . , ,
. , ,
) (.
:
class Program
{
)static void Main(string[] args
{
10 //.int
//.arr
;]int[] arr = new int[10
)(//.InitArray
;)InitArray(arr
//.
;)PrintArray(arr
index- //.
;int bigIdx
;)bigIdx = GetMaxIndexInArray(arr
//.
Console.WriteLine("Index of max member in arr
;)= {0}",bigIdx
}

' "

111

, //
. ,//
//
//.
)static void InitArray(int[] arr
{
//.
;)(Random rnd = new Random
//.
)for (int i = 0; i < arr.Length ; i++
{
//.
;)arr[i] = rnd.Next(-99, 100
}

, //.
)static void PrintArray(int[] arr
{
//.
)for (int i = 0; i < arr.Length ; i++
{
//.
;)]Console.Write("{0}, ",arr[i
}
//.
;)(Console.WriteLine

, //
//.
)static int GetMaxIndexInArray(int[] arr
{
indexOfMax //
. //
//.0
;int indexOfMax = 0
. //
1 //.
)for (int i = 1; i < arr.Length ; i++
{
, //
//.

' "

112

)]if (arr[i] > arr[indexOfMax


//
, //
//.indexOfMax
;indexOfMax = i

//.
;return indexOfMax
}
}
:
45, 63, 53, 12, -58, 12, 81, -12, 95, -45
Index of max member in arr = 8

" 3 ) :(Main -
InitArray .
PrintArray .
GetMaxIndexInArray
.
Main - :
10.
)(.InitArray
)(.PrintArray
"
)( GetMaxIndexInArray .bigIdx
.bigIdx

, )( InitArray
))( ,(GetMaxIndexInArray() ,PrintArray .
, .

' "

113


. ,
:



:
.1 .
.2 .
.3 .
.4 ) 1 ( '
.
:
.1 2 ) ,
'( "" .
.2 .
.3 1 '.
: . ,
, , )( Array.Sort
, .
, .

' "

114


, ,
. , ""
" ".
, . ,
,
,
/
.
2:
start .
end .
:
.1 start, end )(.
.2 start end - .
.a .
.b .
.i start - .
.ii end - .
.c 2 start - .end -

' "

115

:
.1 .
.2 .
.3 )(.
.4 .
.5 .
.6 , .
! , .
.7 SIZE 0 ,9 - :
.
.8 SIZE 1000 ,9999 :
.
.9 SIZE , .
.10 : 50 5
. .
.11 SIZE 0 .9 -
.
:
8530318287354085731
1840294369231828733
.12 . 4589655236 :
.7 .
.13 SIZE .SIZE
, .
.14 .
.15 .
.16 .
.17 , ,
. .-1
.

' "

116

9 -
:
- )(
-
-
foreach

- )(
:
total

Dec

Nov

Oct

Sep

Aug

Jul

Jun

May

Apr

Mar

Feb

Jan
96
97
98
99
00
01
02
03
04
05
06

12 .
10 13 . 13
0-11 .
, , 10 ,
13 . . , ,
. ,
, rates1996 .1996
.
. ,
) , , '(.
, -.

' "

117

- - .
- , -
, ) ,
( . - .
- , -
. 2 - , )
( . .
: - , ,
. , -
.

-
- )(:
;]int[,] mat = new int[3,4
3 4 -.
- , .
,
. ,
) 0 - -(.
. 2 // .3
;mat[1, 2] = 20
//.
;)]Console.WriteLine(mat[1, 2
:
20
, 20 ) (1
) (2 .
, "
,Length
) * (.
. // 4*3 ,
;)Console.WriteLine(mat.Length

' "

118

:
12
) ( ,
)( GetLength . ,
0) 0 - 1 , (.
. //.3 ,
;)int rows = mat.GetLength(0
. //.4 ,
;)int columns = mat.GetLength(1
;)Console.WriteLine("Rows = {0}", rows
;)Console.WriteLine("Columns = {0}", columns

:
Rows = 3
Columns = 4
- , ,

. , ] mat[0,0 ,int
) int , , ,
'(.
," .
.
)/( , )( .GetLength
, ] [ .

' "

119

:
8 10 -//.
;]int[,] mat = new int[5, 10
//.
;)(Random rnd = new Random
. //
) //.(0
)for (int I = 0; I < mat.GetLength(0); i++
{
) //.(1
i //.
)for (int j = 0; j < mat.GetLength(1); j++
{
//.
;)mat[i, j] = rnd.Next(10, 100
}
}

. //.
)for (int i = 0; i < mat.GetLength(0); i++
{
//.
)for (int j = 0; j < mat.GetLength(1); j++
{
//.
;)]Console.Write("{0},", mat[i, j
}
, //.
;)(Console.WriteLine
}

' "

120

:
75,83,79,60,28,60,91,49,97,34,
36,52,66,52,98,12,87,99,70,38,
83,86,99,12,72,57,94,71,59,17,
26,50,36,98,67,78,12,44,40,96,
55,74,20,34,91,81,40,51,23,29,
" 2 :
.
) i (
.
) j ( .
, ).(i, j
].mat[I, j

, , .

) )( ,(Console.Write ,
) )(.(Console.WriteLine

' "

121

-
)(.
:1 , .
;]int[,] mat = new int[2, 3
)for (int i = 0; i < mat.GetLength(0); i++
{
)for (int j = 0; j < mat.GetLength(1); j++
{
;)]Console.Write(mat[i, j
}
;)(Console.WriteLine

:
0,0,0,
0,0,0,
,
. int ,0
.0
:2 .
;} } int[,] mat = new int[2, 3] { { 0, 1, 2 }, { 4, 5, 6
)for (int i = 0; i < mat.GetLength(0); i++
{
)for (int j = 0; j < mat.GetLength(1); j++
{
;)]Console.Write("{0},",mat[i, j
}
;)(Console.WriteLine

' "

122

:
0,1,2,
4,5,6,
, } {
. , } {
, .
, ,
, ] [.
:3 .
;} } int[,] mat = new int[,] { { 0, 1, 2 }, { 4, 5, 6
)for (int i = 0; i < mat.GetLength(0); i++
{
)for (int j = 0; j < mat.GetLength(1); j++
{
;)]Console.Write("{0},",mat[i, j
}
;)(Console.WriteLine

:
0,1,2,
4,5,6,
, } {
.
)( ,
)( .
.
:4 .
;} } int[,] mat = { { 0, 1, 2 }, { 4, 5, 6
)for (int i = 0; i < mat.GetLength(0); i++
{
)for (int j = 0; j < mat.GetLength(1); j++
{
;)]Console.Write("{0},",mat[i, j
}
;)(Console.WriteLine
}

' "

123

:
0,1,2,
4,5,6,
.

foreach
foreach ,
.
. ) (foreach
.
foreach
//.
;} } int[,] mat = { { 0, 1, 2 }, { 4, 5, 6
;int sum=0
//.foreach
)foreach (int x in mat
;sum += x
;)Console.WriteLine("Sum = {0}", sum
:
Sum = 18


, ,
.
) ( , )
(.
)static void FuncName(int[,] arr
{
}
, .
)static void Main(string[] args
{
;]int[,] mat = new int[20, 12
;)FuncName(mat
}
' "

124

:
.1 , :
)static void InitMatrix(int[,] mat
.2 , :
)static void PrintMatrix(int[,] mat
: , ,
1.2-

.3 , .
.4 SIZE :

.5 SIZE .
.
.6 SIZE 4 .
.
.7 SIZE .
.
.8 20 30 - . .
,
.
.9 N*M .0-9
":

. .

' "

125

.10 .
) ( . , ,
.
.11 :
G
500
480
660
730
340
670
---

F
450
430
510
240
220
--670

E
400
380
470
120
--220
340

D
350
260
410
--120
240
730

C
300
230
--410
470
510
660

B
200
--230
260
380
430
480

A
--200
300
350
400
450
500

A
B
C
D
E
F
G

' "

126

10 ,

:





char
string

int, short, double :' . ,


, .
, .


Bit : , 0 : .1
Byte 8 : .
1KB (Kilo Byte) = 210 * 1Byte = 1024 Byte
1MB (Mega Byte) = 210 * 1KB = 1024KB 1,000,000 Byte
1GB (Giga Byte) = 210 * 1MB = 1024MB Byte
TB (Tera Byte) = 210 * 1GB = 1024GB

' "

127


.
, 0 .1 - ,
) 0 .(1 - " "2
. ) (0-9 )
,(decimal " " . " "10
.
:

00000000
0
00000001
1
00000010
2
00000011
3
00000100
4
00000101
5
00000110
6
00000111
7
00001000
8
.
.
.
.
11111111
255
" Byte
0 ,255 - 256 28 )
( . : 0.(28 1) -
Byte . C# -
byte 0 .255 -
) short, int'(.
:
;byte b = 0
;)Console.WriteLine(b
;b = 255
;)Console.WriteLine(b
;b++
;)Console.WriteLine(b
;b--
;)Console.WriteLine(b

' "

128

:
0
255
0
255
) b ,(byte
) ,(255 1 - ) .(0
, 1 ) (0 ).(255
, :
//
, //.
;byte b1 = -8
;byte b2 = 260
0 1 - ,
)( . ,
.2 -
1 ,
0 . ,
) 27 ,(28
,
.
C# - sbyte byte ,
. 7 ,
0 ,127 - 0 ,(27 1) -" 128
. 128 - , ,
. sbyte (-128) - 127
)" 256 ( ) (-27 ).(27 1
:
;sbyte s = 127
;)Console.WriteLine(s
;s++
;)Console.WriteLine(s
;s--
;)Console.WriteLine(s
:
127
-128
127

' "

129

,

.
, :
//
, //.
;s = 128
;s = -129
2 -:
) Signed( ) ,(-/+ .
) Unsigned ( .
:
;)"Console.WriteLine("int:
;int x = int.MaxValue
;)Console.WriteLine(x
;x++
;)Console.WriteLine(x
;x--
;)Console.WriteLine(x
;)"Console.WriteLine("--------------------------------
;)"Console.WriteLine("uint:
;uint ux = uint.MaxValue
;)Console.WriteLine(ux
;ux++
;)Console.WriteLine(ux
;ux--
;)Console.WriteLine(ux
:
int:
2147483647
21474836482147483647
-------------------------------uint:
4294967295
0
4294967295
uint/int 4 -
232 , int signed uint - .unsigned

,MaxValue )" .(MinValue
: ' .

' "

130


.
:
,
. , " :
num * 10power
:
- 275 * 10101 104 ,
6 - 3: ) (275 3- ).(101

)( .,
275 * 10101 6 - ,276 * 10101 :
.
float - :
float 3 -:
b
8.........

31

S A
0 1....7

).(-/+
1...7 .
8...31 .
a b- :f
;exp = a 64
; frac = b / 222
)if (frac>2
{
;frac = frac * 2
}
else
{
;frac = frac + 2
}
f = 4exp * frac
0 .
:2 -
.1 ,3.4 * 10
.2 .1.4 * 10-45
+38

+38

-3.4 * 10

' "

131


, .
. )" (.
,
.
: 65 .A
,"
, .
" ."ASCII
ASCII -American Standard Code for Information Interchange.
ASCII 128 .0-127
) "
.(American
, . ASCII 256
.0-255 128 ) (128-255 ,
.
ASCII:
48-57.
65-90 .
97-122 .
128-154 , ) (.
31 0 . ,
.
:
7.
8 ) '.('/b
) Tab 9 '.('/t
10 ) '.('/n
13 ) '.('/r
: ASCII
' .
ASCII 0-255 byte
.
,ASCII - ,
,
. ,
ASCII - .
' "

132

) Unicode( .
216 ) 0 ,(65,535 - ,
256 . Unicode
ASCII -.
:Unicode
1488-1514 .
1456-1475 .
Unicode - byte 2 .

char
C# - ) char .character"-" "'"( .
Unicode char
.byte 2
! ,char
.
:
ch //char
;char ch
. //.
;'ch = 'a
//.
;)Console.WriteLine(ch
:
a
) (implicit casting char
,int .Unicode
, a " :97
//.char
;'char ch = 'a
n . //.ch
;int n = ch
//.
;)Console.WriteLine(n

' "

133

:
97
)" ( int
,char " .
//.
;char ch = (char)97
//.
;)Console.WriteLine(ch
:
a
:
. //
,char 1- //.
)for(char ch = 'A' ; ch < 'J' ; ch++
//.
;)Console.WriteLine("{0}-{1} ", (int)ch, ch
:
65-A
66-B
67-C
68-D
69-E
70-F
71-G
72-H
73-I
:
//.
;)" Console.Write("Enter one character:
. //.char.Parse() -
;))(char ch = char.Parse(Console.ReadLine
//.
)'if(ch >= '0' && ch <= '9
;)"Console.WriteLine("ch is numeric
else
;)"Console.WriteLine("ch is not numeric

' "

134

" , .
: " )( char.Parse
.char , "".
)( char.Parse :
)( char.ToUpper .
)( char.ToLower .
)( char.IsDigit .
'.

string
char ,
string .
string "" .char string
,(char[ ]) char . char
string .
:
;"string str = "This is string
)for (int i = 0; i < str.Length ; i++
;)]Console.Write(str[i
:
This is string
, ] [
,string ) (char .str[i] ,
char , .char
, string ) ,(Length .
string - string - ,
string - :
//.
;"string str = "This is string
//.
;'str[0] = 'x

' "

135

,string -
.
" string - , ] [
, string
.
string .
:
//.
;"string str = "This is string
)( IndexOf //
"//."is
;)"int idx = str.IndexOf("is
)( LastIndexOf //
"//."is
;)"int lastIdx = str.LastIndexOf("is
//.
;)Console.WriteLine("The index of \"is\" = {0}", idx
Console.WriteLine("The last index of \"is\" = {0}",
;)lastIdx
:
The index of "is" = 2
The last index of "is" = 5
IndexOf ,str
. ,
.-1 LastIndexOf
.
: ,
string ) (. )( .string.Format
, .Visual Studio
' .Visual Studio

' "

136

:
.1 ,
.
.2
, .
.3 .
.
.4 ) !
(.
.5 .
.6 .ASCII -
.7 .
.8 2 .
. : " "ABC "."Abc
.9 )(.
.10 ) .(int.Parse
.
.11:
:string
.

)(Contains

)(StartsWith

)(EndsWith

)(Insert

)(PadLeft

)(PadRight

)(Remove

)(Replace

)(Split

)(Substring

ToLower() .
ToUpper() .
.

)(Trim

, .
' "

137

11 Main -

:
Main -

Main -
, Main - :
)static void Main(string[] args
{
}
Main - )] [.(string
Main - . Main
- .exe -
, ,
. ,
.
.
, Main -
. ,Main -
.exe - Run - Start .Windows

' "

138

Run - ) ,(exe
.
, param1 (param2 - :
)static void Main(string[] args
{
//.
)for (int i = 0; i < args.Length ; i++
//.
;)]Console.WriteLine(args[i
;)(Console.ReadLine

:
param1
param2
:
class Program
{
)static void Main(string[] args
{
//.
;string action = string.Empty
;int num, num2

' "

139

//.
if (args.Length < 3)
{
// , 3-
//. ,
PrintUsage();
return;
}
// ,
// , .
//.int-
action = args[0].ToLower();
num = int.Parse(args[1]);
num2 = int.Parse(args[2]);
//. ,
switch (action)
{
case "add": Add(num, num2);
break;
case "sub": Sub(num, num2);
break;
case "mul": Mul(num, num2);
break;
case "div": div(num, num2);
break;
default: Console.WriteLine("Action is not
supported.");
break;
}
}
//.
static void PrintUsage()
{
string usage = "usage:\r\n";
usage += "add 2 3 - returns the result
2+3\r\n";
usage += "sub 7 3 - returns the result
7-3\r\n";
usage += "mul 2 3 - returns the result
2*3\r\n";
usage += "div 8 2 - returns the result
8/2\r\n";
Console.WriteLine(usage);
}

' "

140

for
for
for
for

//.
)static void Add(int num, int num2
{
;)Console.WriteLine(num + num2
}
//.
)static void Sub(int num, int num2
{
;)Console.WriteLine(num - num2
}
//.
)static void Mul(int num, int num2
{
;)Console.WriteLine(num * num2
}
//.
0 //.
)static void div(int num, int divider
{
)if (divider == 0
{
Console.WriteLine("Division by zero is not
;)"!allowed
}
;)Console.WriteLine(num / divider
}
}
,
. ,
, " ) return - Main
, ( . ,
, case-
. , ,
. switch , -
switch . ,
.
Visual -
,Studio ,Visual Studio -
. , ,
, Run - .
) Project --> MainArgsExample Properties
MainArgsExample (.
' "

141

Debug , Command Line


Arguments .

' "

142


.
:Console Application
class Program
{
//.
static void PrintMenu()
{
Console.WriteLine("This is the application's
menu");
Console.WriteLine("-----------------------------");
Console.WriteLine("1. Plus");
Console.WriteLine("2. Minus");
Console.WriteLine("3. Multiply");
Console.WriteLine("4. Divide");
Console.WriteLine("5. Exit");
Console.Write("Enter your selection: ");
}
static void Main(string[] args)
{
//.
int selection;
//. .do..while
do
{
//.
PrintMenu();
//.
selection = int.Parse(Console.ReadLine();
//. ,
//
//.
switch (selection)
{
case 1: Plus();
break;
case 2: Minus();
break;
case 3: Multiply();
break;

' "

143

;)(case 4: Divide
;break
case 5:
;)"Console.WriteLine("Good by...
;break
default:
Console.WriteLine("Invalid
;)"selection
;break
}
//,
. , //.
;)} while (selection != 5

}
}

" .
, 2 , .
. ,
) .(5
PrintMenu .
Main - :
.1
.2
.3
.4
.5
.6

.PrintMenu
.
.
) 5( .
.
) 5(.

' "

144

) :(Plus
)(static void Plus
{
//.
;int n1, n2, res
, //.
;)" Console.Write("Enter number1:
;))(n1 = int.Parse(Console.ReadLine
;)" Console.Write("Enter number2:
;))(n2 = int.Parse(Console.ReadLine
. ,//.
;res = n1 + n2
//.
;)Console.WriteLine("Sum = {0}", res

, .
,
. ,case -
.

' "

145

.NET - '
:Built in CLR -
, C# ,
.NET - .NET Framework -
) ( C# - ,(structures)
.

.NET Framework
type

C#
Type
-
bytes
bool
System. Boolean
1
byte
System.Byte
1
sbyte System.SByte
1
char
System.Char
2
decimal System.Decimal

16

double System.Double

float

System.Single

int

System.Int32

uint

System.UInt32

long

System.Int64

true or false
0 through 255
-128 through 127
0 through 65535
0 through +/79,228,162,514,264,337,593,543,
950,335 with no decimal point;
0 through +/7.9228162514264337593543950
335 with 28 places to the right of
the decimal; smallest nonzero
number is
+/0.0000000000000000000000000
001 (+/-1E-28).
-1.79769313486231570E+308
through
-4.94065645841246544E-324 for
negative values;
4.94065645841246544E-324
through
1.79769313486231570E+308 for
positive values.
-3.4028235E+38 through 1.401298E-45 for negative
values; 1.401298E-45 through
3.4028235E+38 for positive
values.
-2,147,483,648 through
2,147,483,647.
0 through 4294967295
-9,223,372,036,854,775,808
through
9,223,372,036,854,775,807.

' "

146


Unsigned 8 bit
Signed 8 bit
16bit
Unicode
,128bit
28

64 bit Float

32 bit Float

Signed 32 bit
Integer
Unsigned 32 bit
Integer
Signed 64 bit
Integer

ulong

System.UInt64

object

System.Object

short

System.Int16

0 through
18446744073709551615
Any type can be stored in a
variable of type Object.
-32,768 through 32,767.

0 through 65535

ushort System.UInt16
string

System.String

0 to approximately 2 billion
Unicode characters.

' "

147

Unsigned 64 bit
Integer


Signed 16 bit
Integer
Unsigned 16 bit
Integer

' ASCII

' "

148

' "

149

' "

150

' XML -
, ,
" " " ".
, ,
, .
, C# -
, .XML ,
,Properties , XML 'XML .
.
, ) ,(///
:
summary .
param .
returns .
.XML
, .
:
/// - ) (///
:
><summary
></summary
><param name="num1"></param
><param name="num2"></param
><returns></returns
)Sum(int num1, int num2
;return num1 + num2

///
///
///
///
///
///
int
{
}

: ,
. . ,
, ,param
.returns

' "

151

)(:Sum
><summary
Calculates the sum of two numbers.
></summary
><param name="num1">First number to calculate</param
><param name="num2">Second number to calculate</param
><returns>The sum of the two numbers</returns
)Sum(int num1, int num2

///
///
///
///
///
///
int
{

;return num1 + num2


}
. , Visual Studio -
Tool Tip - ,IntelliSense -
, .

.Tool Tip - .

' "

152

' Debugger -

.
,
.
:
.
, .0
class Program
{
)static void Main(string[] args
{
;string str
;int num, pow
;)" Console.Write("Enter Number:
;)(str = Console.ReadLine
;)num = int.Parse(str
;)" Console.Write("Enter Power:
;)(str = Console.ReadLine
;)pow = int.Parse(str
;)int res = Power(num, pow
;)Console.WriteLine("res = {0}", res

)static int Power(int num, int pow


{
;int res = 0
)for (int i = 1; i <= pow; i++
{
;res *= num
}
;return res

, .
, .
Debugger .
,Visual Studio - .Debug
, .
Debugger - .

' "

153

:Debug
F5 .
F10 .
F11 .
) Debug (F10 :

-
Debugger

F10 :
;)(str = Console.ReadLine

Console - .
.Enter
F10 :
;)num = int.Parse(str

' "

154

, .
) (Autos
" "20 .str
) num - .(0
) (3 :
;)int res = Power(num, pow

' "

155

) F11 ( ,
:Power

num, pow .
) (Locals .
,F10 res ,0 -
,0 )
.(F10
) ,(Break Point .
,F5 ,
, .
F9 ,
, .
. -
.debug

' "

156

, ,
:

F5 :

' "

157

)
.(Break Points
:Debugger -

Autos .
Locals .
Break Points Break Points -.
Call Stack ) (.
Watch , '
. .Watch

.Debug --> Windows


:Watch

:
.1 .num
.2 .i==0
.3 .res
- ,Watch -
.

' "

158

'
, .
,
. , .
,C# - )(Syntax
.
,Visual Studio -
MSDN - Microsoft:
http://msdn.microsoft.com
Visual Studio - Help
:

2 :
Search .
Index .
Search , ,
.

' "

159

if :
"" if-else statement in c#
:

' "

160

Index .Index
,System.Math ,
, '.

:
/ '.
.
OnLine .MSDN
.
.Microsoft
).(See Also
...

' "

161

'
.Net Framework ,C# ,...
http://forums.johnbryce.co.il
' " .
http://msdn.microsoft.com
MSDN .Microsoft
http://msdn2.microsoft.com
MSDN2 .Microsoft
http://www.corner.co.il
' C#.OOP -
http://www.mh2000.co.il
.
http://www.developers.org.il
.
http://www2.eitan.ac.il/dotnet
.Net .C#, VB.NET
http://www.csharpcorner.com
- C# .
http://www.dotnetheaven.com
.Net .
http://www.windowsforms.com
Windows Forms .
http://www.asp.net
ASP.NET .Net -

' "

162

You might also like