.net 2008

Transcription

.net 2008
2
3
4
5
... ‫ﺗﻘﺪﻳﻢ‬
.
‫א‬:‫אذ‬
‫ א‬، ! "‫א و‬$%&'() *+, ‫'ل א‬.‫ אن א‬01‫א‬
A$ 9 :‫ق א<زא‬1 >‫ אد‬2343 @‫( و‬77) 2343 53 .NET Framework
‫ل‬B $"C 5D E$‫ ! א‬،FD G%‫ אو وא‬HI‫ א‬J‫ א‬KL H'1 M 23‫ א‬
‫א‬+! NOPQ‫ و‬،:ND E$R S 0QHT3 U :FV : W‫ وא‬X‫ א‬Y!Z[‫א‬H 53'S‫و‬
‫ 'ل‬X‫ א‬Y4F 0F 4‫ א‬K^> W‫ وא‬vb4arab 0.'\ ‫'ل אول‬J\‫ א‬:]
._‫א‬
P‫א א‬WS a‫ و‬bI ،:ND E$R U\‫ א‬P‫ א‬HI‫ א‬U :.‫ل د‬B $"‫ א‬X'‫ א‬U ‫ ^
א‬c`Q 3
Q‫و‬،:%d93‫و‬234\‫א‬:%d33efQ'g!،h‫א‬$N\‫א‬i^‫و‬3'\‫א‬H`O9‫א‬53Kjk‫دא‬$‫א‬
'g!(Source CodesQH$V\‫א‬:‫א‬O,$V.‫)א‬lS‫'א‬%5D3‫א‬،‫א(م‬n3o‫و‬oP‫א‬Kp5Q‫א‬53‫א‬$%
t‫وא‬Real World Cases77L‫א‬h9L‫א‬53
^P‫א‬1qrgsQt‫^א‬39‫א‬HI‫א‬U‫ع‬$Q‫و‬5NOQ
.a7!iPO‫א‬vT^3‫א‬WOPQ9‫و‬، %‫ אمא‬%D234Fg(
‫אن‬b'VI‫و‬..zFbD.U..z‫'دא‬1.${‫אن‬GV‫א‬53":OQ1‫א‬PL‫א‬A$‫'لא‬7!،XP‫'صא‬Vx
qKM!‫א‬${‫אن‬GV‫א‬53":‫'لא‬7‫אن‬5P>ND's'}g1‫و‬RF‫!"و‬,
I1.NS5PQ_
$5F!"!,
IqCNS‫'ن‬PQ_‫אن‬b'VI‫و‬..hq‫א‬53I‫אא‬WSK&U(.NET~g%'3)
،Java)hN75D‫م‬Q9‫א‬lWSUQ$L‫א‬b‫א‬،gj‚‫و‬gƒk7377hq4‫א‬hq€3
‫א‬WS‫ و‬،
$ „‫ א‬gNF! g, 4‫ א‬hq ‫'ن‬P ‫د אن‬P‫ و‬،(...LINQ ،WPF ،DirectX ،COM،.NET
G D'F nD $FD‫ א‬−:3$73 nD zN– XP‫א א‬WS GP! ،: €3H 3 Rb nD K‫
د‬I XP‫א‬
v,‫م‬$7QKa7!‫א‬WS@،.NETN7‫'ل‬X535PF(‡‫א‬...،VB،C#)O†hqE$R
!q53^]QH$V\‫א‬h‫א‬OT‫א‬
$Q$ ‫ دون‬Visual Studio 2008 XP‫'אن א‬N GP‫ א‬53 (‫א‬$% W‫)א‬HI9‫ˆ ن א‬1N\‫א א‬WS 53‫و‬
NRb‫(وא‬Y4\‫א‬T35‰)$'$7!،C#2343‫אو‬Basic2343:ƒ‫א‬1V3‫א'م‬$$%'Q !،q‫א‬
.".NET43‫"Šل‬jD„‫א‬FNB
6
K^3.O30s‫'א‬3„‫'א‬%WI]Q‹53‫و‬،.NET7N9‫א‬0s‫אزא\'א‬XP‫אא‬WS1qQ
GP‫ א‬K F .GQ‫ و و‬،Windows Forms ‫ ذج‬،Database Programming h‫ א‬$D‫'א‬.
.NET KF‫א‬H‫א‬53^‫א‬H‫א‬$b9‫א‬03hg&t‫)وא‬i$Q$Ž‫א‬hN7‫א‬KS`Q_:‫א‬3$ND^‫א‬
K^et‫ وא‬WPFN7‫و‬،Data Entitiesh‫א‬03‫م‬$7\‫א‬K3:%'\‫ א‬LINQN7K^3(Framework
!' t‫ وא‬WCF N7‫ و‬،Portable User Interfaces K7N . ‫אم‬$+9‫ א‬hg%‫ وא‬4 ‫دم‬7‫ א‬KŽ‫א‬
01Q‫אאن‬$%H‫د‬N‫א‬530s‫'א‬3lWS‫و‬.Distributed ApplicationsD‫א\'ز‬h71%‫א^א‬9'
.$‫وא‬XUg‫*د‬+,
XP‫ˆא‬U'Q5‫'عو‬%53cqQ9‫و‬5FQ9W‫)א‬Q$7‫אא‬WSiz‫א‬. U]1I€PH‫'نא‬P$.،‫
א‬IC
.NET_DKI$ROV‫א‬G7C$‫‹א‬5‫وא‬3YF^‫א‬.‫و‬53:sC3OPQW،(:Op3‫و‬
.g‫א'א‬0‫و‬C53
‫א‬−−
al-asiri.COM
‫ﻣﻮﺟﺰ اﻟﻜﺘﺎب‬
‫ﻣﻘﺪﻣﺔ اﻟﻜﺘﺎب – ﻣﻘﺪﻣﺔ اﻹﺻﺪار اﻟﺜﺎﻧﻲ‬
‫ﻋﻦ ‪Visual Studio 2010‬‬
‫ﻧﺒﺬة ﻋﻦ اﻟﻤﺆﻟﻒ‬
‫ﺷﻜﺮ وﻋﺮﻓﺎن‬
‫ﻫﺬا اﻟﻜﺘﺎب‬
‫ﻣﺤﺘﻮﻳﺎت اﻟﻜﺘﺎب‬
‫اﻟﺒﺎب ‪ : 02‬ﺗﺤﻤﻴﻞ ﻧﺴﺨﺘﻚ اﻷوﻟﻰ ﻣﻦ ﻓﻴﺠﻮال ﺳﺘﻮدﻳﻮ ‪2008‬‬
‫اﻟﺒﺎب ‪ : 03‬اﻟﺠﺪﻳﺪ ﻣﻊ‪.net 2008‬‬
‫اﻟﺒﺎب ‪ : 04‬ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ‪ .net‬اﻟﺮﺋﻴﺴﻴﺔ‬
‫اﻟﺒﺎب ‪ : 05‬اﻟﻮاﺟﻬﺔ اﻷﺳﺎﺳﻴﺔ ﻟـ‪Visual Studio 2008‬‬
‫اﻟﺒﺎب ‪ : 06‬ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ ﻓﻲ ‪ .net‬اﻟﺠﺰء اﻷول‬
‫اﻟﺒﺎب ‪ : 07‬ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ ﻓﻲ ‪ .net‬اﻟﺠﺰء اﻟﺜﺎﻧﻲ‬
‫اﻟﺒﺎب ‪ : 08‬ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‪OOP‬‬
‫اﻟﺒﺎب ‪ : Interfaces - 09‬اﻟﻮاﺟﻬﺎت‬
‫اﻟﺒﺎب ‪ : 10‬اﻷﺧﻄﺎء واﻗﺘﻨﺎﺻﻬﺎ‬
‫اﻟﺒﺎب ‪ : 11‬اﻟﺘﺠﻤﻴﻌﺎت‪Collections‬‬
‫اﻟﺒﺎب ‪ : 12‬اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ‪.net 2008‬‬
‫اﻟﺒﺎب ‪ : 13‬اﻹدﺧﺎل واﻹﺧﺮاج ﺗﺤﺖ‪System.IO‬‬
‫اﻟﺒﺎب ‪ : 14‬ﺑﺮﻣﺠﺔ اﻟﻨﻮاﻓﺬ‪Windows Forms‬‬
‫اﻟﺒﺎب ‪GDI+: 15‬‬
‫اﻟﺒﺎب ‪: Windows Presentation Foundation16‬‬
‫اﻟﺒﺎب ‪ : 17‬ﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت ﺑﺎﺳﺘﺨﺪام‪ADO.net‬‬
‫اﻟﺒﺎب ‪LINQ: 18‬‬
‫اﻟﺒﺎب ‪WWF: 19‬‬
‫اﻟﺒﺎب ‪WCF: 20‬‬
‫اﻟﺒﺎب ‪ : 21‬ﻧﻘﺎط ﻣﺘﻘﺪﻣﺔ‬
‫اﻟﺒﺎب ‪ : 22‬ﺗﻄﻮﻳﺮ اﻟﻤﻮاﻗﻊ ﺑﺎﺳﺘﺨﺪام‪ASP.net‬‬
‫ﺧﺎﺗﻤﺔ اﻟﻜﺘﺎب ‪ ،‬وﺷﻜﺮ‬
‫اﻟﻤﺼﺎدر‬
‫‪7‬‬
‫‪9‬‬
‫‪11‬‬
‫‪12‬‬
‫‪13‬‬
‫‪14‬‬
‫‪15‬‬
‫‪29‬‬
‫‪35‬‬
‫‪45‬‬
‫‪63‬‬
‫‪73‬‬
‫‪97‬‬
‫‪129‬‬
‫‪167‬‬
‫‪183‬‬
‫‪197‬‬
‫‪211‬‬
‫‪277‬‬
‫‪305‬‬
‫‪349‬‬
‫‪361‬‬
‫‪411‬‬
‫‪477‬‬
‫‪499‬‬
‫‪499‬‬
‫‪509‬‬
‫‪509‬‬
‫‪521‬‬
‫‪539‬‬
‫‪539‬‬
‫‪602‬‬
‫‪603‬‬
8
9
‫ﻣﻘﺪﻣﺔ اﻟﻜﺘﺎب‬
.YBC:Rb‫و‬:ŠnD‫و‬$F)N،Y\‫وא‬z‫א‬f,CnD‫وא~ م‬i V~‫وא‬،‫א‬5"‫אא‬
.ً g‫ن‬L‫א‬K{€C‫ ًو‬g:%39‘Kg9g‫א‬
‫!`'אل‬A$N3nDg,CH‫א‬$3nDhF‫وسא‬H$‫א‬530F{5DiHD'SXP‫אא‬Wg!...$3C
”‹53‫و‬، 20084F‫ول‬CU‫א‬$FrgN3zg9‫”א‬،i$Q$Ž‫ א‬.net 2008hN7‫'ل‬X
.‫א'م‬Q$QYl${W‫א‬XP‫'א‬SˆN3X5FsgDi$Q$%h!s‫א‬0s‫و‬03gF{
Andrew opF Pro C# 2008 and the .NET 3.5 PlatformXiz‫א‬.$hz%XP‫א‬iP!
،€!'‫و‬PQ353i$Q$Ž‫ א‬C#+N*•3KPQ<–‫א‬qً 3ً%3h$%‫و‬، Troelsen
G—C i%'3iH'V €1—CD‫ز‬C‫ن‬C01CcC9‘‫א‬q0%3KF€F.‫א‬D‫د‬C9C03‫و‬
UˆF‫א‬01 MSDN53a‫وא‬H„‘C$QF‫و‬، VB‫ و‬C#:q .net‫لאل‬Uj‫طא‬7N‫א‬
.i$nD‫ل‬K
ˆQ3K3KV!Qg$f‫ن‬Cً ^3c3(N !،317Nً 3,ً VO${5}HXP‫אא‬WSU
g'‫و‬g37Q‫و‬i‫אدא‬lWSN‫'ل‬h3'\‫א‬53H$.4CnDf‫א‬01NP‫و‬،h‫אدوא‬$]
Dh71H'1FD‫د‬53^C .netNg!: I5301‫–ن‬f$gQXP‫אא‬Wg!، KI‫دא‬
.O+\‫א‬q‫א‬h'P303g3O‫و‬I‫א‬$‫א‬gNgO‫ن‬C‫دون‬
SNFt‫א‬SO\‫ˆ™א‬1Q':F‫'م‬7FDˆ1AI‫وא‬iZO‫א‬Y$`‫ذ‬53—‫و‬
h Y $` ‫א‬W ... XP‫א א‬WS 53 i$jO‫ א‬53 4C KVR F‫ˆ א‬1 (N‫ א א‬a
X%‫'ل‬.C‫ن‬Cc3(N95Pi
qV‫א‬h71‫^وא‬3‫א‬53
‫د‬$DXP‫אא‬WSUi‫'د‬%'\‫א'אدא‬
.i'1xi'1Iً ^3ˆ1‫אא‬WS
،‫ن‬1T‫وא‬O5F!]1I53‫ن‬3‫و‬،‫א‬5F!X‫'א‬b53:!‫ن‬F!،ً‫א‬$O3XP‫אא‬WS‫'ن‬PQ‫ن‬C‫]لא‬C
.K‫א‬z‫د‘„'א‬k‫وאא‬
10
‫ﻣﻘﺪﻣﺔ اﻟﻨﺴﺨﺔ اﻟﺜﺎﻧﻴﺔ‬
z1I‫א‬53‫د‬$Dv b+N‫א‬lWSU€F.،XP‫אא‬Wk^‫א‬+N‫א‬S‫אšن‬S$STt‫א‬+N‫א‬lWS
‫א‬WSA'3YUFSFAICi30F`i'D$‫א‬HC‫و‬،„‫אو‬+N‫א‬Ui‫'د‬%'3€t‫א‬
.XP‫א‬Ui‫'د‬%'\‫א‬z1I‫א‬nDhgN‫وא‬h‫א‬Z.9‫لא‬H‫א‬4DXP‫א‬
،Visual Studio 2010‫و‬.net framework 4.0H‫و‬$b03‫و‬،2009NI‫وא‬CU]+N‫א‬lWSًMQC
:NDQ$L!3‫€א‬V‫א‬C9‘،i$Q$Ž‫א‬hN7‫ضא‬QgN‫א‬U.‫א!אد‬UP!C€N0.‫א'א‬U‫و‬
n7Q‫و‬،Wh‫
א‬q‫دون‬SFq‫א‬Nbœ‫א‬h‫א‬K(‫و—ذ‬5P،K73XP‫ج‬d
„‘]‫א‬ROV‫א‬U‫و‬،gDK3‫א‬O‫و‬i$Q$Ž‫א‬hN7‫א‬nD‫ ع‬0.‫א\'א‬0%‫نא‬CD
.$Q$,HVIi$Q$Ž‫א‬hN7‫وא‬h.‫و‬O‫\!א‬a‫وא‬H
Qž‫א‬gN3W*IC،^S‫אو„و‬+N‫א‬7NU$D530FŽ:%'3PT‫א‬QgN‫א‬U‫و‬
g^Q‫ن‬C‫'א‬D‫د‬C‫وو‬$D53KPًMQCPT‫א‬HC،XPK3FD‫'و‬q7N‫م‬$.W‫א‬Rs
.S‫'د‬g%nD
11
2010 ‫ﻓﻴﺠﻮال ﺳﺘﻮدﻳﻮ‬
Visual Studio 2010H‫א‬$b‫א‬0353‫א‬gND€!'‫و‬PQ3€NDCt‫وא‬.net framework 4.0+03
Y4Fk I53i
h g€!'‫و‬PQ3€3$.Microsoft Office 2010 P\‫א‬23‫א‬4‫א‬3‫و‬
.Windows 7hF‹‫و‬،€Z–‫א‬h71‫و‬Office03K3P‫א‬،IDE‫אمאل‬$+‫א‬$bnDz‫'א‬
P3‫א‬،ASP.net 4.0032010'Q‫`'אل'د‬O7!3WPF 4.053i$Q$%iH‫א‬$b‫و'!€א‬PQ3‫م‬$7
53$Q\2010_DU$Q$`3$7\‫א‬lWSnD‫ ع‬9‫א‬NP>،:! I‫و‬Silverlight‫אل‬h71zN
:KbO‫א‬
‫رابط‬
http://www.vb4arab.com/vb/showthread.php?p=225389
‫א– ع‬01!s‫א‬h‫Ÿא‬N€3$.t‫وא‬،i$Q$Ž‫א‬+N‫א‬03C# 4.0‫!ق‬H‫!א‬q‫א‬$bnD3C
:NSt‫و‬$353kKVOnD
‫رابط‬
http://ahmedgamal-technical.blogspot.com/2009/09/c-40.html
.ًMQCKF‫א‬H‫א‬5FsF#i$Q$Ž‫א‬q‫א‬23$!s9،vb.net‫ل‬N3‫@א‬O
:K3Pi$Q$Ž‫طא‬7N‫א‬KbO:!€!'‫و‬PQ353a‫אאא‬WSnD‫א– ع‬KM!C،QgN‫א‬U
‫رابط‬
http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx
‫ﻋﻦ اﻟﻜﺎﺗﺐ‬
12
. ‫أﺣﻤﺪ ﺟﻤﺎل ﺧﻠﻴﻔﺔ ﻋﺒﺪاﻟﻌﺎل‬
[email protected] : ‫اﻟﺒﺮﻳﺪ اﻹﻟﻜﺘﺮوﻧﻲ‬
. 00966545663382 – 0020108011792 : ‫اﻟﻤﺤﻮل‬
: ‫اﻟﺴﻴﺮة اﻟﺬاﺗﻴﺔ ﺑﺎﻟﻜﺎﻣﻞ ﺗﺠﺪﻫﺎ ﻫﻨﺎ‬
http://www.vb4arab.com/vb/uploaded/3/01256435433.doc
‫مشرف عام منتديات فيجوال بيسك للعرب‬
www.vb4arab.com
‫ﻣﺪوﻧﺎت ﺷﺨﺼﻴﺔ وﺗﻘﻨﻴﺔ‬
www.AhmedGamal-Space.blogspot.com
www.AhmedGamal-Technical.blogspot.com
www.AhmedGamal-NET.blogspot.com – English ‫ﻣﻠﺨﺼﺎت ﺳﺎﺑﻘﺔ‬
‫ﺷﻜﺮ وﻋﺮﻓﺎن‬
‫ﺷﻜﺮ وﻋﺮﻓﺎن‬
13
53
^P‫'نא‬7RQ‫ص‬+,]Q'Fj.0.‫א'א‬U:Q$XP‫אא‬WSop3‫و‬،‫س‬N‫א‬PTQ953‫א‬PTQ9
5PQ_XP‫نא‬Cً3‫دو‬WC‫ذن‬53f$SC،NSSzƒC‫د‬C‫ن‬Cƒ‫אא‬W،zD$‫وא‬zN^‫א‬
s‫א\'א‬iF^‫א‬hz%n‫ص‬+,‫א‬z9pS53i‫د‬O9‫وא‬fً‫א‬IŠ‫ًو‬9‫و‬CD‫א‬KM!9'W‫'ن‬P
(:%'‫א‬Nj'‰)Gb
‫ذא‬ ًbIً‫א‬P,‫م‬$.C‫א‬W،‫אšن‬Q$QYS‫א‬t‫א‬
‫زאد‬،4‫_א‬D UH3:%'U‹‫
א‬:P‫ (ن‬net.‫ ل‬I53J,KFDH‫‹)א‬
‫'ن‬C‫ن‬C‫א‬53'%HC‫א‬W،ً‫^
א‬F`53 4Cg!1DCFPXP‫אא‬Wk:>$7c!,‫ن‬C‫ذ‬nD
.c3:.'QF!:j%HGIC9C‫و‬،‫ذ‬C5&5$ND
‫د‬$%CF،XP‫אא‬WSg{U:97353ً‫^
א‬h$O‫' א‬3$F)‫س‬$NgFًMQC‫'ل‬b'3PT‫א‬
W*IC،‫אא¡ل‬WSUXQ$7g`TnD:!T3‫و‬X‫!`'אل‬A$N3iH‫–دא‬PT‫א‬
...‫אم‬P‫א‬i'I‫א‬.‫و‬،H$$"Cž‫وא‬0.'\‫א‬Q$3ˆ‫אא‬$D‫אذ‬gN3
،XP‫אא‬WS7Ng$D3nD gN‫א‬$F)‫س‬$Ng\‫א‬، 'D$"C‫س‬$Ng\‫א‬53KPًMQCPT‫א‬
XP‫ א‬iz‫א‬7 g.‫ و‬53 z% £QO k P,C ، z1I − ‫ אل‬9‫ – و‬I € XP‫ א‬53 „‫ אو‬¢N!
.i
I‫א‬+N‫אجא‬I‘K.K,\‫א‬lWS¤H‫א‬$nD$D3‫و‬g%'‫و‬
... ‫ﺷﻜﺮ ﺧﺎص ﺟﺪًا‬
7N U g$D\ a7! @ ‫دل‬D ‫ن‬SH' $Ng\‫ وא‬، YF1‫ 'א‬$‫ و‬G1‫س א‬$NgF ‫ ًא‬$% ‫ص‬I P,
FV53ً‫א‬z$KPT‫אא‬Wg‫'ن‬P:%‫א‬I‫'א‬3.53S33Cl‫א‬W‫א‬XP‫–نא‬5P‫و‬،XP‫א‬hQ')
3ً‫^
א‬kH$.C‫و‬kP,HC،f q‫א‬FVzg‫وא‬،N‫^وא‬39‫وא‬P‫אضوא‬X'C‫و‬hROV‫א‬
.ngCUXP‫אא‬WS‫אج‬I–$g%53l'W
،NSl‫ذ‬C!i‫א‬W‫א‬cI_HWD‫وא‬،XP‫אא‬WS‫אدو‘ج‬$D‘UgN3h$O‫א‬53KPًMQC‫م‬DPT‫א‬
zN^‫ א‬j.$b‫א‬0FŽ‫و‬01S،t‫א‬H‫د‬U‫و‬C3‫א‬UgN3h$O‫א‬530FŽًMQCPT‫א‬
.XP‫אא‬WS‫م‬e–:D‫وא‬:7!'nDً‫א‬IŠ‫ًو‬9‫و‬C$FL‫ذא‬K.‫و‬،
‫ﻫﺬا اﻟﻜﺘﺎب‬
14
`3 QH{ h3 D S S
—‫ و‬Office، Windows K^3 XP‫א א‬WS U iH'W\‫ א‬23‫א‬4‫ א‬zƒ‫ א‬−
.gRb9
.gQ')5D‫ول]ل‬p3
—GP‫نא‬C9‘،XPF‫א‬i‫א\د‬hQ')G—‫א‬HI‫”א‬−
53 ‫ذن‬C ‫ون‬$ H{ ‫ —ض‬:3‫א‬$+‫ אو א‬:Q‫ אو 'ز‬:D ˆd 9‫ و‬، opF &'O) XP‫'ق א‬7 −
.op\‫א‬
gN3$‫وא‬l{‫א‬X‫و‬C
—‫'אد‬C‫'د‬%‫و‬0N>9‫א‬WS5P‫و‬،XP‫א‬KI‫دא‬gQ{”‫א'אد‬G—C −
.‫و‬ZP–‫א‬$QnDH{2j€H‫אً'א‬$‫א]'ن‬W،VB.net‫و‬CC#a7!
.:4+c‫א‬H'$C‫ً]'ن‬Q
‫و‬Cًj 3‘ًJ1Ih$%‫'و‬7Q1‫@א‬ON‫و‬−
‫ ل‬K7N‫ א‬hFD „‘ iH,–‫€ א‬e‫'ل و‬7N3 gN3 K ، GP‫ א‬o] 53 € i‫'د‬%'\‫ ™ א'אد א‬−
.RRbiH'VlH$V\iH,9‫و_א‬Cs‫—
وא‬K7C5DHWQop\!‫ذ‬03‫و‬،S‫'د‬%‫و‬
15
‫ﻣﺤﺘﻮﻳﺎت اﻟﻜﺘﺎب‬
‫א‬WS ، X‫'لوא'א‬VO‫ א‬53 ‫د‬$D4D .net 2008 ‫ ًא‬$Q$‫ و‬.net _D hC 53 D'F XP‫א א‬WS MQ
:S%'3
XP‫ א‬G 5D h‫س و‬gO‫ وא‬XP‫ א‬hQ') 5D 3$73 :' 53 ^C @ X‫א א‬WS : ‫ אول‬X‫א‬
..O9‫وא‬
‫`'אل‬O‫ א‬53 + KFR zŽ‫א א‬WS ¤‫'د‬7Q net 2008. _D U ‫ ق‬1–‫ א‬C$ NS : ^‫ א‬X‫א‬
.O+\‫א‬h‫א‬H‫א‬$b–‫א‬Y.Z‫א‬O‫'وאولو‬Q‫'د‬
5DiWiV†iH'V‫د‬Q،net._DU‫ ق‬1–‫א‬nD¤OR*V†X‫אא‬WS:^‫א‬X‫א‬
@ X‫א א‬Wg! K. 53 ً 43 5P _ ‫ ‘ذא‬، net. _D ‫م‬R.‫ א‬iH‫و‬M N7 }H t‫ א‬i$Q$Ž‫ א‬hN7‫א‬
.a7!$Q$Ž‫אضא‬9A'ًVV†
.O+\‫א‬SbND‫و‬j‫א‬net.JSO\ًOb‫و‬${NS:0‫אא‬X‫א‬
4z$‫א‬OX‫אא‬WS‫ض‬Q،‫א‬FVU‫ ق‬1–‫א‬01NS53 :@3œ‫א‬X‫א‬
.bœ‫א‬4‫א‬JVisual Studio_DU‫ ق‬1–‫א‬O‹53‫و‬
C iH'V :%'3 X‫א א‬WS ، g O‫ א و‬q‫ א‬bND ‫ אض‬C$N NS : ‫ אدس‬X‫א‬
.Y!ZRFq‫א‬G]
Wa7!'S‫و‬Yj$F
.ً3$73iH'V5P‫אˆو‬XH‫א‬F‫א‬:0‫א‬X‫א‬
O‫و‬gQ')‫و‬hJO‫א‬nDf‫א‬NP> OOP:%'‫א‬Nj4I$3'SlWS :53^‫א‬X‫א‬
.k I53KF‫א‬
.4‫א‬Ug3‫א‬$+‫وא‬gVjVI‫و‬Interfaceshg%‫א'א‬:0‫א‬X‫א‬
.gR7N‫و‬gŽ3O‫'دو‬P‫א‬U¤z1IC‫ص‬N.‫א‬K%C53X‫אא‬WS:,‫א‬X‫א‬
16
N‫א‬UiHP\‫א‬g3‫א‬$+‫ وא‬COLLECTIONS‫'אعאل‬CKVOX‫אא‬WS‫د‬Q :TD‫د‬L‫א‬X‫א‬
.O+\‫א‬
_DU‫و‬4‫א‬qUً3$7^CbNDnDf،i\‫א‬lWS3$7\‫א‬4‫ א‬:TD^‫א‬X‫א‬
.net.
.hO\‫א‬03K3‫א‬O‫و‬O+\‫אجא‬I–‫لوא‬I‫قא–د‬:TD^‫א‬X‫א‬
*jVœ‫ وא‬gQ' t‫ א‬h‫ وאدوא‬WINDOWS FORMS ‫_ אل‬D U ‫ ق‬1–‫ א‬: TD 0‫ אא‬X‫א‬
.:! I‫وאو‬
.+GDI‫ ل‬I53‫אد‬jN‹h3'‫_א‬DUQHU¤WI]Q:TD@3œ‫א‬X‫א‬
.O+\‫א‬g‫وא‬g‫دوא‬C‫و‹ ‹אدو‬jN‹h3'V+\‫א‬WPFN7Q‫א‬$:TD‫אدس‬X‫א‬
3‫ و‬ADO.net ‫ ل‬I 53 h‫ א‬$D‫'א‬. _D U ‫ ق‬1–‫ א‬NP> X‫א א‬WS U : TD 0‫ א‬X‫א‬
.:! I‫و‬SQL Serverh‫א‬$D‫'א‬.53‫مذ‬Q
.NSgz$‫א‬NP>LINQ‫و'!€ م‬PQ353i$Q$Ž‫א‬N7‫א‬:TD53^‫א‬X‫א‬
.0QHT\‫א‬iH‫دא‬9€!'‫و‬PQ353i$Q$Ž‫א‬WWFN7_DU‫א‬$NS:TD0‫א‬X‫א‬
.€!'‫و‬PQ353h71‫وא‬23‫א‬4‫א‬HT\WCF_D03ًMQC:‫ون‬T‫א‬X‫א‬
K. O+\‫ א‬ig%9‫ א‬nD KqT ˆ 3k‫ א‬0s‫ א\'א‬53 D'F : ‫ون‬T‫د وא‬L‫ א‬X‫א‬
.ˆ ‫א‬X‫א‬UGQ'‫_א‬DU‫ ق‬19‫א‬
.ASP.net‫ ل‬I53DOGQ‫و‬h71Q'153X‫אא‬WSNP>،
I‫א‬X‫א‬:‫ون‬T‫א^وא‬X‫א‬
...0ON‫وא‬i$jO‫א‬gQ')™U‫'ن‬PQ‫ن‬C‫א‬53'%HC
17
‫ﻟﻤﻦ ﻫﺬا اﻟﻜﺘﺎب‬
A'3f$gQ9XP‫אא‬Wg!،XP‫אא‬WSKFDUH‫'א‬T3‫'אل‬NGb‫א‬S‫אل‬p‫אא‬WS%‫א‬
‫ ً ن‬QC ˆQ1‫ول א‬C nD MQ‫ و‬، iS‫ ن ز‬K 53 @7Q ‫ن‬C ‫ول‬d'g! ، N3 JO ً VV† @‫ و‬Y3
.¤‫'א‬3
!3 OP! ً !Z) €N ' 3C ، 4‫ א‬h‫} א‬H s' „‫ אو‬XP‫ א‬X‫ ًא !]'א‬z$3 €N ‫!¦ذא‬
‫ ق‬1‫א‬17‫'ن‬PXP‫אא‬Wg!ً1'3€N'3C،ONSH§t‫א‬X‫א'א‬U‫ ق‬1–‫وא‬a7!$Q$Ž‫א‬
..net 2008_D53‫!وع‬i$DUi$%
،h‫א‬Uًb'VIs‫א'א‬s'‫و‬C،XP‫א‬Uh‫א‬H‫א‬P‫א‬i^53fZ[‫א‬K>9‫ن‬C'%HC‫א‬W
i\‫א‬SlWS€‫‘ذא‬3C،:N3SS‫א‬Qt‫طא‬7N‫א‬Uً‫א‬H'!‫'ل‬I$‫طאوא‬7N‫{وزא‬:NP>
SN„‫'لאو‬VO‫א‬،XP‫א‬hQ')53ًJ,h'O9C‫ول‬R!4‫_א‬DU‫ ق‬1„‫אو‬
.‫ذ‬$z,K‫س‬C
53‫'ن‬Pt‫א‬X‫™א'א‬s'g!،7‫א‬ROV‫א‬UXP‫א‬hQ')nD01‫ن‬Cً‫א‬$%cFgQ
g!(N‫א‬$‫ن‬C7‫א‬ROV‫א‬h‫€{وز‬N'ً M!‫א‬W.ًMQ‫א‬fZRF‫و‬C،¨$FS‫{وز‬KMO\‫א‬
.AICi3
18
‫اﻟﺘﻌﺮﻳﺐ‬
K^3U‫و‬،BZ‫א‬iz‫א‬.03‫مאא‬$D03ًD'$%C€N–g—C‫و‬C–‫א‬qgC.t‫א‬GP‫א‬KU
H$.€‫و‬W‫א‬X'‫'א‬S‫א‬WS‫و‬،Q<–‫א‬qb9‫א‬FP‫ א‬nD‫א– ع‬KM!‫€א‬Nh9L‫א‬lWS
.XP‫אא‬WS5Fs:%g‫عא‬1\‫א‬
Loops‫و‬ConditionstFPBZH‫א‬P‫א‬h7‫و‬T‫א‬KFŽ‫א‬K^3،J‫و‬$9hBZ‫™א‬¤NS
‫ אل‬oQ‫( و‬J!) :C nD Class ‫ אل‬oQ K^3 J $ 9 gNP‫ و‬i‫'د‬% K.C ‫و‬$ }H hB ¤NS ،
‫ ” ذ‬i‫ אد‬U $` L‫ א‬lWS U ، ‫א‬WPS‫ و‬Variable ‫ ً ل‬Q$ q\‫ א‬، (g%‫ )وא‬gC nD Interface
!:! I‫א‡(و‬...h3$g\‫א‬،h‫א‬$T\‫)א‬K^3B3C،i3KUS‫ذ‬5Dً Q$i$‫وא‬i3BZ‫א‬
.7‫و€א‬3$„‘ًN3:QCH3a7!€3$+‫א‬،gg3$+‫و_א‬gg‫א‬
nD‫د‬FD9‫ولא‬9ًMQC،‫ن‬P3CUkb‫א‬FP‫ذא‬Q_DF${5¦ˆ‹KnD‫و‬
G—CBnDXP‫א‬Y‫ق‬O9‫א‬53‫א'ع‬$%'Q9(R‫א‬nR!،IŠDXiz‫א‬.UtB
.4‫א‬hR1V3B5D‫ق‬O‫א‬UE$R‫ن‬C5Dً M!'3'P‫א‬hR1V3
‫اﻟﻔﻬﺮس‬
19
29
31
32
33
35
37
38
39
41
42
43
45
47
48
49
50
50
52
52
53
54
55
56
56
58
58
59
60
60
63
65
65
66
68
68
69
2008 ‫ ﺗﺤﻤﻴﻞ ﻧﺴﺨﺘﻚ اﻷوﻟﻰ ﻣﻦ ﻓﻴﺠﻮال ﺳﺘﻮدﻳﻮ‬: 02 ‫اﻟﺒﺎب‬
Visual Studio 2008 ‫ اﻟﻨﺴﺨﺔ اﻟﻜﺎﻣﻠﺔ ﻣﻦ‬.1
Visual Studio 2008 ‫ اﻟﻨﺴﺦ اﻟﻤﺠﺎﻧﻴﺔ ﻣﻦ‬.2
VS 2008 ‫ إﻟﻰ‬VS 2005 ‫ ﺗﺮﻗﻴﺔ ﻣﺸﺮوﻋﻚ اﻟﺬي ﻳﻌﻤﻞ ﻋﻠﻰ‬.3
net 2008. ‫ اﻟﺠﺪﻳﺪ ﻣﻊ‬: 03 ‫اﻟﺒﺎب‬
SilverLight ‫ ﺗﻘﻨﻴﺔ‬.1
LINQ ‫ ﺗﻘﻨﻴﺔ‬.2
WPF ‫ ﺗﻘﻨﻴﺔ‬.3
Expression ‫ ﻣﺠﻤﻮﻋﺔ‬.4
WCF ‫ ﺗﻘﻨﻴﺔ‬.5
Code Refactoring .6
‫ اﻟﺮﺋﻴﺴﻴﺔ‬net. ‫ ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ‬: 04 ‫اﻟﺒﺎب‬
. net. ‫ ﻟﻐﺎت‬.1
. ‫ اﻟﻌﻨﺎﺻﺮ اﻷﺳﺎﺳﻴﺔ ﻓﻲ دوت ﻧﺖ‬.2
Base Class Library .3
net Assemblies. .4
CIL .5
Metadata .6
Mainfest .7
Common Type System .8
CTS Members .8.1
CTS Data Types .8.2
Common Language Specification .9
Common Language Runtime .10
Object Browser ‫ اﺳﺘﺨﺪام‬.11
Name Space ‫ ﻣﺠﺎﻻت اﻷﺳﻤﺎء‬.12
‫ اﺳﺘﻴﺮاد ﻣﺠﺎﻻت اﻷﺳﻤﺎء‬.12.1
ildasm ‫ اﺳﺘﺨﺪام ﺑﺮﻧﺎﻣﺞ‬.13
Open Source .net ‫ ﻫﻞ ﺗﺒﺤﺚ ﻋﻦ‬.14
Visual Studio 2008 ‫ اﻟﻮاﺟﻬﺔ اﻷﺳﺎﺳﻴﺔ ﻟـ‬: 05 ‫اﻟﺒﺎب‬
‫ ﻛﻴﻒ أﻛﺘﺐ اﻟﻜﻮد ؟‬.1
VS 2008 Command Prompt ‫ اﺳﺘﺨﺪام‬.1.1
Textpad ‫ اﺳﺘﺨﺪام‬.1.2
++Notepad .1.3
SharpDevelop .1.4
Viusal Studio 2008 ‫ اﻟﺒﺪاﻳﺔ ﻣﻊ‬. 2
‫‪20‬‬
‫‪ .1.2‬ﺑﺮﻧﺎﻣﺠﻚ اﻷول‬
‫اﻟﺒﺎب ‪ : 06‬ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ ﻓﻲ ‪ net.‬اﻟﺠﺰء اﻷول‬
‫‪ .1‬ﺧﺼﺎﺋﺺ ‪Console‬‬
‫‪ .2‬ﺗﻌﺮﻳﻒ اﻟﻤﺘﻐﻴﺮات‬
‫‪ .2.1‬أﻧﻮاع اﻟﻤﺘﻐﻴﺮات‬
‫‪ .2.2‬اﻟﺜﻮاﺑﺖ ‪Constants‬‬
‫‪ .2.3‬اﻟﻘﻴﻢ ﻟﻠﻘﺮاءة ﻓﻘﻂ ‪Read Only Dield‬‬
‫‪ .3‬اﻟﻤﺘﻐﻴﺮات اﻟﻨﺼﻴﺔ ‪String‬‬
‫‪ .3.1‬اﻟﺨﺼﺎﺋﺺ واﻟﺪوال اﻟﺮﺋﻴﺴﻴﺔ‬
‫‪ .3.2‬ﺗﻘﺴﻴﻢ اﻟﻨﺼﻮص‬
‫‪ .3.3‬دﻣﺞ اﻟﻨﺼﻮص‬
‫‪ .3.4‬ﻣﻘﺎرﻧﺔ اﻟﻨﺼﻮص‬
‫‪ - Escape Characters .3.5‬ﺳﻲ ﺷﺎرب ﻓﻘﻂ‬
‫‪ .3.6‬اﻟﺘﺤﻮﻳﻞ ﻣﻦ وإﻟﻰ اﻟﻨﺼﻮص‬
‫‪StringBuilder .3.7‬‬
‫‪ .4‬اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﺘﺎرﻳﺦ واﻟﻮﻗﺖ‬
‫‪ .5‬اﻟﺘﺤﻮﻳﻞ ﺑﻴﻦ اﻟﻤﺘﻐﻴﺮات اﻟﻤﺨﺘﻠﻔﺔ‬
‫‪Widening Conversions .5.1‬‬
‫‪Narrowing Converstions .5.2‬‬
‫‪Cast .5.3‬‬
‫‪Convert.To .5.4‬‬
‫‪ .6‬اﻟﺠﻤﻞ اﻟﺸﺮﻃﻴﺔ ﻓﻲ دوت ﻧﺖ‬
‫‪ .6.1‬أﺳﺎﺳﻴﺎت اﻟﺸﺮوط‬
‫‪ .6.2‬دﻣﺞ اﻟﺸﺮوط‬
‫‪AndAlso .6.3‬‬
‫‪OrElse .6.4‬‬
‫‪ .6.5‬اﺳﺘﺨﺪام ‪switch‬‬
‫‪ .7‬اﻟﺤﻠﻘﺎت اﻟﺘﻜﺮارﻳﺔ‬
‫‪For - Next Loop .7.1‬‬
‫‪While Loop .7.2‬‬
‫‪For Each Loop .7.3‬‬
‫اﻟﺒﺎب ‪ :07‬ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ ﻓﻰ ‪ - .net‬اﻟﺠﺰء اﻟﺜﺎﻧﻰ‬
‫‪ .1‬ﻟﻨﻔﻬﻢ ﺑﺮﻧﺎﻣﺠﻨﺎ اﻷول‬
‫‪ .2‬اﻟﺪوال ‪Function‬‬
‫‪ .3‬اﻟﻄﺮق ‪Methods‬‬
‫‪ .4‬اﻟﻮﻇﻴﻔﺔ ‪out‬‬
‫‪ .5‬اﻹرﺳﺎل ﺑﺎﻟﻤﺮﺟﻊ ‪ byref‬واﻹرﺳﺎل ﺑﺎﻟﻘﻴﻤﺔ ‪byval‬‬
‫‪71‬‬
‫‪73‬‬
‫‪75‬‬
‫‪75‬‬
‫‪77‬‬
‫‪77‬‬
‫‪79‬‬
‫‪80‬‬
‫‪80‬‬
‫‪81‬‬
‫‪81‬‬
‫‪81‬‬
‫‪82‬‬
‫‪82‬‬
‫‪83‬‬
‫‪85‬‬
‫‪86‬‬
‫‪86‬‬
‫‪87‬‬
‫‪87‬‬
‫‪88‬‬
‫‪89‬‬
‫‪89‬‬
‫‪90‬‬
‫‪91‬‬
‫‪92‬‬
‫‪93‬‬
‫‪94‬‬
‫‪94‬‬
‫‪95‬‬
‫‪96‬‬
‫‪97‬‬
‫‪99‬‬
‫‪103‬‬
‫‪104‬‬
‫‪104‬‬
‫‪106‬‬
‫‪21‬‬
‫‪ .6‬اﻟﻤﺼﻔﻮﻓﺎت‬
‫‪ .1.6‬ﻣﺎﻫﻰ اﻟﻤﺼﻔﻮﻓﺎت ‪Arrays‬‬
‫‪ .2.6‬ﺗﻜﻮﻳﻦ اﻟﻤﺼﻔﻮﻓﺎت‬
‫‪ .3.6‬اﻟﻤﺼﻔﻮﻓﺎت ﻣﺘﻌﺪدة اﻷﺑﻌﺎد‬
‫‪ .4.6‬ﻋﻤﻞ ﻣﺼﻔﻮﻓﺔ ﻣﻦ اﻟﻤﺼﻔﻮﻓﺎت‬
‫‪ .5.6‬إرﺳﺎل وإﺳﺘﻘﺒﺎل اﻟﻤﺼﻔﻮﻓﺎت ﻣﻦ وإﻟﻰ اﻟﺪوال‬
‫‪ .6.6‬ﺧﺼﺎﺋﺺ اﻟﻤﺼﻔﻮﻓﺎت اﻟﺮﺋﻴﺴﻴﺔ‬
‫‪ .7‬اﻟـ ‪Enumeration‬‬
‫‪ .8‬اﻟﺘﺮاﻛﻴﺐ ‪Structure‬‬
‫‪ .8.1‬إﻧﺸﺎء اﻟﺪوال داﺧﻞ اﻟـ ‪Struct‬‬
‫‪ .9‬اﻷﻧﻮاع ‪ Value‬واﻷﻧﻮاع ‪Reference‬‬
‫‪ .10‬اﻟﻤﻘﺎرﻧﺎت‬
‫‪Nullable Types .11‬‬
‫‪ .11.1‬ﺧﺼﺎﺋﺺ اﻟـ ‪Nullable‬‬
‫‪ .11.2‬اﻟﻤﻌﺎﻣﻞ ؟؟‬
‫اﻟﺒﺎب ‪ :08‬ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ ‪OOP‬‬
‫‪ .1‬ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﻔﺌﺎت ‪Classes‬‬
‫‪ .1.1‬اﻟﻤﺸﻴﺪات ‪Constructors‬‬
‫‪ .2.1‬اﻟﻤﻬﺪﻣﺎت ‪Destructor‬‬
‫‪this .2‬‬
‫‪ .3‬اﻟﺘﻌﺮف ﻋﻠﻰ ‪Static‬‬
‫‪Static Class .3.1‬‬
‫‪ .4‬إﻋﺎدة ﺗﺤﻤﻴﻞ ‪OverLoading‬‬
‫‪ .5‬ﻣﻌﺮﻓﺎت اﻟﻮﺻﻮل ‪Access Modifier‬‬
‫‪ .6‬اﻟﻌﻨﺎﺻﺮ اﻷﺳﺎﺳﻴﺔ ﻓﻰ ‪OOP‬‬
‫‪Encapsulation .6.1‬‬
‫‪Inheritance .6.2‬‬
‫‪Ploymorphoism .6.3‬‬
‫‪Encapsulation .7‬‬
‫‪ .7.1‬إﺳﺘﺨﺪام دوال ‪ Public‬ﻟﻠﻮﺻﻮل إﻟﻰ ﻣﺘﻐﻴﺮات ‪Private‬‬
‫‪ .7.2‬إرﺳﺎل اﻟﻘﻴﻢ ﻛﺠﺰء ﻣﻦ اﻟـ ‪Conctructor‬‬
‫‪ .7.3‬إﺳﺘﺨﺪام اﻟـ ‪Type Property‬‬
‫‪ .8‬اﻟﻮراﺛﺔ ‪Inheritance‬‬
‫‪ .8.1‬ﺗﻌﺮﻳﻒ ﻋﻼﻗﺔ ‪is-a‬‬
‫‪ .8.2‬اﻟﻜﻠﻤﺔ اﻟﻤﺤﺠﻮزة ‪sealed - NotInheritable‬‬
‫‪ .8.3‬اﻟﻮراﺛﺔ اﻟﻤﺘﻌﺪدة‬
‫‪ .8.4‬اﻟﺘﻌﺪﻳﻞ ﻓﻰ اﻟﻜﻼس اﻟﻤﺸﺘﻖ‬
‫‪107‬‬
‫‪107‬‬
‫‪108‬‬
‫‪109‬‬
‫‪110‬‬
‫‪111‬‬
‫‪112‬‬
‫‪112‬‬
‫‪114‬‬
‫‪116‬‬
‫‪118‬‬
‫‪120‬‬
‫‪125‬‬
‫‪126‬‬
‫‪127‬‬
‫‪129‬‬
‫‪131‬‬
‫‪134‬‬
‫‪135‬‬
‫‪135‬‬
‫‪137‬‬
‫‪140‬‬
‫‪141‬‬
‫‪144‬‬
‫‪144‬‬
‫‪145‬‬
‫‪145‬‬
‫‪145‬‬
‫‪146‬‬
‫‪147‬‬
‫‪148‬‬
‫‪150‬‬
‫‪152‬‬
‫‪154‬‬
‫‪155‬‬
‫‪157‬‬
‫‪157‬‬
‫‪158‬‬
22
158
159
161
161
162
164
165
167
167
169
171
174
197
180
183
185
185
186
189
190
192
193
193
193
194
197
201
203
203
206
206
208
211
213
215
216
218
219
has-a ‫ اﻟﻌﻼﻗﺔ ﻣﻦ ﻧﻮع‬.8.5
Casting ‫ اﻟﺘﺤﻮﻳﻼت‬.8.6
is ‫ اﻟﻜﻠﻤﺔ اﻟﻤﺤﺠﻮزة‬.8.7
Visual Studio Class Diagram .8.8
Polymoriphism ‫ اﻟـ‬.9
Abstract ‫ اﻟـ‬.10
Abstract method .10.1
‫ اﻟﻮاﺟﻬﺎت‬- Interfaces : 09 ‫اﻟﺒﺎب‬
Interface ‫ ﺗﻌﺮﻳﻒ اﻟـ‬.1
Names Clashes .2
IEnumerable interface .3
ICloneable interface .4
IComparable interface .5
‫ اﻷﺧﻄﺎء واﻗﺘﻨﺎﺻﻬﺎ‬:10 ‫اﻟﺒﺎب‬
Syntax Errors ‫اﻷﺧﻄﺎء اﻟﻨﺤﻮﻳﺔ‬.1
Logical Errors ‫ اﻷﺧﻄﺎء اﻟﻤﻨﻄﻘﻴﺔ‬.2
System.Exception ‫ اﻟﻔﺌﺔ‬.3
Throwing Exceptions - ‫ رﻣﻰ اﻻﺳﺘﺜﻨﺎءات‬.4
Catching exceptions - ‫ اﻗﺘﻨﺎص اﻷﺧﻄﺎء‬.5
Finally ‫ اﺳﺘﺨﺪام‬.5.1
break ‫ اﺳﺘﺨﺪام‬.5.2
TargetSite ‫ اﺳﺘﺨﺪام‬.5.3
HelpLink ‫ اﺳﺘﺨﺪام‬.5.4
‫ ﻋﻤﻞ أﺧﻄﺎء ﺧﺎﺻﺔ‬.6
Collectiona ‫ اﻟﺘﺠﻤﻴﻌﺎت‬:11 ‫اﻟﺒﺎب‬
System.Collections ‫ ﻓﻰ‬Interfaces ‫ اﻟـ‬.1
System.Collections ‫ اﻟﻔﺌﺎت ﻓﻰ‬.2
ArrayList .2.1
HashTable .2.2
Queue.3.2
Stack .4.2
.net 2008 ‫ اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻰ‬:12 ‫اﻟﺒﺎب‬
Generics ‫ اﻟـ‬.1
Structure and Class Generics .1.1
Generic Collection .2.1
Where T ‫ اﺳﺘﺨﺪام‬.3.1
Delegates ‫ اﻟـ‬.2
23
221
223
225
226
227
228
229
232
235
237
238
238
240
243
247
250
250
252
253
255
259
259
261
261
262
263
264
264
265
265
270
271
272
272
273
274
277
Delegates ‫ ﺗﻌﺮﻳﻒ اﻟـ‬.2.1
Events ‫ اﻷﺣﺪاث‬.2.2
C# ‫ ﻓﻘﻂ ﻓﻰ‬- Anonymous Methods ‫ اﻟـ‬.3
‫ اﺳﺘﻨﺘﺎج ﻧﻮع اﻟﻤﺘﻐﻴﺮات‬.4
Extension Methods ‫ اﻟﺪوال اﻟﻤﻤﺘﺪة‬.5
Automatic Properties .6
Lambda Expressions ‫ ﺗﻌﺒﻴﺮات ﻻﻣﺪا‬.7
Object Initializer Syntax ‫ ﺻﻴﻎ إﻧﺸﺎء اﻟﻜﺎﺋﻨﺎت‬.8
Anonymous Types ‫ اﻷﻧﻮاع اﻟﻤﺠﻬﻮﻟﺔ‬.9
Partial Methods .10
Gerbage Collector .11
GC ‫ اﻟﻔﺌﺔ‬.11.1
Operator Overloading .12
Pointers ‫ اﻟﻤﺆﺷﺮات‬.13
Query Expressions .14
Preprocessor Directives .15
#region , #endregion .15.1
#if , #elif , #else , #endif .15.2
#define , #undef .15.3
XML Commenting .16
.net assemblies .17
namespace ‫ اﻟـ‬.17.1
Default Namespace ‫ ﺗﻐﻴﻴﺮ اﻟـ‬.17.2
Format of a .net Assembly ‫ ﺷﻜﻞ ﻣﻠﻒ اﻷﺳﻤﺒﻠﻰ‬.17.3
Private Assemblies .17.4
Shared Assemblies .17.5
Multithreading ‫ اﻟﻤﺴﺎرات اﻟﻤﺘﻌﺪدة‬.18
‫ ﻣﻘﺪﻣﺔ‬.18.1
Synchronization ‫ اﻟﺠﻮرﻳﺰﻣﺎت اﻟﺘﺰاﻣﻦ‬.18.2
System.Threading.Thread .18.3
Priority ‫ اﻷوﻟﻮﻳﺔ‬.18.4
ParameterizedThreadStart .18.5
Foreground and Background .18.6
Threads Synchronization .18.7
ThreadPool .18.8
BackgroundWorker .18.9
System.IO ‫ اﻹدﺧﺎل واﻹﺧﺮاج ﻓﻰ‬:13 ‫اﻟﺒﺎب‬
24
278
278
279
284
284
285
287
289
289
289
289
291
292
293
294
296
297
298
301
301
303
305
307
307
310
311
315
320
320
321
322
323
323
324
325
325
325
System.IO ‫ اﻟﻔﺌﺎت اﻷﺳﺎﺳﻴﺔ ﻓﻰ‬.1
Directory ‫ و‬DirectoryInfo ‫ اﻟﻔﻮراق ﺑﻴﻦ‬.2
DirectoryInfo ‫ اﻟﻔﺌﺔ‬.3
Directory ‫ اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻔﺌﺔ‬.4
DriveInfo ‫ اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻔﺌﺔ‬.5
FileInfo ‫ اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬.6
Open ‫ إﻧﺸﺎء وﻓﺘﺢ اﻟﻤﻠﻔﺎت ﺑﺎﺳﺘﺨﺪام‬.6.1
OpenWrite ‫ و‬OpenRead ‫ ﻓﺘﺢ وإﻧﺸﺎء اﻟﻤﻠﻔﺎت ﺑﺎﺳﺘﺨﺪام‬.6.2
OpenText ‫ ﻓﺘﺢ اﻟﻤﻠﻔﺎت ﺑﺎﺳﺘﺨﺪام‬.6.3
AppendText ‫ و‬CreateText ‫ اﻟﻔﺘﺢ ﺑﺈﺳﺘﺨﺪام‬.6.4
File ‫ اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻔﺌﺔ‬.7
Stream.8
FileStream ‫ اﻟﻔﺌﺔ‬.8.1
‫ اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻔﺌﺎت اﻟﻤﺸﺘﻘﺔ‬.8.2
StreamWriter, StreamReader .8.3
StringWriter,StringReader .8.4
BinaryWriter,BinaryReader .8.5
FileSystemWatcher .9
Object Serialization .10
Serialization ‫ اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟـ‬.10.1
XmlSerializaer .10.2
Windows Forms ‫ ﺑﺮﻣﺠﺔ اﻟﻨﻮاﻓﺬ‬: 14 ‫اﻟﺒﺎب‬
‫ ﻣﻘﺪﻣﺔ‬.1
‫ ﺑﺎﻟﻜﻮد‬Windows Forms ‫ ﺑﻨﺎء‬.2
‫ إﺿﺎﻓﺔ أدوات ﺑﺎﻟﻜﻮد‬.2.1
‫ إﺿﺎﻓﺔ اﻟﻘﻮاﺋﻢ‬.2.2
Visual Studio .net ‫ إﻧﺸﺎء ﻓﻮرم ﻋﻦ ﻃﺮﻳﻖ‬.3
Windows.Forms ‫ ﻣﺠﺎل اﻷﺳﻤﺎء‬.4
Windows.Forms ‫ اﻟﻔﺌﺎت اﻟﺮﺋﻴﺴﻴﺔ ﻟﻌﻨﺎﺻﺮ‬.4.1
Form ‫ ﺧﺼﺎﺋﺺ اﻟﻔﺌﺔ‬.4.2
Form ‫ دوال اﻟﻔﺌﺔ‬.4.3
Form ‫ دوال اﻟﻔﺌﺔ‬.4.4
Controls ‫ اﻟﻔﺌﺔ‬.5
Controls ‫ ﺧﺼﺎﺋﺺ اﻟﻔﺌﺔ‬.5.1
Controls ‫ أﺣﺪاث اﻟﻔﺌﺔ‬.5.2
System.Windows.Forms.Control ‫ أدوات‬.6
Button .6.1
25
326
326
326
327
329
329
329
332
333
343
343
343
335
336
338
338
341
342
345
346
347
349
351
351
352
354
355
356
357
361
363
363
363
363
364
365
365
CheckBox .6.2
RadioButton .6.3
ListBox ‫ و‬ComboBox .6.4
Textbox .6.5
Label .6.6
Panel ‫ و‬GroupBox .6.7
RichTextBox .6.8
Timer.6.9
TreeView .6.10
ProgressBar.6.11
TrackBar .6.12
DateTimePicker .6.13
Dialogs .7
MessageBox .7.1
Dialogs Controls .7.2
ColorDialog .7.3
FontDialog .7.4
Open And Save Dialogs .7.5
PrintDialog .7.6
‫ أﺣﺪاث اﻟﻤﺎوس‬.8
‫ أﺣﺪاث اﻟﻜﻴﺒﻮرد‬.9
+GDI : 15 ‫اﻟﺒﺎب‬
+GDI ‫ ﻣﻘﺪﻣﺔ إﻟﻰ‬.1
System.Drawing ‫ ﻣﺤﺘﻮﻳﺎت ﻣﺠﺎل اﻷﺳﻤﺎء‬.2
Graphics ‫ اﻟﻔﺌﺔ‬.3
Pen .4
Bruch .5
‫ رﺳﻢ اﻷﺷﻜﺎل‬.6
‫ رﺳﻢ اﻟﻨﺼﻮص‬.7
Windows Presentation Foundation : 16 ‫اﻟﺒﺎب‬
‫ ﻣﻘﺪﻣﺎت أﺳﺎﺳﻴﺔ‬.1
WPF .1.1
XAML .1.2
Microsoft Expression .1.3
WPF ‫ أﻧﻮاع ﺗﻄﺒﻴﻘﺎت‬.2
WPF ‫ ﻣﺤﺘﻮﻳﺎت وﻣﻜﻮﻧﺎت‬.3
WPF ‫ ﺗﻄﺒﻴﻘﻚ اﻷول ﻓﻲ ﻋﺎﻟﻢ‬.4
26
367
372
375
376
382
385
387
387
388
389
390
391
398
399
399
400
401
402
403
411
413
414
414
415
415
421
421
429
439
441
443
444
444
445
449
450
‫ اﻟﺒﺪء ﻣﻦ ﺧﻼل ﻓﻴﺠﻮال ﺳﺘﻮدﻳﻮ‬.5
WPF ‫ أدوات‬.6
Data Binding ‫ رﺑﻂ اﻟﺒﻴﺎﻧﺎت‬.7
WPF 2D .8
WPF ‫ اﻟﺤﺮﻛﺔ ﺑﺎﺳﺘﺨﺪام‬.9
XAML ‫ اﻟﺤﺮﻛﺔ ﺑﺎﺳﺘﺨﺪام‬.10
Styles ‫ ﺗﻌﺮﻳﻒ‬.11
Style ‫ ﺗﻐﻴﻴﺮ ﻃﺒﻴﻌﺔ ال‬.11.1
‫ ﻣﻦ آﺧﺮ‬Style ‫ اﺷﺘﻘﺎق‬.11.2
Triggers ‫ ﺑﺎﺳﺘﺨﺪام‬Style ‫ ﺗﺼﻤﻴﻢ‬.11.3
Tamplates ‫ اﻟـ‬.12
WPF 3D .13
XNA .14
Microsoft Expression Studio .15
Microsoft Expression Web .15.1
Microsoft Expression Design .15.2
Microsoft Expression Media .15.3
Microsoft Expression Encoder .15.4
Microsoft Expression Blend .15.5
ADO.net ‫ ﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت ﺑﺎﺳﺘﺨﺪام‬: 17 ‫اﻟﺒﺎب‬
ADO.net ‫ اﻟﺒﺪء ﺑﺎﺳﺘﺨﺪام‬.1
ADO.net Data Provider ‫ ﻣﻜﻮﻧﺎت‬.2
‫ اﻟﻤﺪﻋﻮﻣﺔ ﻣﻦ ﻗﺒﻞ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ‬Data Providers ‫ ال‬.1.2
Third-Party ADO.net Data ‫ اﻟﺘﻌﺎﻣﻞ ﻣﻊ ﻣﺰودات ﺧﺪﻣﺔ أﺧﺮى‬2.2
Providers
System.Data ‫ ﻣﻜﻮﻧﺎت ﻣﺠﺎل اﻷﺳﻤﺎء‬.3
Sql Server ‫ اﻟﺒﺪاﻳﺔ ﻣﻊ‬.4
‫ إﻧﺸﺎء ﻗﺎﻋﺪة اﻟﺒﻴﺎﻧﺎت‬.4.1
Sql Statements .4.2
Stored Procedures .4.3
SQL Injection .4.4
‫ اﻟﻌﻼﻗﺎت‬.4.5
‫ اﻟﻮﺿﻊ اﻟﻤﺘﺼﻞ‬.5
ConnectionStringBuilder ‫ اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬.5.1
Command ‫ اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬.5.2
Data Readers ‫ اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬.5.3
Data Access Layers .6
27
459
461
465
465
467
467
468
470
472
473
474
476
477
479
482
487
488
490
494
495
499
501
502
502
503
504
507
509
511
512
513
514
517
517
518
521
523
Asynchronous Data Access .7
Transactions .8
‫ اﻟﻮﺿﻊ اﻟﻤﻨﻔﺼﻞ‬.9
DataSet .9.1
DataTable .9.2
DataTable ‫ اﻧﺸﺎء‬.9.3
DataColumn ‫ اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬.9.4
DataRow ‫ اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬.9.5
DataTable ‫ ﻟﻘﺮاءة اﻟﺒﻴﺎﻧﺎت ﻣﻦ‬DataTableReader ‫ اﺳﺘﺨﺪام‬9.6
XML ‫ إﻟﻰ‬Serializing ‫ ﻋﻤﻞ‬.10
DataGrid ‫ اﺳﺘﺨﺪام‬.11
DataAdapter ‫ اﺳﺘﺨﺪام‬.12
LINQ : 18 ‫اﻟﺒﺎب‬
. ‫ ﻣﻘﺪﻣﺔ‬.1
LINQ ‫ دوال‬.2
LINQ To DataSet .3
LINQ To XML .4
LINQ To SQL .5
SubmitChanges .6
‫ ﻣﻦ ﺧﻼل اﻟﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ‬LINQ To SQL ‫ اﻧﺸﺎء ﻓﺌﺎت‬.7
WWF : 19 ‫اﻟﺒﺎب‬
WF ‫ ﻣﻜﻮﻧﺎت وأﺳﺎﺳﻴﺎت‬.1
WF ‫ اﻟﺒﺪأ ﻣﻊ‬.1.1
Sequential Workflow .1.2
State Machine Workflow .1.3
WWF ‫ ﺗﻄﺒﻴﻖ‬.2
WF Code Library .3
WCF : 20 ‫اﻟﺒﺎب‬
Web Service .1
‫ ﺧﺎﺻﺔ ﺑﻚ ﻣﻦ ﺧﻼل دوت ﻧﺖ‬Web Service ‫ ﻋﻤﻞ‬.1.1
‫ ﺧﺎﺻﺔ ﺑﻚ ﻓﻲ ﻣﺸﺮوﻋﺎﺗﻚ اﻟﻔﻌﻠﻴﺔ‬Web Service ‫ اﺳﺘﺨﺪام‬.1.2
‫ اﺳﺘﺨﺪام ﺧﺪﻣﺎت اﻹﻧﺘﺮﻧﺖ اﻟﺠﺎﻫﺰة‬.1.3
WCF ‫ ﻣﻘﺪﻣﺔ إﻟﻰ‬.2
WCF ‫ اﻟﺒﺪاﻳﺔ ﻣﻊ‬.2.1
Address ‫ ﺷﻜﻞ وﻣﺤﺘﻮﻳﺎت ال‬.2.2
‫ ﻧﻘﺎط ﻣﺘﻘﺪﻣﺔ‬: 21 ‫اﻟﺒﺎب‬
Debug ‫ اﻟﺘﻨﻘﻴﺢ‬.1
28
526
528
533
535
539
541
548
553
554
557
558
558
561
564
567
572
572
574
574
575
578
579
580
582
585
591
591
592
593
594
‫ ﺗﺠﻬﻴﺰ اﻟﺒﺮﻧﺎﻣﺞ ﻟﻠﺘﻮزﻳﻊ‬.2
#VB.net vs C .3
Mono ‫ ﻣﻘﺪﻣﺔ إﻟﻰ‬.4
‫ ﺑﺮﻣﺠﺔ اﻷﺟﻬﺰة اﻟﻜﻔﻴﺔ ﻣﻦ ﺧﻼل دوت ﻧﺖ‬.5
ASP.net ‫ ﺗﻄﻮﻳﺮ اﻟﻤﻮاﻗﻊ ﺑﺎﺳﺘﺨﺪام‬: 22 ‫اﻟﺒﺎب‬
‫ ﻣﻘﺪﻣﺔ إﻟﻰ ﺗﻄﻮﻳﺮ اﻟﻤﻮاﻗﻊ‬.1
ASP.net ‫ ﻣﻘﺪﻣﺔ إﻟﻰ‬.2
System.Web.UI.Page ‫ اﻟﻔﺌﺔ‬.3
Request .3.1
Response .3.2
ASP.net ‫ أدوات‬.4
‫ اﻟﺨﺼﺎﺋﺺ اﻷﺳﺎﺳﻴﺔ ﻷدوات اﻟﻮﻳﺐ‬.4.1
MasterPages .5
Sitemaps .6
Validation Controls ‫ أدوات اﻟﺘﺤﻘﻖ‬.7
‫ ﻟﺘﺨﺰﻳﻦ اﻟﺒﻴﺎﻧﺎت‬State Managment .8
Control State .8.1
ViewState .8.2
Session .8.3
Cookies .8.4
Application .8.5
Cache .8.6
Global.asax .8.7
‫ وﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت‬ASP.net .9
DataGrid .9.1
WAP .10
WAP ‫ ﻣﺎ ﻫﻲ ال‬.10.1
WML .10.2
WAP + ASP.net .10.3
‫ اﺟﺎﻛﺲ‬AJAX .11
‫‪29‬‬
‫اﻟﺒﺎب‬
‫‪2‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫ﺗﺤﻤﻴﻞ ﻧﺴﺨﺘﻚ ﻣﻦ ﻓﻴﺠﻮال‬
‫ﺳﺘﻮدﻳﻮ ‪2008‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
30
31
Visual Studio 2008 ‫اﻟﻨﺴﺨﺔ اﻟﻜﺎﻣﻠﺔ ﻣﻦ‬
.1
3P‫ א‬+N‫ א‬، €!'‫و‬PQ3 0.'3 nD Visual Studio 2008 53 KFR 3 ¢ i$D $%'Q
S${ ، a7! ‫'م‬Q 90 i$\ Q{ iH'V i‫'د‬%'3 gNP‫ و‬iH'V 3
— Professional Edition
:a‫אאא‬WSnD
‫رابط‬
http://msdn.microsoft.com/en-us/vs2008/products/cc268305.aspx
‫م‬$+Q23'SPower ISO 23*.isoo3KP,nD‫'ن‬Pa‫אאא‬WS53gFQt‫א‬+N‫א‬
.g‫صאœص‬7‫'دא‬%‫و‬53$9‫و‬gFQt‫א‬hO\‫א‬U DVD ‫و‬C CD ‫'د‬%‫و‬i[
:NS53 Power ISO 23KQNNP>
‫رابط‬
http://www.freedownloadscenter.com/Utilities/Backup_and_Copy_Utilities/PowerISO.ht
ml
:a‫אאא‬WS53€!'‫و‬PQ353product key‫אل‬G1.،3P‫א‬+N.Z‫א‬UG—€N‫‘ذא‬
‫رابط‬
http://msdn.microsoft.com/en-us/vs2008/products/cc263903.aspx
HI . ‹ 53‫ و‬، Visual Studio 2008HI .‫ و‬Add or Remove ProgramsHI . ‹ 53‫و‬
.:H€!'‫و‬PQ3€3.W‫א‬product key‫لאل‬I‫د‬....Change/Remove
32
Visual Studio 2008 ‫اﻟﻨﺴﺦ اﻟﻤﺠﺎﻧﻴﺔ ﻣﻦ‬
.2
a‫אא‬nDًBS${ ،5QH'1F‫ً'ل‬MQ‫'!א‬، €!'‫و‬PQ3S!'t‫א‬3P‫א‬¢N!s‫א‬
:‫א‬
‫رابط‬
http://www.microsoft.com/express/product/default.aspx
^‫א‬KL‫א‬$gNP‫ و‬Professional Edition3P‫א‬¢N‫א‬53hP39‫א‬UK.‫ א‬Express‫אل‬¢N‫א‬lWS
:ˆ‫א‬a‫אא‬U‫א‬¢N‫א‬${،€h‫و‬$‫א‬H'13K.53ً3‫א‬$+‫א‬
234‫א‬
+N‫א‬
.net Q'1 J nD Basic ‫ אل‬X'] .net 2008 ‫ אل‬53 +
http://go.microsoft.com/?linkid=7653517
Framework
.net Q'1 J nD C# ‫ אل‬X'] .net 2008 ‫ אل‬53 +
http://go.microsoft.com/?linkid=7653518
Framework
.net Q'1 J nD C++ ‫ אل‬X'] .net 2008 ‫ אل‬53 +
O+\‫א‬h71‫جא‬9‫م‬$+Framework
http://go.microsoft.com/?linkid=7653520
zT9 iH'13 h‫دوא‬C !' .net Framework nD N3 Q'1 J
3$73GQ‫و‬h71
http://go.microsoft.com/?linkid=7653519
gh$D‫'א‬.zT9+!'Q،H'gT\‫א‬h‫א‬$D‫'א‬.‫(م‬
.net53‫א‬03K3‫א‬
http://www.microsoft.com/express/sql/default.aspx
33
‫ وאل‬gadgets ‫אل‬zNFDKgt‫א‬i$Q$Ž‫و'!€א‬PQ3h‫دوא‬C$C
mash-ups
http://www.microsoft.com/express/popfly/default.aspx
VS 2008 ‫ إﻟﻰ‬VS 2005 ‫ﺗﺮﻗﻴﺔ ﻣﺸﺮوﻋﻚ اﻟﺬي ﻳﻌﻤﻞ ﻋﻠﻰ‬
.3
.:VjVI53i‫د‬O net 2008.nDKFnet 2005.‫ ل‬I53c\‫א‬D‫و‬T353+!NP>
.i,3.Z‫©א‬3g(‫و‬net 2008.‫ ل‬I53‫وع‬T\‫א‬O.
•
.NextHI.
•
>$7‫ א‬+N‫ א‬ªO ‫ 'د‬W‫ن א‬P\‫ א‬HI . ، hO\‫ א‬53 ‫ א‬+ KFD HI .
•
.:!ً‫א‬
.FinishHI.
•
.KF‫א‬zg‫א‬$zg9Q7nDKVR‫و‬،.Z‫א‬zg‫א‬
•
V *jVœ‫ א‬KQ$ ، 2005 03 ً 7!‫'א‬3 ‫ زאل‬9 :NP‫ و‬2008 ‫ ل‬I 53 KFQ D‫و‬T3 ‫( !¦ن‬R‫ א‬n
:‫א‬h‫'א‬1œ.a7!2008037!‫'א‬3
.‫وع‬T\‫*א‬jVIHI.Solution Explorer53
•
.ON„‘Option InferHI.CompileGQ'‫א‬53
•
.net Framework V Target frameworkHI. Advanced Compile Options53‫و‬
•
..net Framework 2.0.53ً9$3.5
t‫א‬h‫א‬Hœ‫}!א‬.‫وع‬T3‫א‬U، 200803ًj7$%'t‫א‬0%‫!™א\א‬s‫א‬D‫'ن‬P‫אšن‬
.'1\‫א‬0%‫!א\א‬s.‫و‬References„‘‫ل‬79.،S$Q
34
‫‪35‬‬
‫اﻟﺒﺎب‬
‫‪3‬‬
‫اﻟﺠﺪﻳﺪ ﻣﻊ ‪.net 2008‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
36
37
ً7z$‫'دא‬CS„‫אو‬17N‫א‬،Y3SY17‫אض‬Z!‫א‬nD$DXP‫א‬53zŽ‫אא‬WSU
hN7‫ א‬5D €.'‫ ™ א‬X‫א א‬WS U E$RN ، „‫ אو‬iF 234 _ C ^‫ א‬17N‫ א‬، .net 2008
X‫אא‬WShRObG7‫ن‬C¤
MQ5!‫אس‬Uً435P_'!، .net 2008Uhg&t‫א‬i$Q$Ž‫א‬
.‫א‬Xi,3ˆ1N
t‫ א‬hN7‫ א‬K K .net 2008 03 hg& t‫ א‬i$Q$Ž‫ א‬3‫ א‬hN7‫ א‬a7! @ X‫א א‬Wg ‫'د‬V7\‫א‬
USH‫و‬$g,t‫وא‬a7!hN753.net FrameworkKFDH‫א‬KI‫دא‬K3P‫א‬D$‫א‬n7€Rb‫א‬
.3‫د‬.‫وس‬H‫د‬U:Df‫!א‬4‫_א‬DU$Q$Ž‫א‬3C،ً79VON3‫وس‬H‫د‬
SliverLight ‫ﺗﻘﻨﻴﺔ‬
.1
%''NP‫وא‬N7‫ لא‬Uj‫א‬O\‫א‬G—Ce‫‘„)و‬3‫و'!€אא‬PQ3h53z`
t‫א‬h71K^3CKRGQ'‫شא‬DnD Flashh)H‫א‬7‫א‬iD‫و‬RF SilverLightN7€
.‫אج‬I9‫لوא‬I‫قא–د‬nD‫د‬FD9‫وא‬CR\‫א‬Q$F\‫مא‬$+
53 ، g[ SQ'1 ‫ ق‬U }H ‫و‬C − 1œ Flash ¤[ P\‫ א‬Adobe , €C ‫ن‬C $ }H‫و‬
Adobe,hZ,‫א‬WN3QHW%h‫
א‬q$gTQ_W‫! شא‬¤[0Q‫א‬Q'1‫א‬UghC$−!H$Q
k‫و‬C، Action ScriptnD$Fh)E ‹‫ אšن‬AdobeTb]!، MacroMedia,53:.'7
‫ ل‬I53!N\‫א‬aInDSun,€I‫د‬F!،ApolloN7ً‫
א‬IC‫و‬FlexN7‹53‫و‬Flash'SSg,C‫و‬
‫ אل‬FQ 17N‫'ن א‬P }H‫ و‬، QgN‫ א‬U NRV3 U GVN $] ‫א‬WS‫ و‬JavaFX Script g`N3
_FD$nDt‫ وא‬HD Video.$‫א‬D'Q$!KqT:FD$‫ ش‬O‫א‬h).5D SliverLight
.−3'3GnD−$‫אא¡ل‬WS‫'ل‬I‫د‬gN3,‫ول‬
:SliverLight0.'3iHQ‫ز‬z%‫א‬N7‫א‬lWS5D$Q\‫א‬5Df
‫رابط‬
http://www.microsoft.com/silverlight/default_ns.aspx
h‫א‬H$.‫و‬hP3‫`א‬S$C$، Get SliverLight‫'ع‬s'\‫א‬a‫אא‬53 SliverLightKFR.Q‫א‬$
.SliverLight
38
SliverLight hP30F‫وא‬،AICi30.'\‫`א‬.‹53‫و‬،: SetupKFD‫و‬234‫א‬KFR.
.‫ق‬O‫א‬ª9‫و‬...
:SilverLightN7nDًMQ‫א‬$Ft‫אوא‬0.‫א\'א‬X%
0.'\‫א‬
iH'b
http://silverlight.net/samples/1.0/Page Turn/default.html
/http://www.yeejie.com/silverlight_magazine
LINQ ‫ﺗﻘﻨﻴﺔ‬
.2
z%„‘‫ م‬9‫א‬KQ'N7‫א‬lWS،h‫א‬$D‫'א‬.‫ل‬U€!'‫و‬PQ353i$Q$%N7
.4‫א‬q‫ ل‬I53i,3iH'VhNjP‫'لوא‬7L‫אولوא‬$Ž‫א‬03K3‫א‬Q}4‫א‬q53
:lWS‫ م‬9‫א‬B‫אض‬Z!‫א‬5P>0Q‫^ل‬F
SQL Server
Select companyname from customers
‫ﻛﻮد‬
U ‫ م‬9‫ א‬2 ${ 5P‫ و‬، NNQ 3 ‫א‬WS @ ... 7Q ‫אم א‬$+ SWON Q
NP> IŠ ‫ א م‬KF ، gz‫א‬. 01 ، iz‫א‬7‫ א‬7Q G ً ^3 RS.Fields("FieldName")
:Q‫אد‬7Q15jP‫א‬UR‫‹א‬53‫و‬iz‫א‬7Q‫د‬DLoopKFDNP>،$Q$%53iz‫א‬7‫א‬
39
C#
do
{
Console.WriteLine( Rs.Fields(“CompanyName”));
}
while(Rs.Read());
‫ﻛﻮد‬
VB
Do While(Rs.Read())
Console.WriteLine (Rs.Fields("CompanyName"))
Loop
‫ﻛﻮد‬
KP,nDg3K3‫א‬Qh‫א‬$D‫'א‬7!‫אšن‬3C،h‫א‬$D‫'א‬.03K3v\‫א‬HI9‫'א‬S‫א‬WS‫ن‬
KI‫دא‬533‫אא‬WS‫ض‬ZON،gbI Operators k‫ و‬functions‫ و‬methods ‫ و‬Members k Clases
.i,3 .net ‫אل‬
C#
var queryResults = from cust in customers _
select cust.CompanyName
‫ﻛﻮد‬
VB
Dim queryResults = From cust In customers _
Select cust.CompanyName
‫ﻛﻮد‬
gz‫א‬.P3b‫א‬t‫א‬k'7‫و‬gVjVIki,3JO queryResults03K3‫א‬P3b‫وאšنא‬
.KVON7‫א‬lWS5Dˆ9XUfN،i,3
.
WPF ‫ ﺗﻘﻨﻴﺔ‬3
Windows presentation ‫ل‬HVI‫א‬S‫و‬H'N‫‘„א‬SH'g&WinFx$g,t‫א‬i$Q$Ž‫א‬hN7‫א‬53i$‫وא‬
‫‹ ‹אد‬n‫و‬CjN‹hg%‫א'א‬ob'‫م‬$+qS‫و‬XAMLSAI‫א‬N7nD$Ffoundation
ًMQ‫ א‬P3 K(Q F!، QH'! iH'V XAML ‫ 'د‬$' Q net 2008. ‫ ل‬I 53 WPF nD FD zN‹‫ א‬،
40
hROb U E$d ‫ ن‬F ‫'د אد‬P‫ وא‬XAML ‫ אل‬Y K3P‫ א‬KVO‫ א‬Q . h‫د‬HC ‫ ‘ن‬XAML X P‫א‬
.GQ'‫א‬
‫؟‬WPF‫אم‬$+‫\ذאא‬
FV‫ א‬23‫ א‬53 3 H'g& „‘ ‫د‬. XAML ‫אم‬$+ FV‫ א‬Y‫ و‬4‫ א‬q Y K3P‫ א‬KVO‫א‬
U‫'د‬P‫א‬GP‫! شو‬nD‫אو‬،X',''!nDFVOK§،XAML‫'د‬$'t‫א‬VV+\‫א‬
nD FV‫€א‬F‫€א‬N'v5P_t‫א‬FV‫א‬i'.‫و‬PR‫א‬53ً‫א‬$Q3RNF‫א‬WS@‫א‬، net.
t‫ א‬iSŽ‫م א‬L‫ א‬53 D'F $` ً MQ‫ א‬، FV‫'د و@ א‬P‫ א‬3$œ ً b‫ א‬FV\‫ א‬Visual Studio
.234‫א‬g(3Y‫و‬KF{nD¤$D
،net framework 3.5.K.9‫א‬nD‫و‬Cnet 2008.KFR€F.$]€]!N3ً3€N‫‘ذא‬،QgN‫א‬K.
„‘ ‫ ج‬9 }H ، Q$7‫ א‬hg%‫ א'א‬Y‫ و‬gN ‫ق‬O‫ א‬$S,‫ و‬، ^3‫ א‬lWS nD ‫  ع‬KSp3 €]! ‫א‬W
‫ 'ل‬3'gO3 q ‫ א‬7‹ ‫ و‬، H'V‫ אو ذج א‬i‫'د‬%'\‫ א‬hS'Q$O‫ א‬nD 0‫ א‬a7! 234‫ א‬KF
:$‫‘„א‬hg%‫لא'א‬B
0.'\‫א‬
iH'b
http://blogs.msdn.com/tims/archive/2007/02/02/
great-wpf-applications-6-fnac-com.aspx
http://blogs.msdn.com/tims/archive/2007/03/05/
great-wpf-applications-12-roxio-central.aspx
41
http://blogs.msdn.com/tims/archive/2007/02/09/
great-wpf-applications-8-notescraps.aspx
Expression ‫ﻣﺠﻤﻮﻋﺔ‬
.4
53l
—‫ شאو‬O‫وא‬CX',''O‫א‬nDg%‫א'א‬FV\‫'مא‬7Q،FV‫א‬FDUً .z‫א‬H'‫‘„א‬$N
Flash ‫ ل‬I53hL‫وא‬3‫وא‬9‫אو™א‬،ROV‫א‬Ugs‫وو‬H'V‫א‬017ً79Q،FV‫א‬23‫א‬
.4‫وא‬FV‫א‬FDYً3ً V!${،‫א‬WPS‫و‬...4‫و‬C.'\g7‹53‫و‬
، h71‫ א‬FFV3 h%9 lQ'1 5D €!'‫و‬PQ3 €ND‫ˆ א‬1 Expression 'Q‫ 'د‬03‫ אšن و‬3C
NP> XAML ‫'م ج 'د‬7Q €!'‫و‬PQ3 ‫ אج‬53 FV 23 ‫אم‬$+‫ א‬P3 ‫ אšن‬bC .ً MQC Expression BLEND ‫ ل‬I534‫א‬NP>F،i,371U:3‫א‬$+‫א‬
−
L‫א‬h‫‹א‬p\‫وא‬H'V‫وא‬Q$F\‫א‬Q'1 BLINDS ،jHh710H‫א‬03 MS Expression H$VQ
$Q$,−‫وز‬$NQ'‫א‬h713$œ‫س‬9:%'3'S‫ و‬Design'S^‫ˆא‬1‫א‬، −‫! ش‬234:T‫א‬$Q$,
'S‫و‬،ً‫א‬$%DA'}€Z–‫א‬0.‫'א‬3FVb‫ א‬WEB ‫אل‬K%'S^‫א‬، −X',''O:T‫א‬
I‫א‬، XAML ‫ و‬AJAX D‫ د‬K%‫ א‬53 ‫ ًא‬$% 3$73 hP3 5P‫ و‬Microsoft FrontPage ‫ ل‬H'1‫א‬
. Expression Media :! I‫'و‬Q$O‫وא‬Q$\‫א‬03K3*V†
L c— 0.'3 „‘ ‫و‬C .'3 KQ' b‫ א‬Blinds 'S gN ig, ^‫ˆ א‬1‫א‬
:234j‫א‬,T‫א‬SlWS،'g‫א‬Q—Uً‫א‬3‫א‬:! I‫و‬h‫‹א‬p\‫و‬
42
€3. – N7‫ א‬0.'3 53 ‫و'!€ אƒ אو‬PQ3 0.'3 53 ‫'م‬Q 21 i$\ Q{ + KF NP>
N7‫א‬lWSnDfNF - .€!'‫و‬PQ\ Parteners ‫אل‬hT‫א‬A$‫א‬53N7‫א‬z‫א‬T€!'‫و‬PQ3
.XP‫אא‬WSU79‫وس‬H‫د‬5FsVO3iH'V
WCF ‫ﺗﻘﻨﻴﺔ‬
.5
‫אو‬hPT‫א‬nDz‫'א‬،‫ل‬V‫א‬0s‫و‬UKFt‫א‬23‫א‬4‫مא‬$§t‫א‬i$Q$Ž‫و'!€א‬PQ3hN7A$‫א‬S
lWg!FgM5Q‫ز‬g%aH:!Q23‫א‬HVI...:! I‫وو‬ZP9‫א‬$Q4‫א‬h3$I‫`و‬N\‫א‬K^323‫א‬
.‫ض‬q‫אא‬Wkg%'3N7‫א‬
K%‫א‬53i$Q$%N7€!'‫و‬PQ3Nhz%، .net 03 Sockets J!‫ و‬6‫!`'אل‬U Winsock $
. Windows Communication Foundation ‫ل‬HVI‫א‬S‫ و‬WCF ‫ل€א‬V9‫א‬hFD
K3P3‫و‬53Š Server And Client ‫دم‬I‫و‬KFDˆ1KFD01–HVI!،N7‫א‬lWS‫\ذא‬3C
!!!‫'د‬P‫א‬53a7!1‫א‬iTD53K.‫ لא‬I53
.hN7‫א‬.Y‫و‬gNhH7F‫ق‬1f'WCF5DKVO\‫א‬NH‫د‬U،7‫א‬hN7‫א‬53‫ع‬CgCF
43
Code Refactoring
.6
53D'FSHVIiPO‫א‬،'Q‫`'אل'د‬O‫ אœص‬IDE ‫אل‬gz%t‫א‬i$Q$Ž‫א‬h‫א‬F\‫א‬A$‘
.:3K3‫א‬Kg‫'دو‬P‫(א‬NnDi$D\‫א‬Kj'‫א‬
5FM3 gN3 $‫ وא‬bC .net 2008 03‫ و‬، i$D3 23‫ א‬KP, nD 23‫א‬4‫ א‬lWS K^3 !' Q i‫ אد‬U
KQ$‫א‬،hJ!Uh‫
א‬q\‫א‬23$،H‫ز‬1qM
q\*jVIzT‫א‬53!s9‫א‬lWSNPe،s‫א‬Z!‫א‬iH'V
.j3g%‫א'א‬WSK:! I‫و‬h‫א‬Z3H‫وא‬hJO‫א‬U
q‫وא‬
. Refactor! for Visual Basic 2008‫!`'אل‬K%234‫אא‬WSK^3AIC23‫א‬¤NSًMQ‫א‬
:a‫אאא‬WSnD‫'د‬%'3234‫א‬
‫رابط‬
http://msdn.microsoft.com/en-us/vbasic/bb693327.aspx
:‫'د‬P‫א‬iW!nDgOMQt‫א‬h Q$‫™א‬iH'blWS‫و‬
bœ‫א‬lWSNPe، 2008Us‫א‬Z!‫א‬iH'VNFM3S‫ و‬Code Snippet bIًMQ‫و'!€א‬PQ3!'
5P> Fj. 53 '1\‫ א‬Fg\‫ א‬HI ‫ ذ‬Q ، $‫ وא‬1 ‫ون‬$ N3 F K3 ‫אج 'د‬H‫ אد‬53
K%‫א‬53:ً ^3$`‫!`'אلو‬K%‫א‬53234‫אא‬WSi‫ود‬،i$Q$%‫!א'אد‬s‫وא‬g!Q$R‫א‬
:XH,
‫رابط‬
http://msdn2.microsoft.com/en-us/vbasic/bb973770.aspx
44
:234iH'blWS‫و‬
bI gNP‫ و‬، a7! 2008 ~ ً bI 39‫ !@ א‬2005 nD KF h‫א‬H‫א‬$b‫ א‬¤NS ‫ ًא אذ ]ن‬IŠ @‫
ًא و‬I‫א‬
.Visual Studio 200803ًs‫א‬Z!‫א‬NFM3‫€אšن‬Rb‫א‬
‫‪45‬‬
‫اﻟﺒﺎب‬
‫‬
‫‬
‫‬
‫‪4‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ‪ .net‬اﻟﺮﺋﻴﺴﻴﺔ‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
46
47
.net ‫ﻟﻐﺎت‬
.1
53H\‫אא‬WSv”...hqi$D:3$+.H35DiHDSK،i$‫وא‬q .net 49
hq U g. 1‫ א‬i$D. ‫'ن‬P H\‫א א‬WS hT‫ א‬53 $Q$‫€ א‬N‫ و‬2000 ‫و'!€ 'א אم‬PQ3 K.
9‫و‬K‫@א\א‬ONً‫א‬H‫و‬3gO%Z‫و‬،:OH$V\‫'دא‬P‫א‬k‫¦ن‬hq‫א‬lWS0BF،4‫א‬
5P‫و‬..3 Engine q‫א‬¤[9‫א‬h'P\‫א‬nDf‫'م‬7N...—V‫א‬7QUA'o§
.net .H3€Nt‫א‬hq‫™א‬nDfNً .
C++/CLI „‘ !s‫ א‬، J#.net ،VB.net ، C# M t‫ وא‬gON €!'‫و‬PQ3 SH$V t‫ א‬hq‫ א‬$!
n‫ ''ل و‬، O‫ل ود‬P K^3 .net QH3 D$ t‫ א‬AI‫ א‬hq‫ א‬¤NS JScript.net ... ‫
ًא‬IC‫و‬
.DN1b–‫א‬zW‫א‬h714LISP.net
..@PN‫א‬J€ .net QH3D$Qً ^3 mono f، Linux JnDKFt‫א‬h‫א‬H‫א‬$b–‫ًא‬MQ‫א‬nN9
‫—אض‬9 }H VB.net ً 79 :‘ MN ، C# 'S .net J 3$œ 9‫ א‬2N\‫ ن א‬$7! QgN‫ א‬U 5P
4 1.H X'9‫ א‬3ً3'Q:®$.D'F`F f# ‫م‬FM‫אنא‬nN9 ،hq‫א‬0S$C$‫و‬7Q'
.net .N7
:NSgNDh VO‫™א‬03QH\‫א‬lWSD$t‫א‬hq‫א‬KFnD‫ ع‬9‫א‬QgN‫א‬U01
‫رابط‬
http://www.dotnetlanguages.net/DNL/Resources.aspx
‫اﺿﺎﻓﺔ‬
:XU
Pro C# 2008 .NET 3.5 Platform -Exploring the .NET universe using curly brackets
„‘QgN‫א‬UًB‫''א‬R‫دאم‬3 .net hq53‫د‬$‫אא‬WSK‫\ذא‬،:DG®‫ًو‬9¯GP‫א‬v1Q
:X‫א‬i$‫אא¯ل‬WSnDG®‫و‬maneged code
‫؛‬XP‫א‬X'‫א‬KMOQgM!،g'd‫و‬g‫'ن‬4Qt‫א‬qً‫א‬$%YY4\‫א‬53$Q$‫ אنא‬−
nN9، Visual Basic hq Syntex K^3iz‫א‬7.^‫א‬X'9‫א‬Iš‫א™א‬KMOQF!...‫'אس‬.‫وא‬
48
‫ و‬Basic ‫ و‬C# 4\5P> .net 03KFY4\‫א‬0BXW%‫و)و‬7Q'‫א‬H‫و‬$‫א‬NS
0F`!s‫א‬Kg‫א‬gNk7‫א‬K®3‫א‬WS‫و‬،i$‫وא‬VN3€ًBKF‫ א‬Delphi ‫ و‬Fortran ‫و‬C++
.i$‫(وא‬3€Y4\‫א‬
‫'ن‬4QY43$‫ˆא'א‬QO‫א‬U${‫אن‬5P>،i‫د‬$3hqY43$‫ˆא'א‬QO‫א‬HT3 −
OQ‫א‬WS،q‫@א‬ONY4\‫'نא‬PQ‫אن‬KMO\‫א‬53‫אنن‬$QgN‫א‬U$‫وא‬2N3‫אج‬I‫א‬Q‫و‬hqi$
.Y4\‫א‬HI‫א‬UhT‫مא‬3‫^
אًא‬h‫א‬HI9‫א‬
sQ‫א‬hF‫א‬UiŸhq¤NSً ^F!،g3‫א‬$+9‫س‬N‫א‬1Mi'.‫ط‬7NFhq‫ ™א‬−
01‫א‬WPS...L‫א‬hF‫א\وא‬h 3‫א‬UًMQ‫א‬iŸ‫''ل‬P‫א‬،‫אن‬H'O‫א‬K^3h9‫وא\د‬
.net .J€gM03ًBg$‫و‬h‫א‬F\‫א‬lWS53i‫د‬O9‫א‬
.net ‫اﻟﻌﻨﺎﺻﺮ اﻷﺳﺎﺳﻴﺔ ﻟﺒﻴﺌﺔ‬
.2
hN7‫א‬lWS، .net JnD$F\‫א‬234‫א‬iiH‫دو‬UPRjHbNDE ‹gY .net ‫م‬$7
. : CLR, CTS and CLSzƒ]ً‫א‬HVI‫א‬k3QE ^‫א‬
:Fg3، Common Language Runtime‫ل‬HVI‫א‬S‫و‬،234 Runtime Layer ‫ אل‬CLR ‫אل‬K^e
U h‫
א‬q\‫ و` א‬− ‫وאل‬$‫ وא‬hP\‫ א‬.net - K j‫ א‬h'P\‫ א'אع وא‬U PR‫ א‬S 9‫א‬
$Q$,HVI"،‫ن‬3‫א‬h‫א‬HVI‫!™א‬s‫א‬WON‫ وא‬threads ‫אل‬،g3K3‫وא‬i‫א‬W‫א‬7‫و‬i‫א‬W‫א‬
.'3'P‫زא‬g%nDSWON‫ و‬.net 3‫وא‬CBZ9‫ א\א‬CLR ‫אل‬KPT
3'D$\‫ א‬h‫ א'אع א‬03 K3 *† CTS X lHVI‫ א‬Q W‫ وא‬Common Type System ‫אل‬
U3'D$\‫'אع—
א‬9‫'د™א‬%‫و‬iD‫א‬303،gMY‫و‬gNK3‫א‬Qo‫و‬، .net J5FsKF
Common Language S‫ و‬i
I‫ א‬3C ، AIC‫ و‬J Y h! I‫ א‬g $%' t‫ وא‬.net hJ 0B
3'D$\‫وא‬7‫א‬h‫א'אعא‬03a7!K3V†g! CLS 3SHVI‫א‬Qt‫وא‬Specification
. .netJh‫א‬H‫א‬$b‫א‬0B53
'S CLS U \‫ א'אع א‬a7! ‫م‬$+Q‫^ ً و‬3 C# ‫אم‬$+ FV\‫ א‬234‫'ل אن א‬7 ‫ אن‬01 ‫א‬Wg‫و‬
‫ج‬HI€%I'3‫א‬، mono lF\‫ א‬Linux nDKF‫א‬K%‫א‬53 .net Q‫@'ز‬OnDKFً3eˆ!‫'א‬3
.O+\‫א‬F(‫א‬KUizOP‫@א‬ONSWONQ‫אن‬5FM5! CTS „‘ CLS‫قאل‬1
49
Base Class Library
.3
‫وאل‬$‫وא‬3‫אوא‬nD'd ClassJ!5DiHD'S‫و‬، Base Class Library fQ3 .net N7!'
،7Q1‫@א‬ON:VjVI03‫و‬:3K3‫א‬Q‫ و‬.net hJ0BU‫'د‬%'3 JO‫ א‬lWS، .net JUj‫א‬
GUI ‫אل‬، XML ‫אل‬، Threads‫אل‬،h‫א‬$D‫'א‬.‫و‬hO\‫א‬03K3‫א‬K^39‫א‬bN‫א‬Class‫אل‬MQ
t‫א‬hq‫א‬53C03K3PK.‫و‬.KgC‫و‬$'34‫א‬X'‫א‬K%UP\‫א‬lWSS‫و‬.:! I‫و‬
..netD$
:€!'‫و‬PQ353 BCL ‫אل‬hQ')™‫ول‬$Ž‫אא‬WS
‫ אل‬nD ً MQ‫' א‬d ، .net h71 Q'1 :% 3 K nD System 'd ، Q BZ‫و‬
zƒ‫لא‬S System ‫אن‬${$Q$,HVI،‡‫א‬..L‫א‬hF9‫وאلא‬$‫ وא‬Datatypes
.hJO‫א‬.nDg't‫وא‬j‫א‬
ob'‫א‬
JO‫א‬
SWON‫'אدو‬9‫א‬PbI
System.CodeDom
. Lists, Stacks K^3‫'אع‬9‫א‬53‫د‬$DnD'
System.Collections
Process‫ وאل‬Counters ‫ وאل‬Events ‫אل‬MQ
System.Diagnostics
53 O† ( nD KqT ˆQ
System.Globalization
.:! I‫و‬F.9‫א‬h‫אدא‬$D9‫وא‬hq‫א‬
ˆQ5Dz‫'א‬h‫لא‬7‫ˆضوא‬Q3K
'3'P‫ א‬W!N3 ˆQ 5D‫ אو‬، h‫א‬$¡‫ وא‬hO\‫א‬
Serial Port‫אل‬K^3
System.IO
50
KFDQ،234‫א‬oVt‫ א‬Resources ‫אل‬
System.Resources
‫א\^ل‬KnDhq‫א‬i‫د‬$3h71
‫'ص‬VN‫א‬03K3ˆQ3K
System.Text
RegularExpressions‫אل‬03K3‫א‬
System.Text.RegularExpressions
.Net Assemblies
.4
U‫'ل‬RQ‫'د‬P‫!¦نא‬، .net h71zN:3$+W‫ א‬Compiler ‫وאل‬4‫א‬q€Fg3‫و‬QgN‫א‬U
:s‫و‬Q‫و‬، metadata ‫!‘„™אل‬s9 IL ‫ ًא‬HVI‫א‬fQ3'S‫ و‬intermediate language ‫ل‬QgN‫א‬
dll KP,nD‫و‬C exe KP,nDz‫'א‬i,3KFK.ƒ‫א‬o3U
‫ل‬HVI C 7 ‫!א‬s‫€א‬F!‫אšن‬3‫א‬،€!'‫و‬PQ\HVI‫ א‬MS ‫ وאل‬MSIL IL K3Q‫ًن‬7
.7‫ א‬MS 53ً9$Common
nD'R! metadata ‫אل‬3‫א‬،:,3‫وא'אدو‬234‫א‬g‫'م‬7Qt‫مא‬g\‫ א‬MSIL ‫وאل‬C IL ‫אل‬K^>
‫ وאل‬IL ‫ אل‬MQ W‫ א‬:O ƒ9‫ א‬o3 ، U g3$+‫ א‬t‫ א‬hJO‫ א'אع وא‬0FŽ ob‫و‬
${ h9 ¤NS ، D'F¡‫ א‬lWk ً MQ‫ א‬manifest !s‫ א‬Q ، ً MQC metadata X :Ob‫ و‬Q metadata
Ua7!$‫ وא‬manifest A'Q$‫'ن‬PQ5L‫א‬lWSU‫و‬،ƒ‫א‬o353^ً13g!
.™‫א‬gM03hO\‫א‬aH‫و‬Q‫א‬$‫א‬KF‫'م‬7QgN3$‫وא‬
CIL ‫ال‬
.5
Pro.CSharp 2008X53 C# q234‫אא‬WS‫ض‬ZON
C#
// Calc.cs
using System;
namespace CalculatorExample
{
// This class contains the app's entry point.
class Program
{
static void Main()
‫ﻛﻮد‬
51
{
Calc c = new Calc();
int ans = c.Add(10, 84);
Console.WriteLine("10 + 84 is {0}.", ans);
// Wait for user to press the Enter key before shutting down.
Console.ReadLine();
}
}
// The C# calculator.
class Calc
{
public int Add(int x, int y)
{ return x + y; }
}
}
:‫'دא‬P‫א‬$`ILDASMK^3GN3ˆ1C‫אم‬$+‫'د‬P‫אא‬WS5D2N‫ƒא‬9‫א‬O€F.'
‫ﻛﻮد‬
.method public hidebysig instance int32 Add(int32 x,int32 y) cil managed
{
// Code size 9 (0x9)
.maxstack 2
.locals init (int32 V_0)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldarg.2
IL_0003: add
IL_0004: stloc.0
IL_0005: br.s IL_0007
IL_0007: ldloc.0
IL_0008: ret
} // end of method Calc::Add
‫א\א‬U‫ذ‬Q،Platform-Specific Instructions„‘‫'د‬P‫א‬KQ'Q_،\‫א‬lWSn
‫ز و(م‬gŽ‫ א‬hP39 GN3 ‫ ‘„ 'د‬2N‫'د א‬P‫ א‬BZ ‫'م‬7Q W‫ وא‬Jitter fQ 3 ‫ ل‬I 53
.234‫א‬:DKFQW‫א‬KqT‫א‬
:€!'‫و‬PQ353a‫אאא‬WS53‫'ع‬s'\‫אא‬WS5D$Q\‫א‬nDf‫א‬P3
‫رابط‬
http://msdn.microsoft.com/en-us/library/f7dy01k1(VS.80).aspx
52
MetaData ‫اﻟـ‬
.6
::! I‫و‬hg%‫ووא‬hJ!‫دوאلو‬53‫'د‬P‫א‬hQ')Kob'‫م‬$+t‫ א‬MetaData nD‫^ل‬3
‫ﻛﻮد‬
TypeDef #2 (02000003)
------------------------------------------------------TypDefName: CalculatorExample.Calc (02000003)
Flags : [NotPublic] [AutoLayout] [Class]
[AnsiClass] [BeforeFieldInit] (00100001)
Extends : 01000001 [TypeRef] System.Object
Method #1 (06000003)
------------------------------------------------------MethodName: Add (06000003)
Flags : [Public] [HideBySig] [ReuseSlot] (00000086)
RVA : 0x00002090
ImplFlags : [IL] [Managed] (00000000)
CallCnvntn: [DEFAULT]
hasThis
ReturnType: I42 Arguments
Argument #1: I4
Argument #2: I42 Parameters
(1) ParamToken : (08000001) Name : x flags: [none] (00000000)
(2) ParamToken : (08000002) Name : y flags: [none] (00000000)
‫'م‬7 ‫ אن‬.net nD KF €‫ وא‬NP> ، ‫^ل‬3 ‫ول‬C U :P NF. W‫'د א‬P‫ א‬ob' ˆ‫ א‬zŽ‫'م א‬7Q
nD‫و‬$‫א‬KQ$ً3'Q‫ج‬5}H:‫א‬$7D‫א‬،gOvT‫و‬Rs‫طوא‬7N‫א‬G—‫א‬،‫'د‬P‫אא‬WSnD‫ ع‬9
.o\‫אא‬WS
Manifest ‫اﻟـ‬
.7
o\‫אא‬WSoVQ، Assembly File 53^‫א‬¤NS‫'ن‬n23KPo\‫אא‬WS53a7!i$‫ وא‬+
‫^ل‬3‫א‬WS،o353^‫'دא‬%‫و‬Uj‫ƒא‬9‫א‬o3‫ƒو‬9‫א‬+.H53:Oƒ9‫א‬
:D'N‫א‬lWS53‫'د‬nD
53
‫ﻛﻮد‬
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
.ver 2:0:0:0
}
.assembly Calc
{
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module Calc.exe
.imagebase 0x00400000
.subsystem 0x00000003
.file alignment 512
.corflags 0x00000001
Common Type System
.8
JU3'D$\‫'אعא‬9‫א‬ob'*†:‫ ˆوذא‬CTSnDV+\‫'عא‬s'\‫אא‬WSUN
S‫א'אع‬lWS،™‫א‬gM03g3O‫و‬.net
Class
-
Interface
-
Struct
-
Enumeration
-
Delegate
-
‫سאœص‬H$‫ لא‬I‫אšن‬NˆQ3‫אن‬9‘،XP‫א‬53O†3UgN3KoQ7QnDfN
3‫ א‬CTS ‫אل‬i$j!53^‫ج\!א‬5!Q‫د‬Dh712343€N‫‘ذא‬،g3 CTS ‫אل‬K3O'SN
nDf‫'ن‬%R! .netQ'1J5Fsq‫ אو‬CompilerzN‫'ن‬3'7Q5QW‫אوא‬h‫'אدوא‬43
ClassnD‫ ًא‬V†ً9^3‫]ذ‬،9‫*א‬jVœ‫א‬
54
‫ ل‬:T‫ א‬$Q$, − ‫ א 'د‬nD 'd 9 Abstract Class ‫ אل‬، Abstract Class fQ 3 ¤NS
‫'د‬1nD'd5:‫א‬:3‫א‬$+‫א‬Uz$‫א‬K.:‹‫א‬H‫و‬KFD‫ذ‬$5P>r interface Abstract Class fQ\‫^ل‬3‫א‬WS،$‫وא‬
C#
class abst_class
{
int sum(int x,int y);
string name;
}
‫ﻛﻮد‬
VB
Class abst_class
Private Function sum(x As Integer, y As Integer) As Integer
End Function
Private name As String
End Class
‫ﻛﻮد‬
Q3'P‫א‬U CTS 03K3‫א‬U€—H'F!g‘‫ج‬Rt‫ א‬CTS ‫*אل‬jVI‫ول‬$%5Fs53‫وאšن‬
Q$‫ ن‬CTS HI‫א‬K.‫ج‬R، Is the class abstract or concrete bœ‫א‬$`.ً ^3‫אœص‬
.‫ط‬7N‫א‬lWSK^}ًMQ‫א‬l4§‫אن‬NSClass
‫ﻣﻼﺣﻈﺔ‬
‫ في دروس قادمة سنشرح بالتفصيل كيفية عمل‬، ‫ال تقلق لو لم تتضح لديك مثل ھذه الخصائص‬
.‫ وانواعه وطرقة المختلفة‬Class
CTS Members
.8.1
gN3K„‘ Members ‫אل‬53‫د‬$D‫!א‬s‫א‬NP>، CTS ‫ ل‬I53O+\‫א'אعא‬ob'€F.‫אن‬$
:ً MQ‫'نא‬P‫אن‬5P>، Fields ‫'ل‬7LQ‫د‬Dh‫
א‬q3‫'ن‬P‫אن‬5P> Members ‫אل‬،
constructor, finalizer, static constructor, nested type, operator, method, property,
indexer, field, read-only field, constant, event
ً ^3 Public ‫'ن‬PQ‫אن‬5P>،Q¯HA$3‫و‬C ( visibility trait) fQ3:Q$zMD‫א‬lWS53$‫وא‬K
55
‫אن‬f‫אن‬NSNNQ3،ًN‫و‬H‫د‬5Fsً79:DfNŸ ‡‫א‬.. ClassJO‫جא‬HI53:Q¯H5P>r
. CTS UgOb'Q*jVœ‫א‬lWSK
CTS DataTypes
.8.2
Pro C# 2008 X53‫ول‬$Ž‫אא‬WS، .net K.533'D$\‫ א‬DataTypes ‫אل‬nDًMQ‫ א‬CTS ‫'אل‬d
:E ^‫א‬9‫ א‬.net hq keywords Ks'03
.net N3‫א\!א‬53‫'ع‬N CTS ‫אل‬i$j!3'\f‫دאن‬Dh71234FFgQ3K
‫א‬WS 53 z$‫ א‬NPF! ، CTS 5D $Q\‫ א‬nD f‫ א‬U G—‫ و‬iPO‫` א‬D‫ א‬$. €N ‫ ‘ذא‬3C ، 9‫א‬
:a‫אא‬
‫رابط‬
http://msdn2.microsoft.com/en-us/library/zcx1eb1e.aspx
56
Common Language Specification
.9
3‫א ز‬h1\‫א‬53n‫אد‬$L‫א‬oV CTS ‫אل‬53 subset S CLS ‫אل‬،ˆ‫א‬%'\‫א‬U‫ذ‬F
QHI‫ א‬CTS hQ') ™ ‫ !¦ن‬، IŠ nN}‫ و‬، .net J € KF q‫ א‬lWS ‫'ل אن‬7‫ א‬01N
CLS UgF{” CTS hQ')53D'F،Iš‫א‬US${9‫ و‬.net hq™US${‫אن‬5P>
.Q'1 .net J‫م‬$+qKPQH%‫'نא‬P
‫م‬$+qKPg7153$9‫و‬gOb'Q‫و‬،QH%9‫وطא‬T‫א‬lWSnD CLS Rules 1V3‫א ق‬Q‫و‬
.Q'1 .net J
‫!אذא‬3P3، CLS ‫אل‬gFMQ9t‫*א‬jVœ‫א‬53i
D'F¤NS، VB.net ‫ و‬C# hqN
!s‫ لא‬I53KqT‫א‬F(C0BnDgFDiD‫\א‬9‫ אم‬CLS‫אل‬5Fs‫'د‬%'3:3$+W‫'دא‬P‫نא‬
:CLS533‫وא‬CnDA''d9C‫'د‬W‫א‬zŽ‫א‬nDC‫'دא‬P‫א‬
‫ﻛﻮد‬
[assembly: System.CLSCompliant(true)]
:NS53iz‫א‬7‫א‬b‫'א‬3NP> CLS ‫'عאل‬s'}ًFg3€N‫‘ذא‬
‫رابط‬
http://msdn.microsoft.com/en-us/library/12a7a7h3.aspx
Common Language RunTime
.10
™q‫ز‬gŽ‫א‬nD‫ אœص‬.net ‫'دאل‬KF'1\‫א‬h3'\‫!א‬M CLR ‫!¦نאل‬،ً7‫ذ‬F
1M3¦!‫!`'אل‬2343€N‫‘ذא‬،‫א\^ل‬GQ7‫و‬،b‫'دא‬P‫א‬g€et‫א‬q‫א‬5D(N‫א‬
€N '3‫א‬،j‫א‬h‫`'אلودوא‬OFV\‫א‬KF‫ز‬gŽ‫א‬nD msvbvm60.dll‫'د‬%'
'S CLR ‫!¦نאل‬،7Q1‫@א‬ON‫و‬...71:DKFW‫زא‬gŽ‫א‬nD JVM „‘‫!!¦ج‬%2343
.'3'‫ز‬g%‫א‬nD .net J€FV\‫א‬71KF:%W‫א‬$'‫א‬o\‫א‬
57
Microosft Common ~ ‫ ًא‬HVI‫ א‬mscoree.dll lF\‫ א‬CLR ‫אل‬P3‫'د‬%'‫ ج‬.net ‫_אل‬DO!
P\‫א‬lWS„‘ƒ9‫א‬o3iH,‫א‬Q‫א‬$03‫و‬z$03،Object Runtime Execution Engine
U TypesK ً MQ‫ א‬Load KFQ ، metadata ‫ אل‬iz‫א‬.‫ƒ و‬9‫ א‬o\ Load KF CLR ‫'م אل‬7Q
F platform specific instructions „‘ CIL Ui‫'د‬%'\‫א‬234‫א‬3‫אوא‬BZ‫'م‬7Qً‫
א‬I‫وא‬،H'F\‫א‬
‫'مאل‬7234‫א‬KFD‫ ل‬I‫و‬،WON CLR ‫אل‬z$Qً‫
א‬I‫א‬...¤‫ز‬g%nDWON‫א‬:NPFً7N7O‫א‬
.Ug3$+€N‫ ‘ذא‬Base Class Ui‫'د‬%'\‫ א‬.net K9‫א‬hJO‫א‬03K3CLR
:lWON‹53‫ 'دو‬native „‘:Q'n‫'د‬P‫א‬K‫א‬3s'QQ$PQ‫و‬53a1+\‫אא‬WS
:NS53z$‫א‬NP>$Q\‫!א‬3UG—€N‫‘ذא‬،i‫ود‬
‫رابط‬
http://msdn2.microsoft.com/en-us/library/8bs2ecf4(VS.71).aspx
58
Object Browser ‫اﺳﺘﺨﺪام‬
.11
:‫א‬,T‫א‬g(، Object Browser ZI‫ א‬View Fj.53
hP\‫אאض!א‬01،O+\‫ א‬Visual Studio h‫א‬H‫א‬$b‫א‬03i!'\‫ א‬Tool ‫אل‬lWS‫ ل‬I53
iqV3iW‫و‬:3‫א‬$+‫א‬7Q،gQt‫ƒא‬9‫א‬hO3‫و‬:P3f‫אن‬01‫و‬، .net Uj‫א‬hJO‫وא‬
.:$j!5D
‫ אو‬، Help Fj. U i‫'د‬%'\‫ א‬z‫ 'א‬MSDN hP3 „‘ z'`‫ א‬NP> gN3 ‫ א‬5D h3'\‫ א‬53 $Q\
. msdn0.'3Ui,3€Z9‫א‬nDi‫'د‬%'\‫א‬
Name Space ‫ﻣﺠﺎﻻت اﻷﺳﻤﺎء‬
.12
gN3ˆT${t‫א‬j‫ א‬namespace‫אل‬S System ‫ن‬Cª ‫אن‬01،7‫وسא‬H$‫ لא‬I53
. AI‫ א‬name spaces ‫אل‬G—C
59
K^3 hJO‫ א‬53 $Q$‫ א‬g ${
Microsoft
IŠ
name
space
¤NS
03K3a7!bIS Micosoft J!537T\‫א‬hJO‫א‬0B‫ و‬Microsoft.ManagementConsole
.ً ^3mono ‫€אل‬KF9g!‫א‬W‫و'!€و‬PQ3h3$I
' g‫ א‬System.Windows.Forms : ‫ א‬name space ‫אل‬O ‫ אن‬s‫ א'א‬53 ‫'ن‬P ، ً 79
. Forms zNg%t‫א‬j‫مא‬g\‫א‬nD
‫اﺳﺘﻴﺮاد ﻣﺠﺎﻻت اﻷﺳﻤﺎء‬
.12.1
‫א‬KPT‫'دאœص‬P‫א‬o3nD‫א‬zƒ9‫א
אدلא‬NP>
C#
using System.Data.SqlClient;
‫ﻛﻮد‬
VB
Imports System.Data.SqlClient
‫ﻛﻮد‬
:i,3‫א‬3‫א‬NPF!،NRs‫אو‬Fzƒ9‫א\^ل
אدلא‬KnD€F.‫‘ذא‬
C#
SqlConnection sql1=new SqlConnection();
‫ﻛﻮد‬
VB
Dim sql1 as SqlConnection=New SqlConnection()
‫ﻛﻮد‬
i3 K U GZ :'I$ 1M3 €‫ א‬L‫ א‬lWS O! ، zƒ9‫ ل א‬U :OQ 7 _ ' ، K7\‫ א‬U
:g!:3$+
‫ﻛﻮد‬
C#
System.Data.SqlClient.SqlConnection sql1=new System.Data.SqlClient.SqlConnection();
60
VB
Dim sql1 as System.Data.SqlClient.SqlConnection=New
System.Data.SqlClient.SqlConnectionn()
‫ﻛﻮد‬
ildasm ‫اﺳﺘﺨﺪام ﺑﺮﻧﺎﻣﺞ‬
.13
Visual Studio 2008 03 7R\‫ א‬23‫א‬4‫ א‬5Fs
234‫אא‬WSNP>، ildasm23Gq‫א‬U${
€F. 23 ] ‫ƒ אœص‬9‫ א‬nD ‫ ع‬9‫ א‬53
CIL ‫אل‬Q¯H53NP>ًMQ‫א‬، .net ‫אم‬$+:F
:234‫א‬53iH'blWS...234‫אא‬Wg‫אœص‬
:ND$Q\‫!א‬3‫و‬234‫א‬53+KFNP>‫و‬
:NS53
‫رابط‬
http://msdn.microsoft.com/en-us/library/aa730858.aspx
‫ ؟‬open source .net ‫ﻫﻞ ﺗﺒﺤﺚ ﻋﻦ‬
.14
t‫ א‬projects ‫אل‬g,‫'א‬S mono project fQ3'S‫ و‬http://www.mono-project.com
.O+\‫'@א‬NhQ‫'ز‬nDKF‫ א‬CIL K
.O†hVN3nDKF‫א‬53 CIL 5P> Portable.NET IŠ‫وع‬T3¤NS
61
: NS^‫وعא‬TFً1‫א‬H${
‫رابط‬
http://www.dotgnu.org
.MONO5D^CVOiH'VfNXP‫א‬533‫د‬.z‫א‬%CU
62
‫‪63‬‬
‫اﻟﺒﺎب‬
‫‬
‫‪5‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫اﻟﻮاﺟﻬﺔ اﻷﺳﺎﺳﻴﺔ ﻟﻠﻔﻴﺠﻮال‬
‫ﺳﺘﻮدﻳﻮ‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
64
65
‫ﻛﻴﻒ اﻛﺘﺐ اﻟﻜﻮد ؟‬
.1
FP3€%9‫א‬lWS‫ن‬C9‘، Visual Studio 2008‫ ل‬I53Sˆ‫אلא‬p‫א‬nDQ$7‫א‬%–‫א‬
CnD .net framewrok 3.5 development kit a7!‫'د‬%‫ لو‬I53‫و‬:‫א‬SRRV‫א‬%–!،ً3e
lWS™nD`DnD‫س‬H$‫אא‬WSUfN، .net 2008 h71Q'1nDً‫א‬H‫د‬.‫'ن‬P¦!‫ز‬g%
Visual Studio 2008 ‫ ل‬I53g3K3Nt‫א‬9‫א‬7Q1‫'لא‬Q$RK7N‫אن‬K.‫ق‬1‫א‬
:a‫אאא‬WS53gFNP>ًj$3
‫رابط‬
http://msdn2.microsoft.com/en-us/library/zcx1eb1e.aspx
Visual Studio 2008 Command Prompt ‫اﺳﺘﺨﺪام‬
.1.1
‫'ن‬P،'1\‫א‬3‫אوא‬nD‫  ع‬csc -? 3‫א‬: I53NP>، C# 4‫'م‬7NN‫א‬NsZ!‫'א‬
‫אل‬$Q$R‫ج‬R،ًQ‫و‬$Qz,KKF1M5P، C# ‫'د‬BZz$‫א‬01!3‫אوא‬lWS
Q3'S‫و‬Q‫و‬$Qz,KKF‫'م‬7'i353$OK7\‫א‬U، ‡‫א‬....hO\‫ƒوא‬9‫ وא‬out
.z‫‘„א‬o‫א‬53234ˆQ3KUPRS‫ذ‬b!
:‫א‬KPT:G—cso39CompileKFDNP>،iH'ba]
66
‫ﻛﻮد‬
csc File.cs
:dllo3„‘:Q'R‫و‬C
‫ﻛﻮد‬
csc /target:library File.cs
:exeo3„‘:Q'R‫و‬C
‫ﻛﻮد‬
csc /out:My.exe File.cs
:$‫وא‬$Ui‫'د‬%'3hO3i$CompileKFً‫
א‬IC
‫ﻛﻮد‬
csc /define:DEBUG /optimize /out:File2.exe *.cs
:€!'‫و‬PQ353a‫אאא‬WS53z‫א‬$‫א‬$Q\‫!א‬3NP>
‫رابط‬
http://msdn2.microsoft.com/en-us/library/78f4aasd(VS.80).aspx
TextPad ‫اﺳﺘﺨﺪام ال‬
.1.2
+ ، z, ] KF *V+ K.‫ و‬z, ‫ א‬nD KF K. :‫ א‬nN} ، Jg‫ א‬i‫د‬D9 K. ˆ1
GQ‫و‬hROb‫אو‬q9Qi‫دא‬g3‫א‬$+‫א‬NP>،KQ$‫وא‬Q'1:. Notepad ‫אل‬53iH'13
*jVœ‫א‬KQ$01€3‫د‬3z,....‫א‬H‫אو‬GZg3‫א‬$+‫א‬NP>...ƒ‫א‬n‫ אو‬HTML‫אو‬
.'1\‫א‬
67
!s‫א‬$،:D vb.net ‫ אو‬C#qoQo3!s‫א‬01‫ א‬TextPad ‫*אل‬jVI5Fs53i$‫وא‬
53+${ Compile 3‫!א‬s‫א‬NP>، visual studioUF ‫א'אد‬5Q'‫'م‬7Ql$`o\‫א‬
‫ א‬a‫ אא‬0 NP> ‫'ع‬s'\‫א א‬WS ‫ 'ل‬$Q\‫ \! א‬، ‡‫ א‬... C# ‫ אل‬q :3$+\‫ א‬RE ‫אل‬
: :N3‫ ق‬19‫وא‬
‫رابط‬
http://www.eggheadcafe.com/community/aspnet/2/10014016/textpad-and-c.aspx
:NS Textpad~‫א‬nDgZob'‫אوא‬4‫א‬hqKhO3${‫אن‬01F
‫رابط‬
http://www.textpad.com/add-ons/cliplibs.html
0s'€F.'، Reguler Expressions~‫
א‬qˆQ5Dh‫د‬H‫‘نא‬gO4‫א‬qUKQ$‫א‬P3
.ً MQ‫ א‬Textpad ‫אل‬nDSWOND1!bI4‫א‬qY‫'א‬.
68
Notepad++ ‫اﺳﺘﺨﺪام‬
.1.3
‫אل‬bIK^3 Textpad K!'9}Ht‫*א‬jVœ‫™א‬Q،K3P:‫א‬9‘،K‹Ÿˆ1
.‫س'د‬H'v3:‫א‬nN}H$V\‫א‬v'O3:‫א‬Wos‫א‬،auto complete
:NS$Q\‫!א‬3NP>
‫رابط‬
http://notepad-plus.sourceforge.net/uk/about.php
: Open Source :‫א‬lQ'1K‫א‬303NSl${:O234‫א‬
‫رابط‬
http://sourceforge.net/projects/notepad-plus/
SharpDevelop
.1.4
:ً MQ‫א‬FVg%‫'دوא‬%'FQ، C# ‫אل‬3$œ:%'3
69
:‫א‬a‫אא‬4D:Dfz$‫א‬NP>...h‫وאدوא‬g(\‫א‬U'Q‫`'אل'د‬OX.9‫'א‬S‫و‬
‫رابط‬
http://www.icsharpcode.net/OpenSource/SD/
Visual Studio 2008 ‫اﻟﺒﺪاﻳﺔ ﻣﻊ‬
.2
$<،:D'N Studio Viusal ‫'אل‬S VB.net ‫ אوאل‬C# ‫אل‬P€!'‫و‬PQ353$F\‫ א‬IDE ‫אل‬
Visual K^3'g!N3q:%'3‫'ن‬PQW‫ وא‬Express3‫א‬، —'S‫ و‬Proffessional ‫'ع‬N‫א‬
.C# 2008 Express
Web Site ‫و‬C‫وع‬T3zT‫א‬h‫א‬HI${3‫ول‬C$`3$+\‫א‬q‫א‬G‫و‬، i3‫ول‬234‫א‬KqT$
:ً ^3 Project ZI‫ א‬New Fj.53،5Q‫'د‬%'\‫א‬nDKQ$!s‫א‬$Q$%
70
$‫ وא‬Class nD ً j$3 ' ‫'د‬P‫ א‬P ,, S‫ و‬Console Application S ‫ א'אع‬a‫א‬
O†K‫א‬3Uk‫ق‬1N‫'אع‬9‫א‬..a7!...:ZI‫א‬W‫وعא‬T\‫'אא‬S name space ‫ وאل‬Main
. .net 2008 JK3g!: I5301‫א'אعو‬a‫א‬: Console ‫م‬$+N،XP‫א‬53
€،O+\‫وعא‬T\‫א‬h'P3YK7N‫א‬NP>، Solution Explorer ‫אل‬${,T‫א‬Y>nD
aqM‫ ل א‬I 53 i$Q$% h'P3 !s‫ א‬01 ، „‘ !M\‫ א‬h'P\‫ א‬${ Refernces GQ'
. Add aqs‫وא‬5>‫א\وسא‬H ReferncesnD
‫אل‬0B‫ض‬DQr Class‫ض‬DHI‫א‬01،‫אض‬X'‫א‬YKQ$‫א‬NP>GQ'‫אא‬WSKO‫א‬
: g!*jVœ‫قوא‬1‫وא‬D‫و‬T3Ui‫'د‬%'\‫א‬Classes
71
‫وع‬T\‫*א‬jVI$`Y3:DaqM€F.'،‫وع‬T\‫*א‬jVI${ Properties GQ'€
.D‫و‬T\9‫*א‬jVœ‫א‬NP>
iH'V FgN h. ‫ א‬$Q$‫ و‬Classes hJO‫ א‬H5P> Class Designer ً MQ‫ א‬.net ‫ אل‬Q
.i,3‫وع‬T\‫א‬nDFgNa‫אوא‬03i,3g71Q‹53‫و‬j3
‫ﺑﺮﻧﺎﻣﺠﻚ اﻷول‬
.1.2
:‫'دא‬P‫א‬0s Main lF\‫ א‬function ‫אل‬U،Na23‫אول‬X`N
C#
Console.Write("Hello World");
Console.ReadKey();
‫ﻛﻮد‬
VB
Console.Write("Hello World")
Console.ReadKey()
‫ﻛﻮد‬
.Visual Studio 2008U‫אول‬h]TC$.‫א‬WPS‫'ن‬P...a7!
.234‫א‬2X%‫و‬F5H‫ز‬nDaqM‫א‬X%
72
‫‪73‬‬
‫اﻟﺒﺎب‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‪6‬‬
74
75
Console‫*אل‬jVI™nDQ'nDfN،€h‫و‬$‫א‬hq9‫א‬h'P\‫_א‬DUHr9‫א‬K.
.N‫و‬H‫د‬Uً79g3$+Nt‫وא‬
Console ‫ﺧﺼﺎﺋﺺ‬
.1
. ‫ع‬%Z‫ وא‬SzD$‫ دوאل وא‬KFD‫ و‬,T‫ א‬nD P‫ אšن א‬01 ، ‫وس‬H$‫ א‬53 \‫ א‬lWS n
gDKFt‫ א‬Console J9‫א‬bN‫א‬nDfi
V.‫א‬HWI]N\‫א‬lWS$ND،gD‫و‬
.ً :S‫و‬،‫אج‬I9‫لوא‬I‫د‬9‫دوאلא‬S Console JO‫א‬gQ't‫وאلא‬$‫א‬S‫א‬
C#
Console.Write(string);
// *P .
‫ﻛﻮد‬
Console.WriteLine(string)
// zg–‫א‬$$Q$%1‫ل‬79‫א‬aqs03*P .
string x=Console.ReadLine();
// Z‫א‬aqs03iz‫א‬7‫א‬53zg9‫א‬Q‫مو‬$+\‫א‬53h I$3iz‫א‬7
int x=Console.ReadKey();
// Z‘aqs03iz‫א‬7‫א‬FDzg‫א‬Q‫و‬a7!$‫وא‬fiz‫א‬.
ConsoleKeyInfo r= Console.ReadKey();
// Q‫א‬Wً ^3g‫א‬H‫ز‬K^3z,‫لא‬I‫אد‬5P>،:I‫‘د‬$iz‫א‬7‫א‬53zg9‫وא‬a7!$‫وא‬fiz‫א‬.
‫ص‬I
q3U2N‫א‬5Q§
‫ﻣﻼﺣﻈﺔ‬
. ‫ فقط ازل الـ ; من آخر الجملة‬VB.net ‫لو كنت مبرمج‬
‫ 'ن‬BackgroundColor ‫* و‬N‫ 'ن א‬ForeGroundColor K^3 ‫ א'אن‬hF bI AIC ‫دوאل‬
:‫א‬KPTConsoleColorJO‫ˆא‬Q5D‫א'ن‬Y01،Oœ‫א‬
C#
Console.ForegroundColor = ConsoleColor.Yellow;
‫ﻛﻮد‬
76
.iW!N‫א‬g(3$Q$Rg! I‫ و‬Title ‫ و‬WindowWidth K^3AIC*jVI¤NS
:‫*א‬N‫א‬D1‫م‬7‫א‬$QN‫ضא‬ZON،D1‫א‬0s‫'א‬3$‫'د‬
Age
q\‫א‬:F‫ א‬name – q\‫א‬:–‫א‬
:‫'دא‬P‫ˆא‬Q5DW‫م‬7‫א‬NNP>
C#
Console.Write("First Name: " + name + " - Age: " + age);
‫ﻛﻮد‬
:‫א‬7Q1،ً MQ‫א‬KM!‫א‬AIC7Q¤NS
C#
Console.Write("First Name: {0} - Age: {1}" ,name,age);
‫ﻛﻮد‬
KPT exponential K e ‫مو‬.H d ‫'ز‬3H‫אم‬$+*N Format KFDNP>،^‫א‬7Q1‫א‬1‫'א‬
:ً ^3‫א‬
C#
Console.WriteLine("E format: {0:E}", 99999);
‫ﻛﻮد‬
‫ﻣﻼﺣﻈﺔ‬
. ‫ فلن تحتاج سوى الزالة الـ ; من آخر الجملة‬VB.net ‫مجدداً لو كنت مبرمج‬
‫ﺗﻌﺮﻳﻒ اﻟﻤﺘﻐﻴﺮات‬
.2
:‫א‬7Q1h‫
א‬q\‫א‬oQNNP>7‫وسא‬H$‫א‬U‫ذ‬F
C#
int x;
string name;
‫ﻛﻮد‬
VB
Dim x As Integer
Dim name As String
‫ﻛﻮد‬
77
‫؟‬gFg3SF!،h‫
א‬q\‫א‬oQ53
^U new FP‫'دא‬%‫و‬ª $]NP‫و‬،:! I‫و‬
U i‫'د‬%'\‫ א‬s‫א‬Z!9‫ א‬gH'b „‘ S$ 3 'S‫ و‬new ‫אم‬$+ gOQ 5P> 1‫'אع א‬9‫™ א‬
‫'אع‬C.W‫ و‬Ob„‘‫م‬.H9‫ وא‬false „‘ bool 71N\‫'אعא‬9‫א‬KQ'Q،g‫אœص‬±TN\‫א‬
.h‫
א‬q\‫א‬
arraylists ‫ و‬objects ‫אل‬K^3 new ‫אم‬$+9‘g3‫א‬$+‫א‬NP>9h‫א‬53AI‫א'אعא‬¤NS5P
.:NU:DfNŸ:! I‫و‬
: C# U‫'אع‬9‫א‬7'S‫א‬WS
ProCSharp 2008 and .net 2008 platform X53iH'V‫א‬
78
.:! I‫ و‬GetHashCode ‫ و‬EqualsK^39‫א‬:.iH‫و‬Me Object 537T\‫'אعא‬9‫א‬0B
MinValue ‫ و‬MaxValue K^39‫*א‬jVœ‫א‬KFT! long ‫ و‬int K^3F.‫ 'אعא‬9‫قא‬1‫א‬3C
.h I$\‫א‬$Q$R IsLetter ‫ و‬IsDigit K^3*jVInD char ‫'אل‬dF!...
‫أﻧﻮاع اﻟﻤﺘﻐﻴﺮات‬
.2.1
$Q$Q‫و‬،ً ^3 int , string‫'ع‬N‫א‬Gh‫
א‬q\‫א‬oQNNP> Class ‫אل‬KI‫ دא‬234‫א‬53z%‫א‬U
.oQ‫א‬:!‫'د‬%'\‫نא‬P\‫א‬4D‫'ل‬b'‫א‬A$3
‫ ل‬I 9‘ :‘ ‫'ل‬b'‫ א‬$C 01Q 5
q\‫א א‬WS ، ‫ دא‬KI‫א‬$gOQ ”
q3 ‫ض‬ZON 17N‫ א‬lWS s'
) ‫א‬$‫ج א‬HI q3 oQ NF. ' 3C ، QH‫א‬P 7 KI‫و دא‬C ‫ط‬, KI‫ دא‬:OQ ” ' 3‫@ א‬O‫ و‬، ‫א‬$‫א‬
.MembernFQL‫א‬lWSU،i,3 :‘‫'ل‬b'‫دאא‬95PF!(i,3ClassJO‫א‬KI‫دא‬
53:P\
q\‫
אא‬TQ:! I‫ و‬Long ‫ و‬int K^3a‫'א‬S‫'عאولو‬N‫א‬،h‫
א‬q\‫א‬53‫ن‬D'NQ$
‫ن‬P3„‘iH,9‫א‬:N301‫ن‬P3„‘
q\‫
א‬T! Object of Class ‫ و‬Array K^3G\‫א‬3Ci‫א‬W‫א‬
.3‫د‬.‫وس‬H‫د‬UKVO‫'ع‬s'\‫אא‬WSnDfN،i‫א‬W‫א‬U:F.
Constant ‫اﻟﺜﻮاﺑﺖ‬
.2.2
5P> ، €^‫ אو א‬Constant fQ ‫א‬W ، ‫ ًא‬$‫ א‬:F. q 5P> 9 h‫ א‬53 ‫' 'ع‬S Constant ~‫א‬
:‫א‬KPT:
C#
public const int myNumber = 100;
‫ﻛﻮد‬
VB
Public Const myNumber As Integer = 100
‫ﻛﻮد‬
79
U T‫ א‬:3$+ Y3 .H K^3 ، PI=3.14K^3 h9‫ ‹ ™ א\د‬7 €‫ א^'א‬lWS ‫אم‬$+‫ א‬Q
.€.‫אو‬Ul
qR‫نא‬FM qF:OQ53ً9$€^:OQKMOQL‫א‬lWSU.‡‫א‬...hL‫א‬
...a7!:OQ(LF7‫א‬lz1D‫وא‬i$‫وא‬i3€^‫ א‬oQQ
Read Only Field ‫اﻟﻘﻴﻢ ﻟﻠﻘﺮاءة ﻓﻘﻂ‬
.2.3
:‫א‬KPT:OQQ
C#
public readonly double PI=3.14;
‫ﻛﻮد‬
VB
Public ReadOnly PI As Double = 3.14 ‫ﻛﻮد‬
‫ط‬,‫دون‬i$‫وא‬i3lzT‫א‬$F. lz1D‫א‬P3‫א‬Uo•:‫אא‬$D3،ً3e Constant ‫אل‬K^3KFQ
: ً ^3‫ א‬KPToQ‫(א‬L@OUF7‫א‬lz1D‫א‬
C#
class MyMathClass
{
public readonly double PI;
public MyMathClass ()
{
PI = 3.14;
}
‫ﻛﻮد‬
VB
Class MyMathClass
Public ReadOnly PI As Double
Public Sub New()
PI = 3.14
End Sub
End Class
‫ﻛﻮد‬
80
String ‫اﻟﻤﺘﻐﻴﺮات اﻟﻨﺼﻴﺔ‬
.3
String ‫'ع‬NˆQ3K‫'ل‬jŽ‫א‬lWSUE$RN
String ‫اﻟﺨﺼﺎﺋﺺ واﻟﺪوال اﻻﺳﺎﺳﻴﺔ ﻟﻞ‬
.3.1
‫אم‬$+–‫א‬
bœ‫وא‬C‫א‬$‫א‬
*N‫د'لא‬$
Length
YVYH7F
Compare
*N‫א‬5Fsf‫*אو‬5DR
Contains
Y3*‫אو‬frgNQ‫אو‬C$Q*N‫אذאنא‬F!!\
EndsWith
StartsWith
‫אو‬Q‫א‬$‫א‬53z‫'א‬،*N‫א‬5FsY3*Q‫א‬$‫אو‬f‫'د‬%‫نو‬P3!\
IndexOf
QgN‫א‬53
LastIndexOf
*N‫א‬53Y3z%fW
Remove
String‫אل‬KI‫אج*دא‬H‫אد‬
Insert
*N‫א‬53z%‫אل‬$‫א‬
Replace
−)3 DK03*N‫א‬7ً ^3،!'OV3„‘Y3z,G*N‫א‬7
Split
i$Q$%!'OV3„‘(
small‫ و‬capital Yf9‫א‬KQ'R
ToUpper
ToLower
81
: ‫ﺗﻘﺴﻴﻢ اﻟﻨﺼﻮص‬
.3.2
zN*7s'Q‫א\^لא‬،!'OV3UbND„‘*N‫א‬hQ')7Split‫א‬$‫אمא‬$+‫א‬NP>
::1‫و‬U–h3 DnD
C#
string[] newarray = g.Split("-");
‫ﻛﻮد‬
VB
Dim newarray As String() = g.Split("-")
‫ﻛﻮد‬
:‫ دﻣﺞ اﻟﻨﺼﻮص‬.3.3
:‫א‬KPT Concat‫א‬$‫אمא‬$+‫אو‬،+‫אم‬$+S‫'ص‬VN‫א‬23$a9‫א‬7Q1‫א‬
C#
string s3 = String.Concat(s1, s2);
‫ﻛﻮد‬
VB
Dim s3 As String = [String].Concat(s1, s2)
‫ﻛﻮد‬
‫ﻣﻘﺎرﻧﺔ اﻟﻨﺼﻮص‬
.3.4
‫א‬$‫אمא‬$+‫א‬KMO\‫א‬53:‫א‬9‘، VB.net U=‫و‬C C# U‫'ص‬VN‫א‬H7\==K3\‫אمא‬$+‫א‬5P>
:‫א‬KPTEquals
C#
Console.WriteLine(s1.Equals(s2));
‫ﻛﻮد‬
82
VB
Console.WriteLine(s1.Equals(s2))
‫ﻛﻮد‬
‫ – ﺳﻲ ﺷﺎرب ﻓﻘﻂ‬Escape Characters
.3.5
Tab KF /t ‫و‬$Q$%1 /n K^3bœ‫א‬f‫و‬L‫)`'زאً™א‬/f${،‫א‬jDhqKU
:ً ^3‫א‬KPT،l
—‫و‬
C#
Console.Write("My Name:/nAhmed Gamal");
‫ﻛﻮد‬
Verbatim fQ 3 ‫אم‬$+‫' א‬S‫ و‬IŠ K ¤NS ، // GP ‫ אن‬$ ! / GP ‫ אن‬h‫د‬H‫א ‘ذא א‬W
KPT Escape Characters ‫ אل‬53 ˆ7‫ون א‬$ ‫د‬D * L‫ א‬lWS U NP> Strings
:ً ^3‫א‬
C#
Console.WriteLine(@"C:\MyApp\bin\Debug");
String ‫اﻟﺘﺤﻮﻳﻞ ﻣﻦ وإﻟﻰ‬
‫ﻛﻮد‬
.3.6
:ً ^3‫א‬KPT،l&N3„‘*N‫'لא‬t‫ وא‬Parse ‫א‬$‫א‬nD9‫'אعא‬9‫(א‬3'
C#
int x = int.Parse("1");
bool v = bool.Parse("True");
‫ﻛﻮد‬
VB
Dim x As Integer = Integer.Parse("1")
Dim v As Boolean = Boolean.Parse("True")
‫ﻛﻮد‬
83
ً ^3‫א‬KPT*„‘gQ'R ToString ‫א‬$‫א‬nDًMQ‫'א‬F
C#
string x = m.ToString();
‫ﻛﻮد‬
VB
Dim x As String = m.ToString()
‫ﻛﻮد‬
StringBuillder
.3.7
KPT VB.net U & K3\‫وא‬C C# U+K3\‫אمא‬$+9N3‫^
ون‬P‫`]א‬Q،‫'ص‬VN‫א‬23$‫'م‬73$ND
:‫و‬ZP–‫א‬$Q4‫אدא‬$3‫!א‬s‫^لא‬3−‫א‬
C#
// C#:
Label1.Text = Text1.Text + "@hotmail.com";
‫ﻛﻮد‬
VB
'VB.net:
Label1.Text = Text1.Text + "@hotmail.com"
‫ﻛﻮد‬
‫ ل‬U ، StringBuilderJO‫אم א‬$+ ‫'ص‬VN‫ א‬23$ AIC 7Q N €3$. Visual Studio ‫ن‬C 9‘
:‫א‬KPT‫'ص‬VN‫א‬23$g3‫א‬$+‫א‬5P>، System.Text.StringBuilder zƒ‫א‬
C#
//C#:
System.Text.StringBuilder mail = New System.Text.StringBuilder(Text1.Text);
mail.Append("@hotmail.com");
‫ﻛﻮد‬
VB
'VB.net:
Dim mail As New System.Text.StringBuilder(Text1.Text)
mail.Append("@hotmail.com")
‫ﻛﻮد‬
84
& ‫و‬C+h 3\‫אمא‬$+‫א‬3‫א‬،lzT‫(א‬LWN3'SFK(Q stringbuilder ‫אن‬U5FPQYN‹9‫א‬Y‫ق‬HO‫א‬
.23‫د‬FDK03 String ‫אل‬53$Q$% Object KF‫'م‬7Q'g!
.Net Gotachas X53i,3H7\‫א‬H'VN‫و‬،‫'ص‬VN‫א‬53‫د‬$D23$‫'م‬7 Loop ‫^ل‬3‫ض‬ZON‫وאšن‬
‫م‬.‫ و‬، 23‫ د‬FD 1000000 n‫ و‬23‫ د‬hFD 10 53 z‫א‬$‫ א‬23‫ د‬hFD ‫د‬$ HI‫ א‬KF ‫م‬. ،
^WON‫א‬53‫ذز‬03،Q$7‫א‬23$‫א‬h 33‫אم‬$+‫ אوא‬StringBuilder ‫אم‬$+‫א‬Yz‫אدא‬H7}
.gN3KP
...ً Q77.‫د‬59.4c‹3562.933‫אن‬nN9
‫'ص؟؟؟‬VN‫א‬23$+‫م & אو‬$+€‫ز‬3KS...‫وאšن‬
hFD‫ و‬RemovefW‫ و‬Insert ‫אج‬H‫ وאد‬Replace ‫אل‬$‫ א‬hFD ً MQ‫ א‬stringbuilder JO‫'! א‬
a‫אאא‬WS‫ ل‬I53‫'مא‬3'D$3H7Fi
^:%‫و‬CnD‫ ع‬9‫א‬NP>،i
^AIC‫'ص‬V
: Code Project 53
‫رابط‬
http://www.codeproject.com/KB/cs/StringBuilder_vs_String.aspx
85
‫اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﺘﺎرﻳﺦ واﻟﻮﻗﺖ‬
.4
:Y3¢QH!s9ً ^F!، DateTime P\‫א‬U€.'‫وא‬¢QHˆQ30B${
C#
DateTime dt = new DateTime(2004, 10, 17);
‫ﻛﻮد‬
VB
Dim dt as DateTime = New DateTime(2004, 10, 17)
‫ﻛﻮد‬
:L‫א‬¢QH‫א‬D1
C#
Console.WriteLine(DateTime.Now);
‫ﻛﻮد‬
VB
Console.WriteLine(DateTime.Now)
‫ﻛﻮد‬
TimeSpan ‫אم‬$+ًMQC€.'‫א‬03K3‫א‬5P>
C#
TimeSpan ts = new TimeSpan(4, 30, 0);
‫ﻛﻮد‬
VB
Dim ts as TimeSpan = New TimeSpan(4, 30, 0)
‫ﻛﻮد‬
:‫א‬KPT Substract ‫ و‬Add ‫אول‬$‫אمא‬$+v1‫!وא‬s9‫א‬
C#
Console.WriteLine(ts.Subtract(new TimeSpan(0, 15, 0)));
‫ﻛﻮد‬
VB
01.Console.WriteLine(ts.Subtract(New TimeSpan(0, 15, 0)))
‫ﻛﻮد‬
‫و‬C
86
C#
dt = dt.AddMonths(2);
‫ﻛﻮد‬
VB
dt = dt.AddMonths(2)
‫ﻛﻮد‬
:‫اﻟﺘﺤﻮﻳﻞ ﺑﻴﻦ اﻟﻤﺘﻐﻴﺮات اﻟﻤﺨﺘﻠﻔﺔ‬
.5
:YjHYD'„‘h‫
א‬q\‫א‬Yh Q'R‫א‬7N،Q‫א‬$
Widening Conversions
•
Narrowing Conversions
•
Widening Conversions
.5.1
nF‫و‬،h‫א‬53‫א'ع‬iHIg!5P>9t‫א‬h Q'R‫א‬h Q'R‫א‬53‫'ع‬N‫אא‬Wg$V7Q
:‫א\^لא‬U Integer „‘ Short53KQ'R‫^لذא‬3،upward cast
C#
Short x=5;
power(x);
‫ﻛﻮد‬
VB
Dim x As Short = 5
power(x)
‫ﻛﻮد‬
power ‫א‬$‫א‬U‫و‬
C#
int power(int number)
{
return number^2;
}
‫ﻛﻮد‬
87
VB
Private Function power(ByVal number As Integer) As Integer
Return number Xor 2
End Function
‫ﻛﻮد‬
L‫א‬lWSU، Short ‫'ع‬53hkNH‫א‬F! Int ‫'ع‬53hK7‫א‬$‫אنא‬$`€(9'
07Q Short KA$3‫و!¦نא‬، Short ‫אل‬A$3534‫ א‬Integer ‫אل‬A$3‫ن‬PT3¤NS‫'ن‬P5
.$]KP Integer‫אل‬5Fs
Narrowing Conversions
.5.2
Short ‫'ع‬532N‫ وא‬Integer ‫'ع‬53‫
אن‬q\‫^ ً'نא‬3،qb‫‘„א‬49‫א‬53KQ'R‫א‬،P‫א‬L‫א‬
'5P‫و‬، Short KnV.‫א‬$L‫א‬53qb‫ א‬Integer YF.‫'عא‬F‫'ن‬RRbiH'V39‫א‬KF،
.PT32N‫ !¦نذ‬Short ‫אل‬A$3‫ود‬$‫{وز‬gD'F‫אن‬NsZ!‫א‬
:‫]א‬1œ‫א‬H1Q‫'دو‬P‫אא‬WSK^353i,3Q3'P‫א‬N>،G‫אא‬Wk
Cannot implicitly convert type 'int' to 'short'.
]`L‫א‬lWSU،h‫ع™א‬s‫ذ‬5D2'n17N‫א‬lWS5DًF—HKQ'R‫א‬UN—H'5P
Cast ~nFQ\
Cast ‫ﻋﻤﻠﻴﺎت ال‬
.5.3
،KQ'R‫א‬hFDKUg3‫א‬$+‫ א‬5P>K،a7!qb4‫א‬53KQ'R‫א‬nD cast ‫אل‬hFDˆ1N9
:‫א‬KPT Short „‘ IntegerKQ'R'Sk‫אم‬$+‫א‬a‫א‬
C#
int var=10;
short var2 = (short)var;
‫ﻛﻮد‬
88
VB
Dim var As Integer = 10
Dim var2 As Short = CShort(var)
‫ﻛﻮد‬
:‫א\^لא‬NsZ!‫ذא'א‬35P،10g‫א‬$`N var2 `D1NF.'،ˆ‫א\^لא‬U
C#
int var=100000;
short var2 = (short)var;
Console.WriteLine(var2);
Console.ReadKey();
‫ﻛﻮد‬
VB
Dim var As Integer = 100000
Dim var2 As Short = CShort(var)
Console.WriteLine(var2)
Console.ReadKey()
‫ﻛﻮد‬
، 31072−S`N‫'نא‬P234F73iH'V5P‫و‬،KFNg.'5P>5`N‫א‬
‫ אو‬، ˆ‫ א‬.‫ א‬5D i‫د‬Q‫ ز‬K 03 .H ‫ص‬7‫ ‹ א‬53‫ و‬32768 53 z‫א‬$‫ א‬h‫א‬H,9‫@ א‬P Q3'P‫'م א‬7
.32767 'S‫'ع و‬N nV.9‫ א‬A$\‫ אو א‬nV.9‫ א‬$L‫ א‬53 2N‫ א‬.‫ א‬v1 ‫'م‬7Q 'g! HVI
KVOgDfNt‫وא‬Try Catsh ‫אم‬$+‫ًא‬Fj‫دא‬KMO\‫א‬53:¦!،h Q'R‫א‬53‫'ع‬N‫אא‬WS‫אم‬$+
.XP‫א‬53‫دم‬.z%U
Convert ‫اﻟﺘﺤﻮﻳﻞ ﺑﺎﺳﺘﺨﺪام‬
.5.4
:ً ^3‫א‬KPT Convert JO‫אمא‬$+h‫א‬53‫אא'אع‬YKQ'R‫א‬5P>
C#
myByte = Convert.ToByte(myInt);
‫ﻛﻮد‬
VB
myByte = Convert.ToByte(myInt)
‫ﻛﻮد‬
89
.6
‫ أﺳﺎﺳﻴﺎت اﻟﺸﺮوط‬.6.1
.net ‫اﻟﺠﻤﻞ اﻟﺸﺮﻃﻴﺔ ﻓﻲ‬
:‫א‬KPTg7Q‫و‬، if else ‫م‬$+t‫א‬ST‫א‬KFŽ‫א‬a‫א‬
C#
if (x==5)
Console.WriteLine("five");
else
Console.WriteLine("notFive");
‫ﻛﻮد‬
VB
If x = 5 Then
Console.WriteLine("five")
Else
Console.WriteLine("notFive") End If
‫ﻛﻮد‬
‫אم‬$+‫ط‬,53^‫א‬23‫د‬5P>،T‫א‬KFŽ‫א‬U > ‫==و!=و < و‬hH7\‫אم!א'אع א‬$+‫א‬Q
:‫א‬KPTelse if
C#
if (x > 90)
{
Console.WriteLine("‫;)"Ÿز‬
‫ﻛﻮد‬
}
else if (x >=50)
{
Console.WriteLine("%");
}
else
{
Console.WriteLine("G‫א‬H");
}
90
VB
If x > 90 Then Console.WriteLine("‫)"Ÿز‬
‫ﻛﻮد‬
ElseIf x >= 50 Then Console.WriteLine("%")
Else
Console.WriteLine("G‫א‬H")
End If
‫א‬hqQ$7‫(مא‬N‫א‬.^‫طא‬T‫א‬WONQ9‘‫( و‬True) 2N‫'ن א‬U„‫אو‬FŽ‫ˆא‬1Q
:‫א‬FŽ‫א‬K^3ًMQ‫א‬1‫'€و‬RRbgM7 €t‫وא‬
‫ﻣﻼﺣﻈﺔ‬
:‫א‬KPTN‫و‬,™P‫'م‬7‫ن‬CC‫אل‬0t‫א‬hq‫א‬h jD03‫'د‬$.N
C#
if (string.lenght)
‫ﻛﻮد‬
...$XH, ‫א‬03ًLb$Q_‫(م‬N‫אא‬WSTrue=‫ط‬T‫ˆא‬7d‫ن‬CF.:‫'ن‬5P>
‫دﻣﺞ اﻟﺸﺮوط‬
.6.2
g' U ‫ط‬T‫ א‬WON Q r ‫وط‬T‫ א‬Y 23$ And ‫و‬C && ‫אم‬$+‫ א‬5P> ‫ط‬, 53 ^‫ א‬KF
‫'ن‬U`1!||‫א‬KPTXH,U:QW‫ وא‬Or K33‫אم‬$+‫ אوא‬True ً B
G@N9 (O)‫م‬$DUc!!‫א‬KPTGPQW‫ وא‬Not K3\‫א‬،ًRRbgN3 $‫אوא‬
:ً ^3‫א‬KPT‫وط‬T‫א‬KI‫א‬$9nh9L‫א‬lWSU‫'אس‬.9‫א‬
C#
if ((x < 90 || x>50) && (!name="ahmed"));
‫ﻛﻮد‬
VB
If (x < 90 Or x > 50) And (Not name = "ahmed") Then
End If
‫ﻛﻮد‬
91
AndAlso
.3.6
:‫א‬2N‫ولא‬$%k‫'ن‬PQ‫و‬،YT‫א‬HI‫א‬Q‫אن‬AndK3\‫א‬U‫و‬net.hU‫'د‬N
2N‫א‬
2KI$3
1KI$3
True
False
False
False
True
True
False
False
True
False
True
False
D‫دא‬C$%'Q9‫و‬،JI‫'ن‬Pi,3FŽ‫ !¦نא‬false‫אول‬f1‫'نא‬U:]ªR‫و—א‬
.AndK3\‫א‬:OQ93‫א‬WSo 5P‫و‬،‫ط‬T‫א‬53^‫א‬zŽ‫א‬53ˆ7R
.±I
‫'دא‬%‫و‬Ui,3False$Q'g!،o†‫'ع‬s'\!AndAlso035P
:‫'دא‬P‫ضא‬ZON،i$Q$,‫ذ؟‬53$O‫ذא‬3
C#
if (id > 0 & SearchForID(id)>0) {
// do something
}
‫ﻛﻮد‬
VB
If id > 0 And SearchForID(id)>0 Then
' do something
End If
‫ﻛﻮد‬
Ž\‫א‬Uً‫א‬$%$Q$,za2NQ3'S‫و‬R‫א‬3‫א‬WON!،OV‫א‬53qb‫א‬Id‫'نאل‬n‫و‬0.‫א'א‬U
:‫א‬KPTQ$7‫א‬7Q1gDGq‫א‬Q،:‘‫‰ج‬9
C#
if (id > 0) {
if (SearchForID(id) > 0) {
// do something
}
}
‫ﻛﻮد‬
92
VB
If id > 0
If SearchForID(id)>0 Then
' do something
End If
End If
‫ﻛﻮد‬
:AndAlso7Q1‫و‬
C#
if (id > 0 && SearchForID(id) > 0)
{
//do something
‫ﻛﻮد‬
}
VB
If id > 0 AndAlso SearchForID(id)>0 Then
'do something
End If
‫ﻛﻮد‬
OrAlso
.6.4
:‫א‬2jN‫ولא‬$%:W‫وא‬ORK3\‫א‬033‫א‬HPQ،And03‫ل‬L‫'א‬SF
2N‫א‬
2KI$3
1KI$3
True
True
True
False
True
True
False
False
True
False
True
False
D‫دא‬C$%'Q9‫و‬،RRb‫'ن‬Pi,3FŽ‫!¦نא‬True‫אول‬f1‫'نא‬U:¦ªR‫و—א‬
.OrK3\‫א‬:OQ93‫א‬WSo 5P‫و‬،‫ط‬T‫א‬53^‫א‬zŽ‫א‬53ˆ7R
‫س‬H$‫א‬U‫ل‬L‫'א‬SFh I$3i$D53ˆ7R‫א‬zNDOPQ9W‫ وא‬OrAlsoK3\‫אنא‬WSK%‫א‬53
.AndAlso03ًMQ‫אˆא‬
93
Switch Case ‫اﺳﺘﺨﺪام ال‬
.6.5
:‫א‬KPT Switch Case ‫אم‬$+‫א‬ST‫א‬KF`AI‫א‬7Q
C#
switch (x)
{
case 90:
Console.WriteLine("‫;)"Ÿز‬
‫ﻛﻮد‬
break;
case 50:
Console.WriteLine("%");
break;
}
VB
Select Case x
Case 90
Console.WriteLine("‫ )"Ÿز‬
‫ﻛﻮد‬
Case 50
Console.WriteLine("%")
End Select
‫وط‬T‫ א‬. HI‫ א‬UH‫א‬F9‫ א‬53Q3'P‫ א‬0N> ‫ אن ذ‬G‫ א‬، ‫ط‬T‫א‬I‫ א‬U break !s‫@ א‬N 9
oM !gN3‫ˆא‬703 n‫وط‬T‫א‬KnDlH‫و‬3UG—€N‫‘ذא‬3‫א‬،‫ط‬,‫אول‬nD^Q3$ND
.M\‫א‬lWk‫ض‬5‫`'אل‬O‫א‬U،break
94
:‫اﻟﺤﻠﻘﺎت اﻟﺘﻜﺮارﻳﺔ‬
.7
:`DnD‫س‬H$‫אא‬WSUH‫א‬P‫ق א‬vTN،h‫א‬3i$D3‫אوא‬1H‫א‬PQH‫א‬P‫א‬h7L‫مא‬$+
For - Next Loop
.7.1
:‫'دא‬P‫א‬gD‫^ل‬3a‫א‬،g!i'1œ‫א‬H‫א‬$73‫و‬QgN‫وא‬Q‫א‬$‫א‬17$Q$ QH‫א‬P7
C#
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
}
‫ﻛﻮد‬
VB
For i As Integer = 0 To 9
‫ﻛﻮد‬
Console.WriteLine(i)
Next
- :ً ^3%‫مאو‬.H9‫א‬D1 - ‫א‬KPTً ^32=O7‫א‬H‫א‬$73KFD5P>
C#
for (int i = 0; i < 10; i+=2)
{
Console.WriteLine(i);
}
‫ﻛﻮد‬
VB
For i As Integer = 0 To 9 Step 2
Console.WriteLine(i)
Next
‫ﻛﻮد‬
95
While Loop
.7.2
:10.H„‘‫אد‬$‫'لא‬b‫و‬nً ^3‫ض‬ZON،Y3 ‫ط‬,ˆ7nKF‫א‬UFH‫א‬P7
C#
int x = 0;
while (x < 10)
{
Console.WriteLine(x);
X++;
}
‫ﻛﻮد‬
VB
Dim x As Integer = 0
While x < 10
‫ﻛﻮد‬
Console.WriteLine(x)
X+=1
End While
0M‫و‬Q‫א‬$‫א‬U Do oMf'L‫ א‬lWSU، exit ‫ل‬I‫ אد‬nh‫ل‬I‫אد‬،F.H
—AI‫א‬
.QgN‫א‬UWhile
C#
string inp;
do
{
inp = Console.ReadLine();
Console.WriteLine(inp);
}
while(inp!="exit");
‫ﻛﻮد‬
VB
Dim inp As String
Do
inp = Console.ReadLine()
Console.WriteLine(inp)
Loop While inp <> "exit"
‫ﻛﻮد‬
96
For Each Loop
.7.3
:ً ^3N3!'OV3bNDKnD‫אن‬H‫و‬$ً ^3 ،Y3z,(K)nD‫אن‬H‫و‬$
C#
int[] arr = { 10, 20, 30, 40 };
foreach (int i in arr)
Console.WriteLine(i);
‫ﻛﻮد‬
VB
Dim arr As Integer() = {10, 20, 30, 40}
For Each i As Integer In arr
Console.WriteLine(i)
‫ﻛﻮد‬
Next
‫‪97‬‬
‫اﻟﺒﺎب‬
‫‬
‫‬
‫‬
‫‪7‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻻﺳﺎﺳﻴﺔ – اﻟﺠﺰء‬
‫اﻟﺜﺎﻧﻲ‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
98
99
‫ﻟﻨﻔﻬﻢ ﺑﺮﻧﺎﻣﺠﻨﺎ اﻷول‬
.1
:‫א‬KPT‫ن‬W‫ وא‬Hello World B D1‫אول‬NN(9'
C#
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
Console.Write("Hello World");
Console.ReadKey();
}
}
}
‫ﻛﻮد‬
:‫א‬KPT‫ن‬P!‫!`'אل‬U3C
VB
Module Module1
Sub Main()
Console.Write("Hello World")
Console.ReadKey()
End Sub
End Module
‫ﻛﻮد‬
. using ‫אم‬$+‫א'אد‬Pg3$+N t‫א‬hP\‫'א
אدא‬SC#Ul$`N3‫אول‬
Class J! 'S Module ‫ אل‬، i,3 :I‫ א'אد دא‬P €F. Module oQ ! ‫`'אل‬O‫ א‬U 3C
‫'ع‬53D‫و‬T3‫'ن‬U'Q‫`'אل'د‬O‫א‬S]TNQ Shared-StaticSgJ!0B‫ن‬C‫א‬$D3Q‫د‬D
.VB
K : 0s' W‫ א‬9‫' א‬S‫ و‬N4 ‫ אœص‬name space ‫ אل‬oQ 'S C# ‫ 'د‬U ^‫ א‬zŽ‫א‬
Nj4¨‫د‬3‫א‬UNFF ... MainNQ$9‫ א‬Class ‫ ‹אل‬53‫و‬،234‫א‬h'P3
100
Main nF\‫ א‬Class ‫אل‬Uj‫אא‬$‫א‬، Classes ‫אل‬53^‫אوא‬$‫وא‬53‫'ن‬PQ23 C‫!¦ن‬:%'‫א‬
.234‫א‬Uz,‫אول‬SWONQt‫ وא‬main ‫א‬$‫א‬S
!'OV3:qT03K7Q234‫אאنא‬WSnN3، args ‫
€א‬3‫א‬53D'F Main ‫א‬$‫א‬K7
Command nFQ3'S‫و‬،k I53234‫‘„א‬$Q3K‫ل‬H‫א‬5P> ، args[n] „‘ args[0] 53
.Line Parameters
SQe5P>t‫א‬h‫
א‬q\‫א‬53D'FS Command Line Args ‫אل‬،vT‫א‬UH35D$9P
:‫א‬39‫א‬PNF.'ً ^3،‫ط‬7N‫™א‬UPR :qT€.‫و‬234
‫ﻛﻮد‬
Explorer http://www.vb4arab.com
KPT:RO‫'م‬7Q€Z‫א‬0.'3‫‘ذא ن‬،:HF\‫* א‬N‫א‬iz‫א‬7‫'م‬7Q، Expolorer 23!Q3‫אول‬
U234‫@א‬Og‫א‬03h‫א‬$¡‫א‬OV3O‫'م‬7! C:/ً ^3 H3‫'ن‬3‫א‬،€Z9‫א‬OV\‫'د‬g\‫א‬
.QgN‫א‬
: For Loop ˆQ5D:iF\‫א‬h‫
א‬q\‫ א‬iz‫א‬.‫ ل‬I53nD‫{ذ‬01
C#
‫ﻛﻮد‬
for (int i = 0; i < args.Length; i++)
Console.WriteLine(args[i]);
VB
For i As Integer = 0 To args.Length - 1
Console.WriteLine(args(i))
Next
‫ﻛﻮد‬
UG—t‫א‬h‫א‬Z3H‫‹א‬53‫!و‬3‹53‫ و‬H3P.، Run „‘XSW.‫אšن‬
: RunU‫א‬39‫ز €א‬g%U،SQe
‫ﻛﻮد‬
C:\Users\Ahmed\Documents\Visual Studio
2008\Projects\ConsoleApplication4\ConsoleApplication4\bin\Debug\consoleapplication4.
exe ahmed ali
101
:‫א‬KPT‫ن‬g&W‫א‬2N‫א‬
‫א‬$DF!‫و‬،‫ق‬H‫ز‬9‫ م‬P‫א‬OI5Q'Qً ^3 0‫'د‬%‫و‬U‫
אولو‬q\‫א‬iz‫א‬7‫'م‬7N،0Qˆ1
:W‫'دאœص‬P‫'א‬S‫א‬WS،"‫ م‬P‫א‬OI5Q' Q‫ذ‬
C#
if (args[0] == "0")
{
Console.BackgroundColor = ConsoleColor.Blue;
Console.WriteLine("0 enterd");
}
else
{
Console.BackgroundColor = ConsoleColor.Red;
Console.WriteLine("Empty");
}
Console.ReadKey();
‫ﻛﻮد‬
VB
If args(0) = "0" Then
Console.BackgroundColor = ConsoleColor.Blue
‫ﻛﻮد‬
Console.WriteLine("0 enterd")
Else
Console.BackgroundColor = ConsoleColor.Red
Console.WriteLine("Empty")
End If
Console.ReadKey()
53 $] %r 5‰ ‫ ‘ذن‬، ]1I H g( .. h‫
א‬q3 ‫א‬QF 7 _ ' ‫ذא‬3 ، PT3 NS Ng%‫'א‬
53$]‫ !א‬¤NS‫‘ذאن‬،h‫
א‬q3‫'د‬%‫و‬53$]‫ˆא‬Q5DW‫'م‬7N،gz‫א‬.K.‫
س‬3H ‫'د‬%‫و‬
:^‫`]'نא‬YT‫א‬53‫א‬KI‫‘ذאא‬،Obg'
102
C#
if (args.Length > 0)
{
if (args[0] == "0")
{
Console.BackgroundColor = ConsoleColor.Blue;
Console.WriteLine("0 enterd");
}
}
else
{
Console.BackgroundColor = ConsoleColor.Red;
Console.WriteLine("Empty");
}
Console.ReadKey();
‫ﻛﻮد‬
VB
If args.Length > 0 Then
‫ﻛﻮد‬
If args(0) = "0" Then Console.BackgroundColor = ConsoleColor.Blue
Console.WriteLine("0 enterd")
End If
Else
Console.BackgroundColor = ConsoleColor.Red
Console.WriteLine("Empty")
End If
Console.ReadKey()
‫א‬KPT$‫وא‬1U$]‫א‬K< ‫אن‬N‫ذא'א‬3،IŠK¤NS
C#
if (args.Length >0 && args[0] == "0")
‫ﻛﻮد‬
VB
If args.Length > 0 AndAlso args(0) = "0" Then
‫ﻛﻮد‬
103
i,3‫•ج‬:¦!S$®_‫طא^ و‘ذא‬TK7NS$%‫‘ذאو‬،‫س‬Z3H‫'د‬%‫و‬53$] :‫א‬cQ‫א‬WS
...^‫طא‬T‫א‬iz‫א‬.‫دون‬
ˆW‫ א‬AndAlso‫אم‬$+9 1MK، VB.net U:715P>5 And K3\‫אنא‬WQ$Ž‫א‬
.7‫وس‬H‫د‬U:,
Function ‫اﻟﺪوال‬
.2
'S:‘‫‰ج‬3K،h‫
א‬q\‫א‬53‫د‬$D]‫وאل‬$‫א‬53‫د‬$D‫א‬zT‫א‬NNP>، Main ‫دא‬U$S,F
F‫دא‬FVN‫^ ًא‬3 ‫ض‬ZON،gN3‫ج‬Hœ‫א‬2N‫ًא‬MQ‫وא‬،‫א‬$KV‫אن‬k $Qt‫א‬h‫
א‬3H‫! א‬3
:‫א‬KPT‫א‬$‫'ن א‬P، int 2‫ و§ج‬int YF.HK7،0FŽ‫א‬
C#
static int sum(int number1, int number2)
{
int total = number1 + number2;
return total;
}
‫ﻛﻮد‬
‫ﻛﻮد‬
VB
Private Function sum(ByVal number1 As Integer, ByVal number2 As Integer) As
Integer
Dim total As Integer = number1 + number2
Return total
End Function
:ً ^3‫א‬KPT gjD$‫ א‬Main ‫ ل‬I53‫ول‬RN،‹53‫و‬
C#
int result = sum(5, 8);
Console.Write(result);
Console.ReadKey();
‫ﻛﻮد‬
VB
Dim result As Integer = sum(5, 8)
Console.Write(result)
Console.ReadKey()
‫ﻛﻮد‬
104
‫؟؟‬XH,‫א‬U Static g‫א‬nD sum oQ”‫\ذא‬
static ‫'ع‬53S Main ‫و}אندא‬، static ‫ لدא‬I53 Static —‫دא‬zD$‫א‬5P>9:‫א‬G‫א‬
™nDfN،ًMQ‫ א‬static S main‫ لאل‬I53gjD$‫ א‬QAI‫'نאدאא‬P‫אن‬53$ !
.ً79 !s9‫א‬KbO‫א‬
mehtods ‫اﻟﻄﺮق‬
.3
:‫א‬KPTH‫ض‬D‫ دא‬K^3،2$9t‫אא‬$‫א‬S‫ق‬1‫א‬
C#
void printmsg(string msg)
{
Console.WriteLine(msg);
}
‫ﻛﻮد‬
‫א‬KPT ‫'ن‬P VB.net 03ًMQ‫א‬F\‫'א‬S‫و‬، Sub 7Q1‫א‬oQQ‫ن‬،6 ‫`'אل‬O‫א‬U
VB
Private Sub printmsg(ByVal msg As String) Console.WriteLine(msg)
End Sub
‫ﻛﻮد‬
Out ‫اﻟﻮﻇﻴﻔﺔ‬
.4
‫دא‬53`i‫د‬D‫دא‬H‫ذא'א‬3، return ‫ ل‬I53`N‫عא‬%H‫'م‬7N¦! ˆ‫א\^لא‬UNFF
:‫א‬KPT Out ‫א‬$‫אمא‬$+‫ذ‬Q،void
C#
static void sum(int number1, int number2, out int total)
{
total = number1 + number2;
}
‫ﻛﻮد‬
105
‫ﻛﻮد‬
VB
Private Shared Sub sum(ByVal number1 As Integer, ByVal number2 As Integer, ByRef
total As Integer)
total = number1 + number2
End Sub
iH'V 3 KF P 5P‫ و‬، C# ‫'د אل‬P RRV‫ א‬BZ‫ א‬S ‫`'אل‬O bœ‫ א‬7‫א א‬$‫א‬
Ydn ‫'د‬P‫אא‬WS53z‫א‬$‫א‬gNDzNq9‫'م‬7N‫א‬W، Shared5Dcq‫ن‬C$9 MoudleURRb
.g$j!‫و‬SN3v,$D'3
:ً MQ‫`א‬N‫ضא‬:‘‫ ‰ج‬W‫
א‬q\‫א‬QeQ‫א‬$‫א‬zD$‫א‬$ND‫و‬
C#
int result;
sum(5, 8,out result);
Console.Write(result);
Console.ReadKey();
‫ﻛﻮد‬
VB
Dim result As Integer
sum(5, 8, result)
Console.Write(result)
Console.ReadKey()
‫ﻛﻮد‬
‫ ؟‬return ‫אم‬$+‫א‬53ً9$ 7Q1‫א‬lWS‫אم‬$+9c!$Q$.W‫א‬G‫'א‬S35P‫و‬
K 33‫!@א‬،F7‫وא‬0FŽ‫وא‬XM‫א‬2K^3`53^‫א‬i‫د‬D‫א‬h‫د‬H‫'א‬c‫א‬S، a9‫א‬%9‫א‬
. out ‫אم‬$+'Sa9‫א‬KL‫א‬،¤NSgz‫א‬.‫مو‬.H9!'OV3i‫د‬D‫א‬A'
106
byval ‫ واﻻرﺳﺎل ﺑﺎﻟﻘﻴﻤﺔ‬byref ‫اﻻرﺳﺎل ﺑﺎﻟﻤﺮﺟﻊ‬
.5
:‫א‬KPTv1‫א‬F‫ضא\^لאœص‬ZON
C#
int x=5;
int y=10;
sub(x,y);
‫ﻛﻮد‬
VB
Dim x As Integer = 5
Dim y As Integer = 10
sub(x, y)
‫ﻛﻮد‬
‫א‬$‫وא‬
C#
‫ﻛﻮد‬
static void sub(int number1, int number2)
{
number1 = number1 - number2;
return number1;
}
VB
Private Sub [sub](ByVal number1 As Integer, ByVal number2 As Integer)
number1 = number1 - number2
Return number1
End Sub
‫ﻛﻮد‬
، S%–‫א‬،SNH‫א‬t‫ א‬x F.53‫א‬WS
qKS5P‫و‬، number1F.
q NF.7‫אא‬$‫א‬U
. X F.€‫א و‬$‫ ‘„א‬x F.‫ل‬HL‫א‬lWSU‫'م‬7F7‫لא‬HfQ3‫א‬WS
،‫א‬$‫‘„א‬i‫א‬W‫א‬U X q\‫'אنא‬ND‫ل‬H‫א‬QL‫א‬lWSU،^‫ א‬L‫א‬S ByRef 0%\‫ل‬H9‫א‬
. x q\‫א‬nDiH‫و‬M‹p number1U
q‫אنא‬cQ 3‫א‬WS
:‫'دא‬P‫א‬GP ByRef 7Q1ˆ‫'دא‬P‫א‬P
107
C#
static void sub(ref int number1, ref int number2)
{
int result = number1 - number2;
return result;
}
‫ﻛﻮد‬
VB
Private Sub [sub](ByRef number1 As Integer, ByRef number2 As Integer) Dim result As Integer = number1 - number2 Return result
End Sub ‫ﻛﻮد‬
:3K3‫ !א‬Class K^3\‫ א‬h‫
א‬q\‫א‬3‫א‬،1‫א‬h‫
א‬q\‫א‬03a7!:715P>F7‫ل‬H9‫א‬
...ً s‫א‬Z!‫א‬ByRef
Arrays ‫اﻟﻤﺼﻔﻮﻓﺎت‬
.6
Arrays ‫ﻣﺎ ﻫﻲ اﻟﻤﺼﻔﻮﻓﺎت‬
.6.1
GPbND 5 k' ‫م‬.H9‫ א‬53 Array oQ ، ‫'ع‬N‫@ א‬O 53 h‫ א‬53 5D iHD S !'OV\‫א‬
:‫'دא‬P‫א‬
C#
int [] intarray = new int[5];
‫ﻛﻮد‬
VB
Dim intarray As Integer() = New Integer(4)
‫ﻛﻮد‬
:‫ א‬K^3‫'د‬GP!'OV\‫א‬bND$‫א‬iz‫א‬7،4n‫و‬OV‫א‬53h!'OV\‫א‬U.Z‫ א‬C$Q
C#
Console.WriteLine(intarray[3]);
‫ﻛﻮد‬
108
VB
Console.WriteLine(intarray(3))
‫ﻛﻮد‬
:‫א‬KPTH‫א‬P‫א‬h7‫אم‬$+‫א‬5P> bN‫א‬0Biz‫א‬7‫و‬
C#
for (int i=0;i<5;i++)
Console.WriteLine(intarray[i]);
‫ﻛﻮد‬
VB
For i As Integer = 0 To 4
Console.WriteLine(intarray(i))
Next
‫ﻛﻮد‬
:‫ﺗﻜﻮﻳﻦ اﻟﻤﺼﻔﻮﻓﺎت‬
.6.2
:ً ^3‫א‬KPT!'OV\‫‘„ א‬h‫لא‬I‫د‬9Kg9‫א‬7Q1‫א‬
C#
array[0]=15;
array[1]=20;
array[2]=13;
‫ﻛﻮد‬
VB
array(0) = 15
array(1) = 20
array(2) = 13
‫ﻛﻮد‬
:ً ^3‫א‬KPT!'OV\‫‘„א‬h‫لא‬I‫د‬9AIC7Q¤NS ‫אن‬9‘،ًMQ‫א‬H‫א‬P7ˆQ5D‫و‬C
C#
int[] intarray = new int[] { 15, 20, 13 };
‫ﻛﻮد‬
VB
Dim intarray As Integer() = New Integer() {15, 20, 13}
‫ﻛﻮد‬
109
‫اﻟﻤﺼﻔﻮﻓﺎت ﻣﺘﻌﺪدة اﻻﺑﻌﺎد‬
.6.3
h!'OV\‫א‬53AI‫א'אعא‬¤NS، one dimensional $‫א‬Q‫ אد‬h!'OV3S7‫א‬h!'OV\‫א‬0B
: Matrix - nF−‫د‬9‫א‬jN‹!'OV3nD‫^ل‬3‫א‬WS، Multi dimensional ‫د‬9‫ א‬i‫د‬$3‫אو‬jN‹
C#
int matrix = new int[3,3];
‫ﻛﻮد‬
VB
Dim matrix As Integer = New Integer(2, 2)
‫ﻛﻮد‬
:(s‫א‬Z!‫א)א‬KPT!'OV\‫א‬KP,‫'ن‬P
000
000
0 0 0
:‫א‬KPT!'OV\‫א‬53 17„‘h‫لא‬I‫אد‬5P>‫و‬
C#
matrix[1,2]=20;
‫ﻛﻮد‬
VB
matrix(1, 2) = 20
‫ﻛﻮد‬
:ً ^3‫ א‬KPT‫م‬$+\‫ˆא‬Q5D5P‫و‬،h‫لא‬I‫د‬9H‫א‬P7KFD5P>
C#
int matrix = new int[3, 3];
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
matrix[i,j]=Console.ReadLine();
‫ﻛﻮد‬
110
VB
Dim matrix As Integer = New Integer(2, 2) {}
For i As Integer = 0 To 2
For j As Integer = 0 To 2
matrix(i, j) = Console.ReadLine()
Next
Next ‫ﻛﻮد‬
.ً MQ‫א‬KPT‫@א‬OND1‫وא‬
‫ﻋﻤﻞ ﻣﺼﻔﻮﻓﺔ ﻣﻦ اﻟﻤﺼﻔﻮﻓﺎت‬
:‫א‬KPT!'OV3 nDgN3VNDK'd!'OV3KFD5P>
C#
int[][] complexarray = new int[5][];
‫ﻛﻮد‬
VB
Dim complexarray As Integer()() = New Integer(4)()
‫ﻛﻮد‬
:ً ^3‫'دא‬P‫ˆא‬Q5Dg!VND‫'ل‬b'‫א‬5P>‫و‬
C#
Console.WriteLine(complexarray[1][4]);
‫ﻛﻮد‬
VB
Console.WriteLine(complexarray(1)(4))
‫ﻛﻮد‬
. complexarray!'OV\‫א‬5Fsi‫'د‬%'\‫'!אو„א‬OV\‫א‬534.HVN‫ א‬cQ3‫א‬WS‫و‬
111
‫ارﺳﺎل واﺳﺘﻘﺒﺎل اﻟﻤﺼﻔﻮﻓﺎت ﻣﻦ وإﻟﻰ اﻟﺪوال‬
.6.5
:‫א‬KPT!'OV3hQ')D1‫دא‬KFDNP>
C#
static void print(int[] arr)
{
for (int i = 0; i < arr.Length; i++)
Console.WriteLine(arr[i]);
}
‫ﻛﻮد‬
VB
Private Sub print(ByVal arr As Integer())
For i As Integer = 0 To arr.Length - 1
Console.WriteLine(arr(i))
Next
End Sub
‫ﻛﻮد‬
.‫'!א‬OV\‫א‬nD‹p‫א‬$‫א‬UKQ$C‫א‬W،ًs‫א‬Z!‫ א‬byref g3K3‫א‬Q:‫ًא‬nN9
:‫א‬KPT‫'د‬P‫א‬GP، return ‫א‬$‫ א‬53:‫د‬D‫'دא‬3S array ‫'نאل‬U
C#
static int [] read()
{
int []arr=new int[3];
for (int i=0;i<3;i++)
arr[i]=Console.Read();
return arr;
}
‫ﻛﻮد‬
VB
Private Function read() As Integer()
Dim arr As Integer() = New Integer(2) {}
For i As Integer = 0 To 2
arr(i) = Console.Read()
Next
Return arr
End Function
‫ﻛﻮد‬
112
‫ﺧﺼﺎﺋﺺ اﻟﻤﺼﻔﻮﻓﺎت اﻟﺮﺋﻴﺴﻴﺔ‬
.6.6
:ً3‫א‬$+‫א‬S^‫وא‬Sg,‫א‬،gDKF‫א‬U¤$D $.‫*ودوאل‬jVI™nDh!'OV\‫'א‬
‫אم‬$+9‫א‬
bœ‫א‬
!'OV\‫א‬bND‫د 'ل‬$
Length
!'OV\‫א‬bNDGZ‫'م‬7
Sort
!'OV\‫א‬bNDG@P‫'م‬7
Reverse
V
q3„‘!'OV\‫א‬KQ'R
ToString
!'OV\‫א‬U‫د‬9‫دא‬$D‫د‬$
Rank
Enumeration ‫اﻟـ‬
.7
234‫א‬KI‫دא‬O†.‫ و‬h9K^ebN‫א‬53D'FnD' enumerations - ~HVI‫א‬Enum
h‫א‬H‫ א‬53‫א'אع‬E ‹NQ$‫ض‬ZON،h‫א‬H‫א‬h Q‫\'د‬Ug3‫א‬$+‫'א‬S Enum ‫אل‬nD‫^ل‬3a‫א‬
N¦!،ً ^3h‫א‬i$D.U2‫ و‬1،0.KP,nDgNQ+‫'م‬7N'، FIAT ‫
ًא‬I‫وא‬Nissan ،Toyota ،
„‘ ً 79 :B W‫ وא‬gƒ‫ل א‬I‫ אد‬:NP> K ، iH K .H ‫ل‬I‫ אد‬nD 234\‫א‬4< ‫ אن‬$Q 9
.:&N\‫א‬.‫א‬
C#
enum cars
{
toyota=0,
nissan=1,
fiat=2
}
‫ﻛﻮد‬
VB
Enum cars
toyota = 0
‫ﻛﻮد‬
113
nissan = 1
fiat = 2
End Enum
‫'ع‬N‫ א‬$Q$5P>،ًMQ‫א\א‬HVI9 enum ‫אل‬VNDg!5Q§Qt‫ א\א‬$Q$ًMQ‫א‬NNP>
:‫א‬KPT‫ذ‬nD‫^ل‬Fbyte
C#
enum cars:byte
{
toyota=0,
nissan=1,
fiat=2
}
‫ﻛﻮد‬
VB
Enum cars As Byte
toyota = 0
nissan = 1
fiat = 2
End Enum
‫ﻛﻮد‬
، ‫אم‬$+9‫' א‬g N KOPQ } ‫'ز‬3‫و א‬C ‫م‬.H9‫ א‬53 ً9$ 4‫ א‬U i$Q$Ž‫ א‬zƒ9‫אم א‬$+‫ א‬NNP> ‫אšن‬
.iH‫אא‬nDzNiH‫دאضא‬$QN‫^ ً א‬3‫ض‬ZON
C#
static void printPrice(cars mycar)
{
if (mycar == cars.fiat)
Console.WriteLine("20,000");
else if (mycar==cars.nissan)
Console.WriteLine("30,000");
else
Console.WriteLine("40,000");
}
‫ﻛﻮد‬
VB
Private Sub printPrice(ByVal mycar As cars)
If mycar = cars.fiat Then
‫ﻛﻮد‬
114
Console.WriteLine("20,000")
ElseIf mycar = cars.nissan Then
Console.WriteLine("30,000")
Else
Console.WriteLine("40,000")
End If
End Sub
. byte ‫'ع‬53S+\‫א‬O‫א‬7‫—אن א‬HRs‫وא‬zƒ‫مא‬$+N‫א‬$<‫א‬WPS
K^3h K€‫א‬0.‫א'א‬U،‫وز‬$NQ'bœ‫ א‬API ‫دوאل‬S enum Ki$jO:§NP> 3s‫אو‬
ً9$3
q\9$ Local K^3Rs‫א'א‬zƒ‫™א‬KO${0.‫א'א‬U5P،‫وאل‬$ A127X 00
. ‫'ز‬3‫א‬BZ‫'س‬3. ‫'د‬%‫دونو‬gFg!DGVt‫وא‬i$7\‫'زא‬3‫א‬53
Structure ‫اﻟﺘﺮاﻛﻴﺐ‬
.8
nD *jVI ‫ א‬K" 01 SzT‫ א‬NP> h‫ א‬53 VV† ‫ א'אع‬S Structs ‫ אو‬Structure ~‫א‬
0NV‫א‬KQ‫'د‬3$<iHKP،iH‫^لא‬3'S Struct nD‫^ل‬3a‫א‬،:! I‫دوאلو‬n‫אو‬h‫
א‬q3KP,
:ً ^3‫א‬KPT Struct ‫אل‬NNP>،ً ^3 '‫א‬.H‫و‬H\‫وאא‬
C#
struct Car
{
public int carNumber;
public int year;
public string factory;
};
‫ﻛﻮد‬
VB
Structure Car
Public carNumber As Integer
Public year As Integer
Public factory As String
End Structure
‫ﻛﻮد‬
115
:‫א‬KPTgVjVIY‫'م‬7N¦!iH53+oQ$Q3$ND‫وאšن‬
C#
Car ahmedcar = new Car();
ahmedcar.carNumber = 1000;
ahmedcar.factory = "Nissan";
ahmedcar.year = 2007;
‫ﻛﻮد‬
VB
Dim ahmedcar As New Car()
ahmedcar.carNumber = 1000
ahmedcar.factory = "Nissan"
ahmedcar.year = 2007
‫ﻛﻮد‬
nD'd
‫א‬VI StructNsZ!‫'א‬، Struct lH‫و‬$Iš‫'א‬S VNDnD Struct ‫'אل‬d‫אن‬5P>
:‫א‬KPT‫'نذ‬P!،ً ^3VI‫א‬zg97\‫א‬h‫'א‬N‫م وא‬$+\‫אא‬
C#
struct Licence
{
public string UserName;
public int yearsToFinish;
}
‫ﻛﻮد‬
VB
Structure Licence
Public UserName As String
Public yearsToFinish As Integer
End Structure
‫ﻛﻮد‬
:‫א‬KPT‫!ذ‬،iH‫*א‬jVI53 z%
‫א‬VIHK<‫دאن‬H‫وאšن'א‬
C#
struct Car
{
public int carNumber;
public int year;
public string factory;
public Licence carLicence;
};
‫ﻛﻮد‬
116
VB
Structure Car
Public carNumber As Integer
Public year As Integer
Public factory As String
Public carLicence As Licence
End Structure
‫ﻛﻮد‬
:‫א‬KPT ‫'د‬GPNiH‫*א‬jVI$Q$R‫و‬
C#
Car ahmedcar = new Car();
ahmedcar.carNumber = 1000;
ahmedcar.factory = "Nissan";
ahmedcar.year = 2007;
ahmedcar.carLicence.UserName = "Ahmed Gamal";
ahmedcar.carLicence.yearsToFinish = 3;
‫ﻛﻮد‬
VB
Dim ahmedcar As New Car()
ahmedcar.carNumber = 1000
ahmedcar.factory = "Nissan"
ahmedcar.year = 2007
ahmedcar.carLicence.UserName = "Ahmed Gamal"
ahmedcar.carLicence.yearsToFinish = 3
Struct ‫اﻧﺸﺎء اﻟﺪوال داﺧﻞ ال‬
‫ﻛﻮد‬
.6.1
'‫ذ‬nD‫^ل‬3 a‫א‬، Struct ‫אאل‬WSnDhF‫'م™א‬7 ‫دא‬zT‫ א‬Struct ‫א‬KI‫دא‬UNNP>
:‫א‬KPT Struct ‫אل‬L‫א‬lWSU5P>،
‫א‬VIH$Q$` renew ‫دא‬KFD‫د‬H‫א‬
C#
struct Licence
{
public string UserName;
public int yearsToFinish;
public void renew(int periode)
‫ﻛﻮد‬
117
{
yearsToFinish += periode;
}
}
VB
Structure Licence
Public UserName As String
Public yearsToFinish As Integer Public Sub renew(ByVal periode As Integer)
yearsToFinish += periode
End Sub
End Structure
‫ﻛﻮد‬
.i,3‫א‬$‫א‬lWS„‘‫'ل‬b'‫ˆא‬Q 5DVI‫א‬iZ!$Q${NNP>‫א‬WPS‫و‬
‫ل‬I‫אد‬0N\ ‫ˆدאوذ‬Q5D9‘i,3bN‫'ل‘„א‬b'FQ9i‫אد‬UO‫ א‬h71‫א‬U
Q Struct ‫ אل‬53 + zT‫ א‬$‫^ ً و‬3 Struct ‫ אل‬zT9 Create‫ دא‬KFD 5P> . ً ^3 'q3 h
.h‫
א‬q\‫א‬.Q¯ FQ5h‫א‬±\‫א‬$‫א‬lWSzD$‫א‬
Qe Struct ‫ אل‬53 + zT‫€ א‬.‫ و‬NP> ، $T\‫ אو א‬Constructor ‫אم‬$+ IŠ K ¤NS
:‫א‬KPT$T\‫א‬Q،'1\‫ א‬h‫א‬
C#
struct Car
{
private int carNumber;
private int year;
private string factory;
private Licence carLicence;
public Car(int p_carNumber, int p_year, string p_factory,Licence p_carLicence)
{
carNumber = p_carNumber;
factory = p_factory;
year = p_year;
carLicence = p_carLicence;
}
};
‫ﻛﻮد‬
118
‫ﻛﻮد‬
VB
Structure Car
Private carNumber As Integer
Private year As Integer
Private factory As String
Private carLicence As Licence Public Sub New(ByVal p_carNumber As Integer, ByVal p_year As Integer, ByVal
p_factory As String, ByVal p_carLicence As Licence)
carNumber = p_carNumber
factory = p_factory
year = p_year
carLicence = p_carLicence
End Sub End Structure
h!3، Struct ‫جאل‬HI:‫'ل‬b'‫א‬5P>9r private ‫'ن‬P h‫
א‬q\‫'ل‘„א‬b'‫א‬N'N‫א‬ª9
public ‫אنאن‬OPQ5P‫و‬K`9‫א‬W OOP ‫_אل‬DUKI$FNNs‫'א‬3 $‫'نא‬P‫'ل‬b'‫א‬
‫אل‬KI‫دא‬539‘ k‫'ل‬b'‫א‬5P> ! private 3‫א‬،‫א‬$‫
אوא‬q\‫ن‘„א‬P3‫א‬53‫'ل‬b'‫א‬. K{
.Struct
Reference ‫ واﻷﻧﻮاع‬Value ‫اﻷﻧﻮع‬
.9
nN3، Value Type 537T3h‫(א'אع א‬3‫אن‬$`N،h‫
א‬q\‫سא'אعא‬H‫‘„د‬AICi3$D'
:‫א‬KPTً9^3NsZ!‫!'א‬،:OK^>gN3
q3 K‫ אن‬Value Type 537T3‫א'אع‬lWS‫אن‬
C#
int x=5;
int y=x;
y=18;
Console.WriteLine(x);
Console.WriteLine(y);
‫ﻛﻮد‬
VB
Dim x As Integer = 5
Dim y As Integer = x
y = 18
Console.WriteLine(x)
Console.WriteLine(y)
‫ﻛﻮد‬
119
g! y=x BUN‫א‬G‫א‬،Q‫א‬$‫ א‬UgNNQ‫و‬N‫—א‬،:bIF.: y ‫ و‬x 53ً ‫אن‬$`N
. x F.nDKVd y q3]TNQ‫אن‬Q3'P‫א‬
...ً MQ‫ א‬struct ‫אل‬nD ،9‫א‬h‫
א‬q\‫א‬nDˆ1NQ‫(م‬N‫אא‬WS@O
‫א‬KPTiH‫^لא‬3‫ض‬ZON،‫א\^ل‬gDˆ1NQ9 Class ‫אل‬K^3 Refernce Types ‫'ع‬53‫א'אع‬
C#
class car
{
int carNumber;
string carName;
}
‫ﻛﻮد‬
VB
Class car
Private carNumber As Integer
‫ﻛﻮد‬
Private carName As String
End Class
:‫א‬KPT‫'نא\^ل‬P، ints ‫אل‬03 ˆ‫@א\^لא‬OGPN‫وאšن‬
C#
Car x = new Car();
‫ﻛﻮد‬
x.carNumber=1;
Car y=x;
Console.WriteLine (x==y);
VB
Dim x As New Car()
x.carNumber = 1
Dim y As Car = x
Console.WriteLine(x = y)
‫ﻛﻮد‬
120
y ‫ و‬x q\‫‘ذאنא‬، ]1†€]! gDKQ$‫א‬NP> car 53+nD'd y q\‫אنא‬5(€N'
53‫ذ‬53$]‫א‬NP>،I³KQ$UGFS$‫ א‬UKQ$]!‫و‬،
q\‫@א‬ON‫
ون‬TQ
:‫א‬K^3‫ ل'د‬I
C#
Car x = newCar();
Car y = x;
x.carNumber=1;
y.carNumber =2;
Console.WriteLine (x.carNumber);
Console.ReadKey();
‫ﻛﻮد‬
VB
Dim x As Car = newCar()
Dim y As Car = x
x.carNumber = 1
y.carNumber = 2
Console.WriteLine(x.carNumber)
Console.ReadKey()
‫ﻛﻮد‬
‫ˆ אل‬1Q Car Class K´ . ، Clone ˆ1 53 $ 9 Car nF\‫ א‬Class ‫ אل‬53 77 + KF
. Clone‫دאאل‬P.‫و‬Cloneaple Interface
‫اﻟﻤﻘﺎرﻧﺎت‬
.10
، H7F C# U ==K3\‫وא‬C = K3\‫ א‬Y4\‫ א‬G—‫م א‬$+Q ، Q‫א‬$‫ א‬17N AIC i3 $N
:‫^ذ‬3‫א‬a‫א‬
C#
if (x==y)
{
‫ﻛﻮد‬
}
VB
if x=y Then
End if
‫ﻛﻮد‬
121
NS‫ و‬$V7‫و‬،‫مאو‬$DU False ‫'ن‬PF!‫אو‬U True V[‫ א‬F7‫'نא‬P
.1‫'אعא‬9‫א‬nDa7!ˆ1NQ ‫א‬WS5P‫و‬، "Ahmed"="Ahmed" ‫و‬C7=7‫אو‬5=5:ً ^3K3P‫אوא‬
‫ﻣﻼﺣﻈﺔ‬
...‫ وغيرھا‬Int , Long , String ‫األنواع البسيطة ھي االنوع مثل‬
: ً MQ‫א\^لאא‬03N,Kb‫'א‬N
C#
string a = new string(new char[] { 'h', 'e', 'l', 'l', 'o' });
string b = new string(new char[] { 'h', 'e', 'l', 'l', 'o' });
Console.WriteLine(a == b);
‫ﻛﻮد‬
VB
Dim a As New String(New Char() {"h"C, "e"C, "l"C, "l"C, "o"C})
Dim b As New String(New Char() {"h"C, "e"C, "l"C, "l"C, "o"C})
Console.WriteLine(a = b)
‫ﻛﻮد‬
:‫א‬1 ‫'د‬P‫א‬NF‫ذא'א‬35P‫و‬،ًMQ‫ א‬True `N‫א‬K(L‫א‬lWSU
C#
object c = a;
object d = b;
Console.WriteLine (c==d);
‫ﻛﻮد‬
VB
Dim c As Object = a
Dim d As Object = b
Console.WriteLine(c = d)
‫ﻛﻮد‬
L‫ א‬lWSUKL‫א‬، False ‫'ن‬P2N‫ –نא‬−a7!XH,‫א‬U − o N&G+ˆ‫א‬1‫א‬
: EqualsK3\‫אمא‬$+
C#
Console.WriteLine (c.Equals(d));
‫ﻛﻮد‬
VB
Console.WriteLine(c.Equals(d))
‫ﻛﻮد‬
122
:‫ض א\^لא‬ZON،ً ^3 Structs ‫אل‬YH7F Equals K3FIŠ‫אم‬$+‫א‬
C#
struct car
{
public int carNumber;
};
‫ﻛﻮد‬
VB
struct car
{
public int carNumber;
};
‫ﻛﻮد‬
:‫א‬h‫
א‬q\‫א‬oQ NF.'،‫وאšن‬
C#
Car x = new Car();
x.carNumber=1;
Car y=x;
Console.WriteLine (x==y);
‫ﻛﻮد‬
VB
Dim x As New Car() x.carNumber = 1
Dim y As Car = x
Console.WriteLine(x = y)
‫ﻛﻮد‬
False €nSo ‫ ؟؟؟‬True SD'1\‫'نאא‬P‫ضאن‬ZO\‫א‬،:.'W‫א‬2N‫'א‬S3
.]1I1‫א‬WS‫–ن‬
:‫א‬7Q1 Equals K3\‫אمא‬$+'SRV‫א‬KL‫א‬
C#
Console.WriteLine (x.Equals(y));
‫ﻛﻮد‬
123
VB
Console.WriteLine(x.Equals(y))
‫ﻛﻮد‬
:‫א‬KPTًMQ‫אم==א‬$+‫א‬5P>، Classes oQU
C#
Console.WriteLine (Class1==Class2);
‫ﻛﻮد‬
VB
Console.WriteLine(Class1 = Class2)
‫ﻛﻮد‬
‫ ؟‬True ً Fj‫دא‬2N‫'نא‬PQ‫\ذא‬fKS،ˆ‫א\^لא‬UF Equals ‫و‬C
2N‫אنא‬Wi‫א‬W‫א‬U‫ن‬P\‫@א‬ON‫
אن‬TQ‫ن‬NjP‫אنא‬4+ CS‫'ع‬s'\‫אא‬Wk71N\‫א‬%9‫א‬
:‫ א‬KPTTrue
:‫ضא\^لא‬ZON،Rb‫א‬WS‫و‬
C#
Car x = new Car();
Car y = new Car();
x.carNumber=1;
y.carNumber = 1;
Console.WriteLine (x==y);
Console.ReadKey();
‫ﻛﻮد‬
124
VB
Dim x As New Car()
Dim y As New Car() x.carNumber = 1
y.carNumber = 1 ‫ﻛﻮد‬
Console.WriteLine(x = y)
Console.ReadKey()
:‫א‬KPT‫دא‬PKL‫ א‬،i$‫وא‬FkI‫א‬$‫*א‬jVœ‫ —אنא‬False ... S`N‫'نא‬P
C#
bool isthesame(Car c1,Car c2)
{
if (c1.carNumber==c2.carNumber)
return true;
return false;
}
‫ﻛﻮد‬
VB
Private Function isthesame(ByVal c1 As Car, ByVal c2 As Car) As Boolean
If c1.carNumber = c2.carNumber Then
Return True
End If
Return False
End Function ‫ﻛﻮد‬
‫
؟‬q\‫א‬53i$Q$%+ KFDUG—N'‫ذא‬35P
:‫א‬KPT Clone C$3‫م‬$+L‫א‬lWSU
C#
Car doCopy(Car c1)
{
Car newCar = new Car();
newCar.carNumber=c1.carNumber;
//
//
return newCar;
}
‫ﻛﻮد‬
125
VB
Private Function doCopy(ByVal c1 As Car) As Car
Dim newCar As New Car()
newCar.carNumber = c1.carNumber
'
'
Return newCar
End Function
‫ﻛﻮد‬
g%‫ א'א‬53 7T3 J! ‫ א‬، s‫א‬Z!‫ א‬iH'V i‫'د‬%'3 Clone ‫א‬$‫ א‬${ 9‫ א‬bN‫ א‬53 ^ U
€F.‫ و‬Class JO‫ א‬4 ‫'م‬7 53 €‫€ א‬N ' ،i,3 ‫אم‬$+ iS% ‫א‬$‫ א‬lWS $`ICloneaple
nD bœ‫ א‬JO‫'ن א‬P r g4 ‫'م‬7 i‫'د‬%'3 Clone ‫א‬$‫ א‬$`! 7‫ א‬JO‫ א‬53 g.7,
. i,3k Clone KFD53JO‫م‬$+3‫א‬01Q،7‫
א‬Q\‫א‬
Nullable Types
.11
'd‫אن‬$9ً ^3 Boolean ‫'ع‬53
q\!، ً . ‫'א‬73
— Null F7‫א‬$Q$7‫א‬h‫
א‬q\‫א‬fDU
U،‫א‬WPS‫و‬...ً ^3 32767‫و‬OV‫א‬Y3‫م‬.H‫א‬nD'd‫אن‬$9 Short q\‫א‬، False ‫و‬C True nD
. reference ‫'ع‬53g null F7‫א‬X‫א‬01 String ً ^3VN‫א‬7‫€ א‬Y
5QH‫د‬.
—N‫א‬nN} ( Null− F.9)F. Boolean 71N3
q3KFd‫ن‬1M‫ن‬9‫™א‬UNNP
43G—‫א‬:%‫'א‬t‫א‬Q$7‫א‬PT\‫א‬S‫^ذ‬3‫א‬a‫א‬، False ‫و‬C True ‫‘ذאن‬F!$Q$nD
‫م‬$+\‫ض אنא‬ON‫و‬،(‫وج‬3)K75P‫و‬3K7UF7‫م‬$+\‫لא‬I‫مאد‬$DUh‫ א‬$D‫'א‬.
‫م‬Q‫ن‬3'S‫و‬، null F7 ªOdK7L‫א‬K(L‫א‬lWSU،:3$D53ً%‫و‬3*+T‫د'نא‬$d_
.ً ^3 bool ‫'ع‬53
q3 ‫א‬Ugs‫و‬K. Null €g‫א‬nD CheckKFD
null F7‫א‬K7F*V†
q3oQ‫ن‬P39b‫ א‬.net framework 53^‫ א‬iH‫א‬$b9‫א‬03‫و‬5P
:‫א\^لא‬UF،:9‫א‬7!s‫א‬
C#
bool? ismarried = null;
‫ﻛﻮد‬
126
VB
Dim ismarried As System.Nullable(Of Boolean) = Nothing
‫ﻛﻮد‬
Null SL‫א‬F7‫'نא‬53ˆ7‫دونא‬h‫א‬i$D.53i,3F.iz‫א‬7 l‫د‬N‫א‬NNP>L‫א‬lWSU
:MQ‫אא‬7Q1‫ א‬K^3 Null K7Q
q3oQAI‫قא‬i$D¤NS
C#
Nullable<bool> nullableBool = null;
‫ﻛﻮد‬
UlN3 nDfN3'S‫و‬، System.Nullable<T> nF\‫ א‬generic KHVI‫!ًא‬S ? ‫אن‬
.XP‫א‬533‫د‬.z‫א‬%C
:‫א‬KPT‫'نذ‬P! Nullable k return ‫'نאل‬PQ‫دא‬oQ‫د‬H‫'א‬F! 7Q1‫@א‬ON‫و‬
C#
public bool? functionName()
{
‫ﻛﻮد‬
}
VB
Public Function functionName() As System.Nullable(Of Boolean)
‫ﻛﻮد‬
End Function
Nullable ‫ﺧﺼﺎﺋﺺ ال‬
.11.1
ªOd :‫ אم א‬F. : q\‫ ‘ذא ن א‬F! ‫د‬$ t‫ وא‬HasValue bI S nullable ‫* אل‬jVI S‫א‬
:‫א‬KPT Null F7
C#
if (ismarried.HasValue)
{
‫ﻛﻮد‬
}
127
VB
If ismarried.HasValue Then
‫ﻛﻮد‬
End If
:‫א‬KPT‫`'אل‬O‫ א‬U <> ‫و‬C=!ًMQ‫א‬H7\‫א‬Kj‫אمو‬$+g5P>
C#
if (ismarried!=null)
‫ﻛﻮد‬
VB
if ismarried<>nothing then
‫ﻛﻮد‬
‫ﻣﻼﺣﻈﺔ‬
‫ في السي شارب‬null ‫ خاصة بالفيجوال بيسك بدال ً من‬nothing ‫ال تنس أن‬
” ‫اﻟﻤﻌﺎﻣﻞ “؟؟‬
.11.2
‫ض‬ZON، null XS‫'د‬%‫و‬U3F.0s'l4µP nullable ‫אل‬7‫א‬03‫؟؟‬K3\‫אمא‬$+‫א‬5P>
‫אن‬nN}XD‫*א‬+,'g!‫אوאج‬h‫ل‬I‫د‬7Q_*+,‫ضאنא‬ZON‫و‬،ˆ‫^لאوאج א‬3
:‫ذ‬K%‫א‬53‫'دא‬P‫א‬P‫'م‬7N،i,3 False VF7‫א‬
C#
int? ismarried = returnvaluefromdatabase() ?? False;
‫ﻛﻮد‬
VB
Dim ismarried As System.Nullable(Of Integer) = IIf(returnvaluefromdatabase() Is
Nothing, [False], returnvaluefromdatabase())
‫ﻛﻮد‬
128
‫‪129‬‬
‫اﻟﺒﺎب‬
‫‬
‫‬
‫‬
‫‪8‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫اﻟﻔﺌﺎت وﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ‬
‫ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
130
131
Classes ‫ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﻔﺌﺎت‬
.1
i$‫ وא‬J! nD 'd Console Application€ ]TN\‫ א‬234‫ !¦ن א‬، 7‫ א‬N‫و‬H‫ د‬U N(9 F
N! 0.‫ א'א‬U ... ‫ وق‬h‫א‬z‫א‬%‫ وא‬h‫
א‬q3‫ دوאل و‬nD gI‫א‬$ ' class Program lF3
. Class JO‫'א‬S OOP ¨‫د‬3ˆ1Q239‫א‬
—HU،:I‫א‬$hJ!i$DnDًMQ‫א‬JO‫אن'א‬5P>‫و‬،hJ! i$DnD234‫'א‬d‫אن‬5P>
. Project 53 New Class !s‫א‬NP>KVON3 Class KFD U
‫و‬CXH,‫א‬U{}Y:'P3oQ Q،:ƒ‫‹א‬53‫ و‬Class i‫א[`'ز‬FP‫אمא‬$+JO‫א‬oQQ
، Person gF‫ و‬i$Q$% J! ‫אج‬H‫'م د‬7N ، VB.net U End Classn oQ‫ א‬B $ 53
:s‫א‬Z!‫ א‬iH'Vً‫'دא‬%'3‫'دא‬P‫א‬$`N
C#
namespace ConsoleApplication4
{
class Person
{
}
}
‫ﻛﻮد‬
VB
Namespace ConsoleApplication4
Class Person
‫ﻛﻮد‬
End Class
End Namespace
i‫'د‬%'\‫ א‬Classes hJO‫ א‬0B ‫א אن‬WS cQ ، H‫و‬s namespace ‫د אل‬$d W‫ אول א‬zŽ‫א‬
‫ ل‬I53 i$Q$Ž‫ א‬JO‫א‬03K3‫א‬535PFN‫א‬W،Iš‫א‬gM Q¯HgNP> namespace ‫@אل‬O€
. Program lF\‫א‬9‫א‬JO‫ א‬UNbœ‫א‬main
132
JO‫א‬KI‫دא‬F‫
وא‬I‫אولوא‬9‫א‬h!s‫^ ًא‬3NNP>،h‫
א‬q\‫א‬S ClassJ!Ch'P3a‫א‬
:‫א‬KPTClass
C#
class Person
{
public string FirstName;
public string LastName;
public int Age;
}
‫ﻛﻮد‬
VB
Class Person
‫ﻛﻮد‬
Public FirstName As String
Public LastName As String
Public Age As Integer
End Class
:ً ^3‫א‬KPTJO‫ א‬lWS53 Objects hNji$DoQ5P>‫אšن‬
C#
Person Ahmed = new Person();
Ahmed.Age = 15;
Ahmed.FirstName = "Ahmed";
Ahmed.LastName = "Gamal";
Person Ali = new Person();
Ali.Age = 15;
Ali.FirstName = "Ahmed";
Ali.LastName = "Gamal";
‫ﻛﻮد‬
VB
Dim Ahmed As New Person()
Ahmed.Age = 15
Ahmed.FirstName = "Ahmed"
Ahmed.LastName = "Gamal"
Dim Ali As New Person()
Ali.Age = 15
Ali.FirstName = "Ahmed"
Ali.LastName = "Gamal"
‫ﻛﻮد‬
133
:‫א‬KPT!'OV3 KP,nDgOQ5P>‫و‬C
C#
Person [] MyEmpolyee = new Person[3];
MyEmpolyee[0] = new Person();
MyEmpolyee[0].FirstName = "Ahmed";
MyEmpolyee[0].LastName = "Gamal";
MyEmpolyee[0].Age = 15;
‫ﻛﻮد‬
VB
Dim MyEmpolyee As Person() = New Person(2) {}
MyEmpolyee(0) = New Person()
MyEmpolyee(0).FirstName = "Ahmed"
MyEmpolyee(0).LastName = "Gamal"
MyEmpolyee(0).Age = 15
‫ﻛﻮد‬
N$‫دא‬4‫'م‬7N،ClassJO‫א‬KI‫وאلدא‬$‫א‬oQًMQ‫א‬NP3 ‫!¦ن‬، Struct ‫אل‬U‫ذ‬F
:‫א‬KPT‫'ن‬P،Y3*+TK3P‫ א‬9‫א‬
C#
‫ﻛﻮد‬
public string getFullName()
{
return FirstName + LastName;
}
VB
Public Function getFullName() As String
Return FirstName + LastName
End Function
‫ﻛﻮد‬
134
Constructors ‫اﻟﻤﺸﻴﺪات‬
.1.1
t‫אא‬$‫א‬S‫و‬، Constructor‫אאل‬$‫א‬KqT‫'م‬7N‫א‬cQ‫א‬WS‫ !¦ن‬new Person() oQ‫'م‬73$ND
t‫ א‬g!3‫وא‬9‫ ™ א‬0s‫ و‬NNP>‫ و‬I ‫א‬$‫ א‬lWS‫'ن‬P ً s‫א‬Z!‫ א‬، 234‫ א‬53 + ‫ א‬KqT 03 KF
:ClassJO‫א‬53i$Q$%+ zT4§Hً ^3‫ض‬،+zT‫€א‬.‫و‬g%‰
C#
public Person()
{
Console.WriteLine("new object");
}
‫ﻛﻮد‬
VB
Public Sub New()
Console.WriteLine("new object")
End Sub
‫ﻛﻮد‬
‫ﻣﻼﺣﻈﺔ‬
‫ اما في فيجوال بيسك فيتم تسمية الدالة‬، ‫في السي شارب يتم عمل دالة بنفس اسم الفئة‬
New ‫باسم‬
03 ‫ אول‬9‫ א‬K7Q Constructor ‫ אل‬KŽ ً ^F! ، h‫א‬Z3H Constructor ‫ אل‬K7Q ‫ ً אن‬MQ‫ א‬5P>
:‫א‬KPT‫'نذ‬P!،$Q$Ž‫€א‬P´‫و‬9‫ א‬oQ
C#
‫ﻛﻮد‬
public Person(string userfirstname)
{
FirstName = userfirstname;
}
VB
Public Sub New(ByVal userfirstname As String)
FirstName = userfirstname
End Sub
‫ﻛﻮد‬
:‫'دא‬P‫ א‬NDG%'i$Q$%+KF‫و‬
135
C#
Person MyEmpolyee = new Person("ahmed");
‫ﻛﻮد‬
VB
Dim MyEmpolyee As New Person("ahmed")
‫ﻛﻮد‬
Destructor ‫اﻟﻤﻬﺪﻣﺎت‬
.1.2
ً ^3 Beep h'bH‫א‬$b9، Object ‫אمאل‬$+‫א‬zg‫א‬03E$L‫אא‬WS‫א ق‬Q، Constructor ‫@אل‬PD
:234‫א‬zg‫א‬03
C#
~Person()
{
Console.Beep();
}
‫ﻛﻮد‬
VB
Protected Overrides Sub Finalize() End Sub
‫ﻛﻮد‬
3„‘‫ ‰ج‬3ً‫א‬،ً3eObject5jP‫
א‬3$K.hF‫™א‬WONU Destructor ‫אل‬53$O
q :3‫א‬$+‫ א‬5P> ً MQ‫ א‬، E$L‫א א‬Wk g,9‫אم א‬$+9‫' א‬S‫ و‬i‫א‬W‫ א‬U : 1\‫ א‬h‫
א‬q\‫ א‬0B
.N3 J!53¢N‫א‬$‫'م‬7t‫^ ًوא‬3h‫אدא‬$‫א‬
this
.2
W‫وא‬،i,3ˆ‫سא‬H$‫א‬U‫'د‘„ א\^ل‬N،XH,‫א‬U this i‫א[`'ز‬FP‫'مא‬gO3s'
:‫א‬KPT Constructor KF:!NF.
C#
‫ﻛﻮد‬
public Person(string userfirstname)
{
FirstName = userfirstname;
}
136
VB
Public Sub New(ByVal userfirstname As String)
FirstName = userfirstname
End Sub
‫ﻛﻮد‬
:ً ^3‫א‬KPT FirstName ‫'ن‬PZ3H‫
אא‬q ‫'م‬7NN‫אšنא‬NsZ!‫'א‬
C#
public Person(string FirstName)
{
FirstName = FirstName;
}
‫ﻛﻮد‬
VB
Public Sub New(ByVal FirstName As String)
FirstName = FirstName
End Sub
‫ﻛﻮد‬
„‘ (NQ 5‫ و‬، :O ‫و‬Q Z3H‫ א‬FirstName K{ ‫ א‬Q3'P‫ א‬gO o L‫ א‬lWS U
= €P´‫و‬9‫ א‬U ‫'د‬%'\‫
א‬q\‫ אن א‬$V7 ¦ Q3'P‫ א‬oQ . €P´‫و‬9‫ א‬5Fs qF FirstName
U ‫'د‬%'\‫
א‬q\‫
‘„ א‬T t‫ وא‬VB.net U Me ‫و‬C C# U this FP‫م א‬$+N K\‫ א‬Z3H‫א‬
:L‫€א‬P´‫و‬9‫א‬
C#
public Person(string FirstName)
{
this.FirstName = FirstName;
}
‫ﻛﻮد‬
VB
Public Sub New(ByVal FirstName As String)
Me.FirstName = FirstName
End Sub
‫ﻛﻮد‬
a‫ א‬، ً Fj‫ دא‬GN3 ‫'ن‬P this ‫אم‬$+‫ !¦ن א‬، ˆ‫س א‬H$‫ א‬U k N.1 t‫ א‬7‫ א‬L‫ א‬U n
. thisg!GP t‫(א‬R‫א‬WN34‫€א‬.‫€و‬P´‫و‬9‫א‬Ui‫'د‬%'\‫א‬bNFj.Hg&‫'א‬S‫ ذ‬X‫א‬
137
Static ‫اﻟﺘﻌﺮف ﻋﻠﻰ‬
.3
S&N\!s‫ א‬C# ‫אل‬U static FP‫م א‬$+N‫א‬234‫א‬Uً‫א‬i‫'د‬%'\‫ א‬main ‫א‬$‫א‬UN(9
‫ ؟‬FP‫א‬lWSnN3F!، VB.net ‫אل‬UShared
Q‫א‬$‫
אوא‬q\‫אא‬WS‫אن‬ch‫
א‬q\‫א‬n‫אو‬hJO‫وאل אوא‬$‫א‬03g3‫א‬$+‫א‬5P>t‫ وא‬static FP‫א‬
X‫ضא\^لאאœص‬ZON، object ‫אل‬A'353@‫و‬i,3 Class ‫אل‬A'3 nD53k‫'ل‬b'‫א‬
:Person
C#
class Person
{
public string FirstName;
public string LastName;
public int Age;
static public int counter;
}
‫ﻛﻮد‬
VB
Class Person
Public FirstName As String
Public LastName As String
Public Age As Integer Public Shared counter As Integer
End Class
‫ﻛﻮد‬
:ً ^3‫'دא‬P‫א‬N N‫ضא‬ZON‫و‬
C#
Person MyEmpolyee = new Person();
MyEmpolyee.Age = 15;
MyEmpolyee.counter = 3;
‫ﻛﻮد‬
VB
Dim MyEmpolyee As New Person()
MyEmpolyee.Age = 15
MyEmpolyee.counter = 3
‫ﻛﻮد‬
138
A'3nDi,3:z‫א‬.‫א‬W‫ و‬static q3'S counter ‫אن‬،ًRRb ‫'د‬P‫אא‬WS‫'ن‬PQ5o :‫א‬KPT ClassJO‫א‬
C#
Person MyEmpolyee = new Person();
MyEmpolyee.Age = 15;
Person.counter = 3;
‫ﻛﻮد‬
VB
Dim MyEmpolyee As New Person()
MyEmpolyee.Age = 15;
Person.counter = 3;
‫ﻛﻮد‬
ClassJO‫א‬KI‫دא‬53:bœ‫ א‬counter‫אل‬F.‫ض‬NF.‫و‬،JO‫@ א‬O53$Q$% Object oQNF.'
0FŽ Class JO‫ א‬A'3 nD :N3 i$‫ وא‬+ oQ Q static q\‫ ذ אن א‬، i,3 3 g‫ א‬$`N
.:N3gFDQt‫א‬objecthNjP‫א‬
‫א‬WS53S]TNt‫@א‬P´‫و‬9‫א‬$‫'م‬7t‫وא‬،h‫אدא‬$‫א‬bISbœ‫א‬lWS53 i‫د‬O9‫א‬nD‫^ل‬3
: Destructor U‫ن‬V7N‫'دא‬0MF! Constructor‫אل‬U!s9‫'دא‬P‫א‬0MN،ClassJO‫א‬
C#
class Person
{
public string FirstName;
public string LastName;
public int Age;
static public int counter;
public string getFullName()
{
return FirstName + LastName;
}
public Person()
{
counter++;
}
~Person()
{
counter--;
}
}
‫ﻛﻮد‬
139
VB
Class Person
Public FirstName As String
Public LastName As String
Public Age As Integer
‫ﻛﻮد‬
Public Shared counter As Integer
Public Function getFullName() As String
Return FirstName + LastName
End Function
Public Sub New()
counter += 1
End Sub
Protected Overrides Sub Finalize()
Try
counter -= 1
Finally
MyBase.Finalize()
End Try
End Sub
End Class
:‫אد‬$‫א‬F.‫'مض‬7‹53‫و‬،hNjP‫א‬53‫د‬$DzT ‫'م‬7N‫وאšن‬
C#
Person MyEmpolyee = new Person();
Person MyEmpolyee2 = new Person();
Person MyEmpolyee3 = new Person();
Person MyEmpolyee4 = new Person();
Person MyEmpolyee5 = new Person();
Console.WriteLine(Person.counter);
‫ﻛﻮد‬
VB
Dim MyEmpolyee As New Person()
Dim MyEmpolyee2 As New Person()
Dim MyEmpolyee3 As New Person()
‫ﻛﻮد‬
140
Dim MyEmpolyee4 As New Person()
Dim MyEmpolyee5 As New Person()
Console.WriteLine(Person.counter)
:‫'دא‬P‫א‬NsZ!‫وאšن'א‬
C#
Person [] MyEmpolyee = new Person[5];
Console.WriteLine(Person.counter);
‫ﻛﻮد‬
VB
Dim MyEmpolyee As Person() = New Person(4) {} Console.WriteLine(Person.counter)
‫ﻛﻮد‬
Q_ MyEmpolyee ¢53ًQ‫אن א‬G‫وא‬،:)U@.'o ، 5‫'ن‬P2N‫אنא‬0.'9
:52N‫א‬153S‫א‬L‫א‬،$lzT‫א‬
C#
Person [] MyEmpolyee = new Person[5];
for (int i = 0; i < 5; i++)
MyEmpolyee[0] = new Person();
Console.WriteLine(Person.counter);
‫ﻛﻮد‬
VB
Dim MyEmpolyee As Person() = New Person(4) {}
For i As Integer = 0 To 4
MyEmpolyee(0) = New Person()
Next
Console.WriteLine(Person.counter)
‫ﻛﻮد‬
Static Class
.3.1
$9 Static Class C‫ل!¦ن‬L‫א‬1‫و‬، Static Class ‫ אل‬C$3‫د‬FD‫ ”א‬.net framewrok 2.0 WN3
object oQ71N\‫א‬53@:¦!‫‘„ذ‬os‫א‬، static ‫'ع‬53:!‫وאل‬$‫ وא‬h‫
א‬q\‫א‬0B‫'ن‬P‫אن‬
. New ‫אم‬$+ClassJO‫א א‬WS53
141
MessageBox S Class‫אאل‬WS^3‫א‬a‫א‬،i,3‫ ودوא‬ClassJO‫אم א‬$+‫א‬5P>L‫א‬lWSU
.gN3+oQ‫دون‬i,3g3‫א‬$+‫ א‬5P>t‫وא‬
C#
MessageBox.Show(“Welcome”);
‫ﻛﻮد‬
VB
MessageBox.Show(“Welcome”)
‫ﻛﻮد‬
OverLoading ‫اﻋﺎدة اﻟﺘﺤﻤﻴﻞ‬
.4
@ON‫قאودوאل‬i$DF 5P>، Overloading ‫¨אل‬$3ˆ1S OOP ‫د¨אل‬3S‫א‬53
.‫س‬Z3H‫א‬U
q¤NS‫دאم‬39‫א‬
: Windows Forms ‫אل‬U MessageBox.Show() ‫دא‬S Overloading ‫אل‬hFDnD‫^ل‬3a‫א‬
:ً ^33‫אوא‬lWS $`€%'
‫ﻛﻮد‬
MessageBox.Show(string text)
MessageBox.Show(string text,string caption)
MessageBox.Show(string text, string caption, MessageBoxButtons buttons)
C$35PQ_'H'VN،9‫@א‬OًB k‫و‬bI‫دא‬5DiHDgN3i$‫وא‬K،3‫אوא‬75FsًMQ‫א‬S
—‫و‬
:‫א‬KPT‫ دوאل‬P1MNN،ً‫'دא‬%'3Overloading
‫ﻛﻮد‬
MessageBox.ShowWithString(string text)
MessageBox.ShowStringAndCaption(string text,string caption)
MessageBox.ShowStringAndCaptionAndButtons(string text, string caption,
MessageBoxButtons buttons)
. ‫אم‬$+9‫'א‬g GQ3‫א‬WS‫و‬،9‫@א‬ONًBS${‫אم‬$+9‫א‬Kg‫אšنو‬3C
142
‫א‬YUً ^30FŽ‫א‬F−‫א‬KPT‫'د‬NP>‫ دوא‬U OverLoading ‫אل‬C$3ˆ1
: double - ‫'ع‬53‫ אو‬int ‫'ع‬53.ClassJO‫א‬UH> KSH$9
C#
static int Add(int x, int y)
{
return x + y;
}
static double Add(double x, double y)
{
return x + y;
}
static long Add(long x, long y)
{
return x + y;
}
‫ﻛﻮد‬
VB
Private Shared Function Add(ByVal x As Integer, ByVal y As Integer) As Integer
Return x + y
End Function
Private Shared Function Add(ByVal x As Double, ByVal y As Double) As Double
Return x + y
End Function
Private Shared Function Add(ByVal x As Long, ByVal y As Long) As Long
Return x + y
End Function
‫ﻛﻮد‬
'،‫م‬$+\‫אجא‬GgN3‫د‬$DKFDNPF!، Constructor ‫אل‬03AIC i3iP‫א‬$‫אن‬5P>
: ‫א‬KPT Constructors ‫אل‬oQ5P> Person N^\ $D
C#
class Person
{
public string FirstName;
public string LastName;
public int Age;
public Person()
{
Console.WriteLine("c1");
‫ﻛﻮد‬
143
}
public Person(string fname,string lname)
{
FirstName = fname;
LastName = lname;
Console.WriteLine("c2");
}
public Person(string fname,string lname,int myage)
{
FirstName = fname;
LastName = lname;
Age = myage;
Console.WriteLine("c3");
}
}
VB
Class Person Public FirstName As String
Public LastName As String
Public Age As Integer
‫ﻛﻮد‬
Public Sub New()
Console.WriteLine("c1")
End Sub
Public Sub New(ByVal fname As String, ByVal lname As String)
FirstName = fname
LastName = lname
Console.WriteLine("c2")
End Sub
Public Sub New(ByVal fname As String, ByVal lname As String, ByVal myage As
Integer)
FirstName = fname
LastName = lname
Age = myage
Console.WriteLine("c3")
End Sub
End Class
:‫قא‬1‫א‬$] hNjzT‫א‬NNP>7Q1‫א‬lWg‫و‬
C#
Person MyEmpolyee = new Person();
Person MyEmpolyee = new Person("ahmed","gamal");
Person MyEmpolyee = new Person("ahmed", "gamal",22);
‫ﻛﻮد‬
144
VB
Dim MyEmpolyee As New Person()
Dim MyEmpolyee As New Person("ahmed", "gamal")
Dim MyEmpolyee As New Person("ahmed", "gamal", 22)
‫ﻛﻮد‬
Access Modifier ‫ﻣﻌﺮﻓﺎت اﻟﻮﺻﻮل‬
.5
NQ‫א‬WS‫وذאن‬، public 'S:3‫א‬$+ ‫'م‬7W‫א‬s‫א‬Z!9‫'لא‬b'‫א‬f3‫ن‬،7‫א‬N‫و‬H‫د‬U
f\‫ א‬N3$+‫ ' א‬N‘ ً MQ‫ א‬N. ، Object ‫ ل אل‬I 53 i,3 q\‫א א‬WS ‫و‬C ‫א‬$‫ א‬lWS „‘ ‫'ل‬b'‫א‬
a7! :O Class JO‫ א‬KI‫ دא‬53 A' ‫א‬$‫ א‬lWS ‫
אو‬q\‫א א‬WS Q¯H 53 5PF 5! Private
.gNh.‫و‬O‫وא‬O+\‫'ل א‬b'‫א‬h!3‫א'אع‬nDff'‫س‬H$‫אא‬WSU
: Public
JO‫ق א‬7, $C ‫م‬. ' ً MQ‫ א‬، i,3 Object ‫ אل‬53 q\‫و א‬C ‫א‬$‫'ل ‘„ א‬b'‫ א‬f\‫א א‬WS Q
.k‫'ل‬b'‫א‬$Q$Ž‫א‬ClassJO‫א‬53 objects K5PF‫و‬SF public ‫א‬$‫א‬lWS$`!Class
: Private
.: I53:OQ”W‫ א‬Struct ‫אوאل‬ClassJO‫ א‬KI‫دא‬:Q¯Ha7!5P>
: Protected
.ˆT\‫א‬ClassJO‫ א‬53k‫'ل‬b'‫א‬5P>5P‫ و‬Object ‫אل‬53k,\‫'لא‬b'‫א‬5P>9
: internal
.a7! L‫ƒא‬9‫א‬KI‫دא‬k‫'ل‬b'‫א‬5P>
: protected internal
.ƒ9‫א‬o3@O‫ ل‬I53k‫'ل‬b'!s‫ˆא‬T\‫א‬Class JO‫ لא‬I53ًMQ‫א‬k‫'ل‬b'‫א‬5P>
145
OOP ‫اﻟﻌﻨﺎﺻﺮ اﻻﺳﺎﺳﻴﺔ ﻓﻲ‬
.6
:‫א‬E ^‫ط א‬7N‫אنض‬$9 OOP ‫د¨אل‬3ˆ1t‫א‬4‫א‬hq0B
Encapsulation .1
Inheritance .2
Polymorphism .3
: Encapsulation
.6.1
nD ‫م‬$+F QgN‫ א‬U SHg&‫ وא‬O+\‫ وא'אد א‬h‫ א‬s‫ و‬zOI‫' א‬S Encapsulation ‫ ل‬$V7Q
‫'د‬%'\‫'دא‬P‫'א‬S3FgQ90.‫א'א‬U، PrintReport ‫دא‬QgN‫א‬U$` ، Black Box KP,
.QH7‫א‬D‫دא‬Q$KFSzD$‫א‬OPQ،gI‫دא‬
Structured X'KF‫א‬L‫א‬U،‫وع‬T\‫א‬nDDFŽ‫ א‬KF‫א‬Ubœ‫א‬lWS53ًMQ‫א‬$O
KF‫א‬53z%K‫'ن‬P! OOP ‫אل‬U Encapsulation ‫אل‬033‫א‬،$‫ن وא‬P3U‫'د‬P‫א‬0B$`
KF‫ א‬GKgUSQ3‫א‬WS‫و‬،O† Objects ˆQ5D™‫א‬gNKb‫א'א‬Q‫ و‬:OnDً7q3
.z1I‫א‬fT‫א‬Kg،
: Inheritance
.6.2
KQ$‫و‬CSQ'1K%‫א‬53:VjVI@OnD'ClassJO‫א‬53 i$Q$%+KFDg$V7Q‫و‬،‹‫א‬H'‫وא‬C
.ً ^3gNb¢QH‫و‬iH‫אא‬nD'd(iH)ClassJ!NQ$‫^ ًאن‬3 ‫ض‬ZON،*jVœ‫™א‬
ClassJ!KF‫'م‬7‫]אن‬1œ‫א‬53L‫א‬lWSU،ً ^3 BMW ‫אل‬h‫א‬H ClassJ!KF‫م‬7‫א‬$Q‫وאšن‬
isSport bI!s‫א‬03 Car nF\‫ א‬ClassJO‫א‬53$Q$% ClassJ!‫ق‬7,‫ א‬01NNP‫و‬،kKVON3
ًMQ‫ א‬، BMW ‫ و אل‬Car‫ אل‬Y ZT3 *jVI $`N N‫ ذ א‬53 f$k‫ א‬، BMW lF\‫ א‬Class JO
.ZT3hnDlH‫و‬$'RW‫ وא‬GMC KJ! !s9ً3'Q1MN
146
0BUKQ$‫'م‬7NKg! ،h‫א‬H‫א‬KP countofdoors K^3$Q$%VND!sNF.'Iš‫א‬G‫א‬
.h Q$‫ˆא‬1a7!:!KQ$‫א‬01N¦! Car JO‫א‬53‫ق‬7,‫א‬KFNF.U،hJO‫א‬
.h‫א‬53
‫'د‬%‫و‬Ui$jO‫` א‬K§015P‫و‬i
qV‫א‬hJO‫א‬UFS‫א‬g(9}H
‫ل‬P, J! ‫'د‬%‫و‬UًMQ‫א‬، BMW is a car ‫אن‬، is a Inheritance . ‫א‬oQ Q
.Circle is a shape‫^ ً!¦ن‬3ij‫א‬$AICJ!‫و‬
L‫א‬lWSU، aggregationnF‫ و‬has a . DS‫ و‬Classes ‫אل‬Yh. ‫א‬53IŠ‫'ع‬¤NS
، Wheels iH‫ א‬h `D K%‫ א‬53 J! NQ$ ‫^ ً ' ن‬3 ، „‫ אو‬JO‫ א‬nD Q') ^‫ א‬JO‫'ن א‬P
.Car has a wheel‫'ن‬P
: Polymorphism
.6.3
H%‫'א‬SG‫وא‬، Implementation‫ونא‬$ k‫وא‬$ J!P vF‫'א‬S OOP ¨‫د‬353
I‫א‬C$\‫א‬
‫^ل‬3 a‫א‬،zƒ9‫א‬:T5FMQ}‫وאل‬$‫א‬lWk implementation KF JO‫قא‬7, ‫'م‬7Q‫م‬$+3‫א‬
:‫א‬KPT:OQNNP>، Shape ~ClassJ!‫ذ‬nD
C#
class Shape
{
public void Draw()
{
}
public void GetSize()
{
}
}
‫ﻛﻮد‬
VB
Class Shape
Public Sub Draw()
End Sub
‫ﻛﻮد‬
147
Public Sub GetSize()
End Sub
End Class
ً‫^
א‬:TQW‫ وא‬Interface‫אل‬C$3ًMQ‫ א‬C# !'، Abstract Class Class ‫אل‬fQL‫א‬lWSU
.gNUgDfNh.‫!و‬035P‫ و‬Abstract Class ‫אل‬
‫א'אد‬nDً‫א‬4‫'ن‬P JO‫אא‬WS 53:.7,‫^(א‬3،03،ij‫ )دא‬J!K‫ אˆ!¦ن‬JO‫א‬U
.gN3KP\‫א‬X‫אو‬
default ‫'د‬%‫ و‬F‫ א‬U f I9‫ א‬03 5P‫ و‬OverRidding ‫ אل‬4D AIC 7Q1 ‫ ذ‬KFD 5P>
.Implementation
Encapsulation
.7
YD‫ א‬5D J! I‫א‬$‫ א‬KbO‫ א‬zOI‫‘„ א‬HVI :, ˆ W‫ وא‬Encapsulation ‫ אل‬C$3 f$gQ
53‹‫و‬،VIŠ‫و‬،‫زن‬+\‫א‬iH‫دא‬9‫(م‬5FMQ¶)‫ض(م‬ZON$Q$, HVI،Y4\‫א‬.
.h\‫ א‬K%‫א‬
‫وאل‬$‫ א‬53 ‫د‬$) ‫د‬$D (N‫ א‬lWS 53 $‫ وא‬KP ‫'ن‬P Encapsulation ‫ אل‬C$3 ¤'D$Q L‫ א‬lWS U
${ h\‫مא‬P(Uً ^F!،k I53Kb‫(א^ ‹א'א‬N5P>t‫(موא‬N‫אא‬WS 53‫'لوאœوج‬I$
.‫وאل‬$‫א‬53 ‫ ًא‬$%i‫ود‬$)D'FU‡‫א‬...(VI)(hQZT3!s‫()א‬h3FD!s‫)א‬
$]‫وא‬h‫א‬i$D.!5FMQ،3‫אوא‬53ً‫א‬H'G1h3FD !s‫א‬K^3FD‫(€אن‬9'ً
gF{”،h‫ א‬i$D.U2N‫א‬5Q§‹53‫و‬FP‫'دא‬%‫و‬53$]‫وא‬RRbI$\‫א‬h‫אن א‬53
53ً9$:3‫א‬$+‫م‘„א‬$+\‫א‬hg%‫وא‬4 ‫'م‬7QW‫א‬Iš‫א‬3‫'مز‬7Q$‫وא‬3CKP,nDQgN‫א‬U
.NO‫א‬KbO‫א‬lWSKU‫'ص‬q‫א‬
¤‫'د‬gOً‫א‬1M3‫א'ن‬5،ً9‫אو‬hD'FU KFt‫صא‬+,‫'عא‬s'\‫אא‬WS$OQ،€(9F
:Q3CK‫م‬SKP,nDًFFV3‫'ن‬P‫'د‬P‫אنא‬F،3K3‫ א‬ofD‫אنא‬cOPQ‫و‬K3P
148
53 ‫ ^
ًא‬K7Q 3 'S‫م و‬k‫س א‬CH „‘ ‫'ل‬b' a7! ‫ ًא‬H‫د‬. 234\‫ א‬3‫'ن ز‬P 5P ، 3‫ אوא‬53 D'F
.5QIš‫א‬Y4\‫ א‬53]1œ‫ˆא‬Q5Dg‫א‬53bœ‫
אא‬q3FdF،z1I‫א‬
‫ط‬7N‫א‬53$Q$‫א‬¤NS‫'م‬gO\‫אא‬WSˆ1‫و‬، OOP hqK:b' ‫ولאن‬W‫'مא‬gO\‫אא‬WS
.‫س‬H$‫אא‬WSUk‫ق‬1N t‫א‬
ً ^3nN}...‫م‬$+\‫'א‬SIŠ2343¤NS‫و‬2343CNS‫ذ‬UgM‫אن‬$9 17‫ول‬C،Kb‫אن'א‬K.
.‫وع‬T\‫א‬53z`JO‫א‬WS‫אم‬$+234\‫א‬3‫'مز‬7Q‫و‬J!4‫'م‬7 ‫א‬
private ‫ ﻟﻠﻮﺻﻮل إﻟﻰ ﻣﺘﻐﻴﺮات‬public ‫اﺳﺘﺨﺪام دوال‬
.7.1
:7‫وسא‬H$‫א‬A'3nDh‫א‬3i$DlzTNF.W‫ א‬Person ‫'صאل‬Vx ‫ضא\^لא‬ZON
C#
class Person
{
public int Salary;
}
‫ﻛﻮد‬
VB
Class Person
‫ﻛﻮد‬
Public Salary As Integer
End Class
:‫א‬FŽ‫א‬P‫م‬.−'gQ953K%‫و‬−Th‫ل ™א‬I‫ˆאœصد‬QO‫א‬UQ‫א‬3‫و–نز‬
C#
Person Ahmed = new Person();
Ahmed.Age = 999999999999;
‫ﻛﻮد‬
VB
Dim Ahmed As New Person()
Ahmed.Age = 999999999999
‫ﻛﻮد‬
149
a‫وא‬،0.‫'א‬X.‫א‬z,‫א‬UPT\‫א‬lWk‫ض‬$.NNP،KR3:,$Q`L‫א א‬Wg.HU'g‫و'אنא‬
K^3‫!¦ن‬-
@— - ‫م‬$+3‫'د‬%‫و‬U‫و‬،i,3g
‫م‬$+\‫א‬53F7‫א‬iz‫א‬7‫'م‬7Q:‫ذ'א‬53
.ً ً‫א‬3C$h I$\‫ א‬lWS
}H ‫ل‬I‫د‬9‫א‬h,,23433‫אنز‬F، gF€F.W‫ א‬JOK%‫א‬H3$‫א‬G KI$\‫אא‬WSً
H'g(‫ א‬53 ‫
א‬q3 0N3‫ א‬، Fj‫א‬$‫ א‬RVN‫א ] א‬W ، ‫ل‬I‫د‬9‫ א‬53 ˆ7R‫ א‬3‫ א‬zND :O oPQ 5
:‫א‬KPTg‘P‫ אوא‬gz‫א‬7‫دوאل‬gN3ً9$0s‫و‬−Iš‫א‬234\‫א‬−g3$+\
C#
class person
{
private int Age;
public string SetAge(int x)
{
if(x>100 || x<1)
return "you can't edit age like that";
‫ﻛﻮد‬
Age=x;
return "done";
}
public int GetAge()
{
return Age;
}
}
VB
Class person
Private Age As Integer
Public Function SetAge(ByVal x As Integer) As String
If x > 100 OrElse x < 1 Then
Return "you can't edit age like that"
End If Age = x
Return "done" End Function Public Function GetAge() As Integer
Return Age
End Function
End Class
‫ﻛﻮد‬
150
‫ وذ‬− ً ^3 ‫ א‬KPT‫ א‬WI] ‫ אن‬qNQ Set ‫ دא‬، ً 7 N7O‫ א‬F 1I'S x h‫
א‬q\‫ א‬F ً 
:−ˆ‫سא‬H$‫א‬U Me ‫و‬C this *jVI53NFF
C#
public string SetAge(int Age)
{
if(Age>100 || Age<1)
return "you can't edit age like that";
‫ﻛﻮد‬
this.Age=Age;
return "done";
}
VB
Public Function SetAge(ByVal Age As Integer) As String
If Age > 100 OrElse Age < 1 Then
Return "you can't edit age like that"
End If
‫ﻛﻮد‬
Me.Age = Age
Return "done"
End Function
zNq9‫ א‬5P>9Q'ً7$Q$Ž‫א‬0QHT\‫א‬UH'3‫א‬lWSK^3:NP،ً Q' ‫Ÿ ًאو‬3‫وא‬$Q}H
.a]1IGYQ 3i$DoPQ‫وع‬T\‫'ط‬7UG$.ggND
‫ﻣﻼﺣﻈﺔ‬
. Mutator ‫ فتسمى باسم‬SetAge ‫ أما الدالة‬Accessor ‫ يطلق عليھا اسم‬GetAge ‫الدالة‬
: Constructor ‫ارﺳﺎل اﻟﻘﻴﻢ ﻛﺠﺰء ﻣﻦ ال‬
.7.2
h‫א‬Z3H QF‫م‬$+FbO‫אא‬S‫و‬،7‫א‬7Q1‫א‬03‫אو‬KQ$g3‫א‬$+‫ א‬NP>AIC7Q
„‘„‫אو‬7Q1‫אمא‬$+‫א‬Dً3‫'ن א‬Pi
P‫ א‬hJO‫א‬U، Constructor $T\‫א‬5Fsh‫
א‬q\‫א‬.
151
‫אل‬53 Object zT‫(א‬Lh‫
א‬q\‫א‬K.QF‫'م‬7Q‫م‬$+\‫ א‬H'V5‫א‬7Q1‫א‬lWSG%
.Class
:7Q1‫א‬lWS‫^ل‬3
C#
class Person
{
private int Age;
public Person(int Age)
{
if(Age>100 || Age<1)
return "you can't edit age like that";
‫ﻛﻮد‬
this.Age=Age;
return "done";
}
}
VB
Class Person
Private Age As Integer
Public Sub New(ByVal Age As Integer)
If Age > 100 OrElse Age < 1 Then
Return "you can't edit age like that"
End If
Me.Age = Age
Return "done"
End Sub
End Class
‫ﻛﻮد‬
152
: Type Property ‫اﺳﺘﺨﺪام ال‬
.7.3
‫ و‬: Set ‫دאن‬gN3KPbI„‘
q\‫א‬KQ'nDً‫دא‬FD‫وא‬AI‫א‬7Q1 5P‫و‬،7‫א‬7Q1‫@א‬ON
:‫א‬KPT‫ذ‬Q ،Get
C#
class Person
{
public int Age
{
get { return Age;}
set
{
if (!(value>100 || value<1))
Age=value;
}
}
}
‫ﻛﻮد‬
VB
Class Person
‫ﻛﻮد‬
public Property Age() As Integer
Get
Return Age
End Get
Set
If Not (value > 100 OrElse value < 1) Then
Age = value
End If
End Set
End Property
End Class
z,G U‫و‬، Set zD$‫א‬z,‫ˆא‬1K.5P‫و‬، Age „‘,\‫'لא‬b'‫א‬NP> ‫وאšن‬
hFDnDhF‫ ™א‬KFD‫لאو‬I‫د‬9‫א‬h53$]‫א‬Q3'S‫و‬، Get 53:D‫'ل‬VL‫א‬
‫אج‬I9‫א‬
S Age lF\‫(א‬L‫א‬lWSU
q\‫)و@א‬bœ‫نא‬9 public FS Get ‫ و‬Set ‫ن‬CًMQ‫(€ א‬9
153
،i$nD Get ‫ אو‬Set X‫'لאœص‬b'‫א‬f3UKQ$‫א‬P3b‫ א‬.net 2.0 WN35P‫و‬، public
:ً ^3‫א‬KPT
C#
public int Age
{
get { return Age; }
protected set { Age = value; }
}
‫ﻛﻮد‬
VB
Public Property Age() As Integer
‫ﻛﻮد‬
Get
Return Age
End Get
Protected Set
Age = value
End Set
End Property
KF @P‫ א‬h‫د‬H‫ ' א‬3C ، Set bœ‫ אزא א‬NPF! Read Only Property KFD U G— €N ‫‘ذא‬
: Read Only Property‫אא\^لل‬WS، Get bœ‫!]زلא‬Write Only Property
C#
public int Age
{
get { return Age; }
}
‫ﻛﻮد‬
VB
Public ReadOnly Property Age() As Integer
Get
Return Age
End Get
End Property
‫ﻛﻮد‬
154
Inheritance ‫اﻟﻮراﺛﺔ‬
.8
‫وس‬H‫د‬U Encapsulation ‫'مאول‬gO\‫ א‬vTNF.،‫א‬bNDE ‹k OOP ‫سˆאن‬H‫د‬U‫ذ‬
. Inheritance ‫אل‬03$D'3‫وאšن‬،7
:‫אœص‬lN, W‫ضא\^لאˆא‬ZON،KF‫א‬:30‫^ل‬3KFC$N‫אšن‬
C#
class Car
{
private string carName;
private int carModel;
public Car(string carName, int carNumber)
{
this.carNme=carName;
this.carNumber=carNumber;
}
public Car()
{
carName="Unknown";
carNumber=0;
}
}
‫ﻛﻮد‬
VB
Class Car
‫ﻛﻮد‬
Private carName As String
Private carModel As Integer
Public Sub New(ByVal carName As String, ByVal carNumber As Integer)
Me.carNme = carName
Me.carNumber = carNumber
End Sub
Public Sub New()
carName = "Unknown"
carNumber = 0
End Sub End Class
.‫س‬H$‫אא‬WSK‫א‬3‫ ل‬I:N‫و‬lQ'1nD KF‫א‬0‫و‬،a‫אא\^لא‬WgC$N
155
is-a :‫ﺗﻌﺮﻳﻒ ﻋﻼﻗﺔ‬
.8.1
‫'عאول‬N‫א‬v,‫ولאšن‬RN،has-a‫'ن‬P$.‫ و‬is-a ‫'ن‬P$.. ‫!¦ن א‬،TD0‫سא‬H$‫א‬U‫ذ‬F
: BMW iH‫ض‬ZON،j‫א‬JO‫'عא‬53'S7T\‫א‬JO‫אنא‬cQW‫ وא‬h. ‫א‬53
C#
class BMW: Car
{
}
‫ﻛﻮد‬
VB
Class BMW
Inherits Car
‫ﻛﻮد‬
End Class
@O‫ و‬Car X‫ א‬ClassJO‫*א‬jVI@OnD'd BMW 59‫ א‬ClassJO‫'لאنא‬7‫אن‬01‫א‬WPS
carName bœ‫‘„א‬,\‫'لא‬b'‫‰ولא‬59‫א‬JO‫א‬UN‫ض א‬ZON5P‫و‬،a7! public ‫אل‬:.‫و‬:‫دوא‬
:17N‫א‬lWSs'Q‫אא\^ل‬WS ،‫ذ‬535PF5!
C#
BMW ahmedcar=new BMW();
ahmedcar.carName="anyname";
‫ﻛﻮد‬
VB
Dim ahmedcar As New BMW()
ahmedcar.carName = "anyname"
‫ﻛﻮد‬
N‫ضא‬ZON،bœ‫א‬lWS„‘‫'ل‬b'‫א‬01r 7T\‫ א‬JO‫א‬KI‫وאلدא‬$‫™ א‬oQNF.'n
:‫א‬KPT‫'ن‬P BMW JO‫—א‬b $D‫א‬
C#
class BMW: Car
{
public changeCarName(string value)
{
‫ﻛﻮد‬
156
carName=value;
}
}
VB
Class BMW
Inherits Car
Public Sub New(ByVal value As String)
carName = value
End Sub
End Class
‫ﻛﻮد‬
‫'ل‬b'‫א‬f3‫אن‬oTP‫'ل‬b'‫א‬h!3‫س‬H‫'ع‘„د‬% ‫א‬،ً3eًRRb‫א‬WS‫'ن‬PQ5o :‫ א‬protected ‫'ل‬b'‫ א‬f3 ‫م‬$+ ‫א‬WS K%‫ א‬53 ، 7T\‫ א‬JO‫ א‬53 : ‫'ل‬b'‫ א‬5P> 9 private
‫'ل‬b'‫ א‬5P>K7\‫א‬U:NP، object ‫ لאل‬I53:,\‫'لא‬b'‫א‬5P>9:'U private ‫אل‬:TQ
: ‫א‬KPT Car JO‫^لא‬3NsZ!‫'א‬،7T\‫א‬JO‫א‬KI‫دא‬53:‘
C#
class Car
{
protected string carName;
protected int carModel;
}
‫ﻛﻮد‬
VB
Class Car
Protected carName As String
Protected carModel As Integer
End Class
‫ﻛﻮد‬
‫'ن‬PQ f' ‫א‬W ، h‫
א‬q\‫ א‬lWS iz‫א‬7 ‫'م‬7 BMW 7T\‫ א‬JO‫ א‬KI‫ دא دא‬oQ NNP> L‫ א‬lWS U
:ًRRb‫'دא‬P‫א‬
C#
class BMW: Car{
public changeCarName(string value)
{
carName=value;
}
}
‫ﻛﻮد‬
157
VB
Class BMW
Inherits Car
Public Sub New(ByVal value As String)
carName = value
End Sub
End Class
‫ﻛﻮد‬
NotInheritable - sealed ‫اﻟﻜﻠﻤﺔ اﻟﻤﺤﺠﻮزة‬
.8.2
:‫א‬KPT‫ذ‬Q،:N3‫ق‬7,9‫א‬5P>9JO‫א א‬WS‫אن‬FP‫א‬lWS‫אم‬$+‫א‬cQ
C#
sealed class Car
{
‫ﻛﻮد‬
}
VB
NotInheritable Class Car
‫ﻛﻮد‬
End Class
‫ﻣﻼﺣﻈﺔ‬
C# ‫ في‬sealed ‫ تقابل‬NotInheritable ‫الكلمة‬
‫اﻟﻮراﺛﺔ اﻟﻤﺘﻌﺪدة‬
.8.3
nN3، managed c++ a7!:71 YU،i‫د‬$\‫א‹א‬H'‫ א‬C$3 VB.net ‫אوאل‬XH,‫א‬q!'9
U،iH J!‫و‬N, J!NQ$‫ض‬ZON، J!53^‫ א‬53ˆT‫אن‬3J!‫ن‬P3‫אن‬i‫د‬$\‫א‹א‬H'‫א‬F
5P‫ و‬،Q‫אد‬iH‫وא‬NT‫*א‬jVInD'd$Q$%‫'ع‬KFD01N¦!i‫د‬$\‫א‹ א‬H'3qD‫د‬
VB.net .‫אوאل‬XH,‫א‬53Kl!'93‫א‬WS
158
FN:DfN3'S‫و‬، interface 53^9 Implementation KFD‫ند‬q‫مא‬$7،WKQ$‫و‬
.zŽ‫אא‬WS„‘KV
:s'a‫אאא‬WS¦!، VB.net ‫ و‬C# Ui‫د‬$\‫א‹א‬H'‫א‬D‫و'!€د‬PQ3‫م‬$7_‫\ذא‬3C
‫رابط‬
http://blogs.msdn.com/csharpfaq/archive/2004/03/07/85562.aspx
‫اﻟﺘﻌﺪﻳﻞ ﻓﻲ اﻟﻔﺌﺎت اﻟﻤﺸﺘﻘﺔ‬
.8.4
U، i$Q$Ž‫ א‬JO‫ودوאلא‬E‫א‬$C‫*وقو‬jVInDi,3KQ$‫א‬NNP> ،7‫وسא‬H$‫א‬UNQCHF
‫د‬$DnD' BMW JOi$Q$%bI!s‫א‬NNP>،9‫
א‬qNF‫!دא‬sNF.ˆ‫א\^ل א‬
...‫א‬WPS‫و‬، BMW‫'ع‬53h‫א‬H‫א‬U!s‫א‬iFiH‫א‬KI‫'ندא‬QO‫א‬ig%C
' 5P . ¤RF Ž‫ א‬hRO‫د א‬$D !s‫ א‬NNP> L‫ א‬lWS U ، H‫ !
א‬AIC J! KFD NNP>
Car 9‫ א‬JO‫ א‬U g!s‫ א‬OP! h‫א‬H‫ א‬0FŽ maxSpeedbI oQ „‫ א‬3 U N`‫א‬
.ً BzN‫א‬hJO‫א‬Uًj7i‫'د‬%'3S$`‫و‬
،gT\‫א‬bN3Di$D.0s‫و‬S ‹‫א‬H'‫א‬Fj‫א‬$j‫'א‬O‫א‬53i$‫אنوא‬ª ‫אن‬01NS53
Uً‫ق
א‬O‫א‬${5}H،h‫א‬3i$DgN3KH‫א‬Pi‫د‬D‫ א‬53ً9$a7!f I9‫طא‬7!s9¢KFD‫و‬
03 K3 3‫ אوא‬i$D 03 77 ‫^ل‬3 U 5P‫ و‬، a7! *jVI 4 ‫ אو‬3 03 KF N‫א\^ل אˆ א‬
Y ‫ق‬HO‫ א‬¤H$ ‫ אن‬01 L‫ א‬hF‫ وאض وא‬D1‫ وא‬h‫ א‬i$D. U ªOR‫م و‬$+\‫א‬
.:3$D‫א‹و‬H'‫'مא‬gO3‫אم‬$+‫א‬
has-a ‫اﻟﻌﻼﻗﺔ ﻣﻦ ﻧﻮع‬
.8.5
JO‫אنא‬cQ‫'ع‬N‫אא‬WS،O+\‫א‬hJO‫א‬Y h. ‫א‬53^‫'ع א‬N‫'א‬S‫א‬Wg!NH‫אولد‬UNRs‫אو‬F
:‫א‬KPTh `‫א‬J!‫^ل‬3NsZ!‫'א‬،AIC J!nD'
159
C#
class Tires
{
int TiresType;
int TiresSize;
}
‫ﻛﻮد‬
VB
Class Tires
Private TiresType As Integer
Private TiresSize As Integer
End Class
‫ﻛﻮد‬
‫א‬W، car has a tire iH‫א‬53z%gNP‫ و‬tire is not a car iH‫'ع‬53€h‫א‬H9‫אنא‬N7Qf
: ‫א‬KPTiH‫ א‬J!oQNNP>
C#
class Car
{
Tires carTires=new Tires();
}
‫ﻛﻮد‬
VB
Class Car
Private carTires As New Tires()
End Class
‫ﻛﻮد‬
‫ﻣﻼﺣﻈﺔ‬
‫ وعمل خاصية لھا من اجل القراءة والكتابة‬protected ‫ او‬private ‫ال تنس ان بامكانك تعريفھا كـ‬
‫إليھا‬
Casting ‫اﻟﺘﺤﻮﻳﻼت‬
.8.6
.ˆ‫س‬H‫د‬U:D‫وא'א‬:‫'مאم‬gO\‫א‬v,”،IŠ„‘‫ 'ع‬53KQ'R‫'א‬Sً3'FD Casting ‫ل‬$V7Q
،Q‫( אد‬cast) ‫אم‬$+‫א‬SKQ'R „‫אو‬7Q1‫א‬، Classes ‫אل‬nDSO\‫@א‬Oˆ1‫ول‬RN‫وאšن‬
: BMW iHoQNF.'ً ^3
160
C#
BMW ahmedCar=new BMW();
‫ﻛﻮد‬
VB
Dim ahmedCar As New BMW()
‫ﻛﻮد‬
‫‘„دא‬kHNF.'ًMQ‫א‬،RRbiH'VKFf'! BMW ‫ل‬7‫'م‬7‫
‘„ دא‬q\‫لא‬HNF.‫و‬
RRb€ P‫א‬F‫א‬FN، Car 77L‫א‬US BMW K‫–ن‬RRb‫א‬WS‫'ن‬P! Car K7
:‫א‬iH'V BMW oQNF.'^‫א‬17N‫א‬
C#
Car ahmedCar=new BMW();
‫ﻛﻮد‬
VB
Dim ahmedCar As Car = New BMW()
‫ﻛﻮد‬
„‘ i,3 q\‫ل א‬H‫ א‬5P> ‫ وאšن‬، implicit cast nD$Q 3 'S‫ ! ً و‬Rb ‫'ع‬s'\‫א א‬WS
. Car K7t‫אא‬$‫א‬
:‫א‬KPT BMW oQ:! NF.IŠً9^3‫ض‬ZON
C#
Object ahmedCar=new BMW();
‫ﻛﻮد‬
VB
Dim ahmedCar As Object = New BMW()
‫ﻛﻮد‬
f'! Car K7t‫אא‬$‫
‘„א‬q\‫لא‬HNF.'5P،ًMQ‫ א‬Object 'S J!K‫ً –ن‬MQ‫א‬Rb‫א‬WS
:‫لא‬P,9‫א‬$] cast KF‫'م‬7‫א‬W،1IHg(
C#
functionname((Car)ahmedCar);
functionname((BMW)ahmedCar);
‫ﻛﻮد‬
161
VB
functionname(DirectCast(ahmedCar, Car))
functionname(DirectCast(ahmedCar, BMW))
‫ﻛﻮد‬
is ‫اﻟﻜﻠﻤﺔ اﻟﻤﺤﺠﻮزة‬
.8.7
: ‫^ل‬3،^‫א‬f1‫א‬53'S‫ول‬9‫א‬f1‫‘ذאن א‬F!HIFP‫א‬lWS‫'م‬7
C#
if (ahmedCar is BMW)
{
‫ﻛﻮد‬
}
VB
If TypeOf ahmedCar Is BMW Then
‫ﻛﻮد‬
End If
‫‘ذא‬F!f‫אن‬$Q‫و‬،JO‫@א‬O537T3‫א'ع‬i$D53h‫
א‬q3i$D‫'د‬%‫ و‬UFP‫א‬lWS¤$O
.ً ^3H‫ אو!
א‬BMW ‫'ع‬53€
Visual Studio Class Diagram
.8.8
:gD‫^ل‬3‫א‬WS، Class Diagram ‫ אل‬KFi‫אدא‬2005H‫א‬$b9‫א‬53z‫א‬$‫'א‬Q‫`'אل'د‬O‫'!א‬Q
162
، Q$ t‫ א‬h‫א‬JO‫ض א‬D ‫ אو‬، i,3 gD KF‫ ‹ א‬53‫ و‬، new - class diagram 53 g!s‫ א‬NP>
. mode‫אאل‬WSUO+\‫א‬h. ‫א‬zT‫א‬NP>
Polymorphism ‫اﻟـ‬
.9
‫ اﻵن ﺳﻨﺘﻌﺮف ﻋﻠﻴﻪ‬، ‫ ﺑﺸﻜﻞ ﻋﺎم‬polymorphism ‫ﺗﻌﺮﻓﻨﺎ ﻓﻲ درس ﺳﺎﺑﻖ ﻋﻠﻰ ﻣﻌﻨﻰ ال‬
... ‫ﻼ‬
ً ‫ﺑﺼﻮرة أﻛﺜﺮ ﺗﻔﺼﻴ‬
5P‫ً'دو‬MQ‫'!א‬Q ، implementation ‫ونא‬$ class oQFQW‫وא‬s\‫א‬oQ‫א‬
fQ 3 'S‫ و‬، AI‫ وא‬JO‫ א‬Y ‫א‬$ ‫ אœص‬implementation‫
אل‬q FQ K7\‫ א‬U
.Overriding
‫אن‬K.iH7\‫א\!א‬Xrbœ‫אא א‬$‫'دא‬%‫و‬NsZ!‫'א‬،N‫אœص‬iH‫^لא‬3‫ض‬ZON
.Z3'10KPً'%fV(ً ^3) iH‫وאنא‬،5QN‫א‬$ONQ
C#
public int calc(int fuel)
{
return fuel * 10;
}
‫ﻛﻮد‬
163
VB
Public Function calc(ByVal fuel As Integer) As Integer
‫ﻛﻮد‬
Return fuel * 10
End Function
5KPً'%fVg‫‘ذא‬،i$D7‫@א‬OnD
9iH‫א‬lWS ‫אن‬NOT‫ א‬BMW iHNFD$5P‫و‬
fQ 3'S‫א‬WS، 7T\‫ א‬JO‫א‬U calc ‫א‬$‫א‬oQi‫د‬D‫‘„א‬%r 5‰L‫א‬lWSU ،a7!h‫א‬Z3'
‫א‬$‫ א‬oQ ˆQ 5D ‫ ذ‬Q . polymorphism ‫د¨ אل‬3 $‫' א‬S‫ و‬Overriding i‫د‬7‫ א‬i‫د‬D‫ א‬
:‫א‬KPT virtual ‫'ع‬53 base class ‫אل‬U9‫א‬
C#
public virtual int calc(int fuel)
{
return fuel * 10;
}
‫ﻛﻮد‬
VB
Public Overridable Function calc(ByVal fuel As Integer) As Integer
Return fuel * 10
End Function
‫ﻛﻮد‬
‫م‬$D5P>F، 7T\‫ א‬JO‫א‬UgOQi‫د‬D‫א‬5P>‫א‬$‫א‬lWS ‫אن‬c overriddeable ‫ אوאل‬virtual ‫אل‬
:7T\‫א‬JO‫א‬U‫'دא‬P‫א‬GPgOQi‫د‬D9 ،ًMQ‫א‬gOQ
C#
public override int calc(int fuel)
{
return fuel * 5;
}
‫ﻛﻮد‬
VB
Public Overloads Overrides Function calc(ByVal fuel As Integer) As Integer
Return fuel * 5
End Function
‫ﻛﻮد‬
164
f،zN‫ א‬hJO‫א‬U g4.‹53‫ و‬j‫ א‬JO‫א‬Uً—H! implementation ‫אل‬¤NP>ًMQC
U:D fNW‫ א‬interface ‫'—
אل‬S‫ و‬Abstract class implementation ‫אل‬53‫غ‬HO‫ א‬JO‫א‬
.3‫د‬.3
Abstract ‫اﻟـ‬
.10
‫ون‬$ Q‫د‬D J! ‫ د‬g‫ א‬N!D‫ و‬، Abstract Class F nN3 nD N! ˆ‫س א‬H$‫ א‬U
i‫ א[`'ز‬FP‫م א‬$+ ، :3‫א‬$+‫ א‬K. :N3 + KFD nD NO‫ א‬4< P 5P ، implementation
:‫א‬KPT:OQabstract
C#
abstract partial class Car
{
}
‫ﻛﻮد‬
VB
MustInherit Partial Class Car
‫ﻛﻮد‬
End Class
‫ﻣﻼﺣﻈﺔ‬
C# ‫ في‬abstract ‫ ھي مناظر كلمة‬vb.net ‫ في‬MustInherit ‫الكلمة المحجوزة‬
:]1IoQ‫אא‬WSN1Qf' L‫א‬lWSU
C#
Car ahmedCar=new Car();
‫ﻛﻮد‬
VB
Dim ahmedCar As Car=new Car()
‫ﻛﻮد‬
165
Abstract method
.10.1
JO‫ א‬U k overriding KF ‫'م‬7 KP virtual ‫وאل‬$‫ א‬oQ ‫'م‬7 N‫ ً א‬MQ‫س אˆ א‬H$‫ א‬U ‫ذ‬
234\‫א‬H%‫دא‬H‫'א‬5P،:S{‫אو‬g‫'دאœص‬P‫ א‬i‫د‬D‫א‬UˆL‫א‬N1Q3‫א‬WS‫و‬،ً79 7T\‫א‬
:‫א‬KPT Abstract method oQW‫'م‬7overridingi‫د‬7‫א‬i‫د‬D‫א‬nD
C#
public abstract int calc(int fuel);
‫ﻛﻮد‬
VB
Public MustOverride Function calc(ByVal fuel As Integer) As Integer
‫ﻛﻮد‬
166
‫‪167‬‬
‫اﻟﺒﺎب‬
‫‬
‫‪9‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫اﻟﻮاﺟﻬﺎت ‪Interfaces‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
168
169
Interface ‫ﺗﻌﺮﻳﻒ ال‬
.1
+KFD5P> abstract methods and membersnD'd abstract class 'S interface ‫אل‬
^9 implement KFDP3FQ F، inheritance 53ً9$ implementation ‫'م‬gO}‫אم‬$+:N3
. multiple inheritance ‫'م‬gO3 5DKQ$‫'א‬S‫و‬i$‫א'א‬i\‫א‬U interface 53
:ً ^3‫א‬KPT interface oQ5P>
C#
public interface ICar
{
int carMaxSpeed{get;set;}
void AddItem(string Item);
}
‫ﻛﻮد‬
VB
Public Interface ICar
Property carMaxSpeed() As Integer
Sub AddItem(ByVal Item As String)
‫ﻛﻮد‬
End Interface
:ً ^3‫א‬KPTIŠ53 interface ‫ق‬7,‫א‬P3‫אن‬nN9
C#
public interface ICar:IDisposable
{
int carMaxSpeed{get;set;}
void AddItem(string Item);
}
‫ﻛﻮد‬
VB
Public Interface ICar
Inherits IDisposable
Property carMaxSpeed() As Integer
Sub AddItem(ByVal Item As String) End Interface
‫ﻛﻮد‬
:‫'دא‬P‫א‬P ‫'م‬7 interface 9 implements KF‫و‬
170
C#
public class BMW : Car
{
‫ﻛﻮد‬
}
public class BMW2 : Car, Truck
{
}
VB
Public Class BMW
Implements Car
‫ﻛﻮد‬
End Class
Public Class BMW2
Implements Car, Truck
End Class
.ً .WNF.FJO‫אمא‬$+‫‹א‬53‫و‬،i$Q$%‫!دوאل‬s‫ א‬. i‫'د‬%'\‫وאلא‬$‫א‬i‫د‬D‫א‬NP>‫אšن‬
: ‫ﻫﺬه ﺑﻌﺾ اﻟﻨﻘﺎط اﻟﺘﻲ ﻻ ﻳﻤﻜﻨﻚ ﻋﻤﻠﻬﺎ ﻣﻊ اﻟﻮاﺟﻬﺎت‬
:JIFŽ‫א‬lWSK^F!‫א‬W، :N3 Object ‫א‬KFD5P> 9 Interface ‫אل‬،Q‫א‬$
C#
ICar x=new ICar();
‫ﻛﻮد‬
VB
Dim x As New ICar()
‫ﻛﻮد‬
:JI interface ‫אل‬KI‫دא‬FŽ‫א‬lWSK^3‫א‬W، interface ‫ אل‬U‫د‬D
q3oQ5P>9
C#
int number;
‫ﻛﻮد‬
171
VB
Dim number as integer
‫ﻛﻮد‬
:‫א‬KPT get ‫ و‬set bIKFD'S،KQ$‫א‬
C#
int x {set;get;}
‫ﻛﻮد‬
VB
Private Property x() As Integer
Get
End Get
Set
End Set
End Property
‫ﻛﻮد‬
. interface ‫אل‬KI‫'د دא‬1CNP>901
. interface K constructor KFD5P>9F
Name Clashes
.2
:TU KT3E$d}H‫و‬، interface 53^9 implements KF3 struct ‫ אو‬class ‫'م‬7Q3 ً ‫א‬
:‫ضא\^لא‬ZON،zƒ‫א‬
C#
public interface ICar
{
void move();
}
public interface ITruck
{
void move();
}
public class BMW: ITruck, ICar
{
}
‫ﻛﻮد‬
172
VB
Public Interface ICar
Sub move()
End Interface
Public Interface ITruck
Sub move()
End Interface
Public Class BMW
Implements ITruck
Implements ICar
End Class
‫ﻛﻮد‬
: BMW i$Q$Ž‫א‬JO‫א‬U move ‫א‬$ implementation KF€F.'F!PT3${5}H
C#
public class BMW: ITruck, ICar
{
void move()
{
// do something.
}
}
‫ﻛﻮد‬
VB
Public Class BMW
Implements ITruck
Implements ICar
‫ﻛﻮد‬
Private Sub move()
' do something.
End Sub
End Class
‫'م‬7، truck 53 move ‫א‬$AI‫ وא‬car 53 move ‫א‬$ implementation KFDh‫د‬HC'‫ذא‬35P‫و‬
:‫א‬KPTW
173
C#
public class BMW: ITruck, ICar
{
void ICar.move()
{
// do something.
}
void ITruck.move()
{
// do something.
}
}
‫ﻛﻮد‬
VB
Public Class BMW
Implements ITruck
Implements ICar
Private Sub move() Implements ICar.move
' do something.
End Sub
Private Sub move() Implements ITruck.move
' do something.
End Sub
End Class
‫ﻛﻮد‬
:‫א‬KPTSzD$‫א‬QY‫א‬$‫א‬53i$‫א وא‬$Q$5P>، BMW JO‫א‬53 object KFD$‫و‬
C#
BMW ahmedCar=new BMW();
ICar temp= (ICar)ahmedCar;
temp.move();
‫ﻛﻮد‬
VB
Dim ahmedCar As New BMW()
Dim temp As ICar = DirectCast(ahmedCar, ICar)
temp.move()
‫ﻛﻮد‬
174
IEnumerable interface
.3
‫'م‬7Q Class‫و‬CJ!KFDO5D3‫د‬. ‫وس‬H‫د‬E ^‫ضאšنو‬N، interfaces ‫אل‬03N‫و‬H‫אšند‬Kb‫'א‬
3‫ و‬IEnumerable nF\‫ א‬interface XC$N‫س‬H$‫א א‬WSU،Y3 interface K implement KF
.‫ذ‬z‫א‬H‫و‬i'%\‫א‬i$jO‫א‬S
‫ﻣﻼﺣﻈﺔ‬
‫ فھذا واحد من الدروس التي ستالحقنا كثيراً أثناء تطبيق‬، ‫أرجو منك أن تركز جيداً في ھذا الدرس‬
. Linq ‫مبادئ‬
: ‫א‬KPThi$DnD 'zƒC!'OV3J!NQ$‫ضאن‬ZON
C#
string[] users = { "Ahmed", "Mohammed" };
‫ﻛﻮد‬
VB
Dim users As String() = {"Ahmed", "Mohammed"}
‫ﻛﻮد‬
:ً 7NFFfor – each‫אم‬$+‫'دא‬P‫مא‬$+N!'OV\‫א‬hQ')iz‫א‬7‫وאšن‬
C#
foreach (string us in users)
{
Console.WriteLine(us);
}
‫ﻛﻮد‬
VB
For Each us As String In users
Console.WriteLine(us)
Next
‫ﻛﻮد‬
ًD' ‫ א\^ل‬0' ‫'م‬7N ،bN‫ ! א‬nD ‫אن‬H‫و‬$ ‫م دא‬$+ N‫ א‬${ ، array nD $F N' ‫א‬WS
:‫א‬KPTYO&'\‫א‬J!‫ض‬ZON،J!nD‫د‬FD9 ‫'نذ‬P
175
C#
public class employee
{
int emp_number;
string emp_name;
}
‫ﻛﻮد‬
VB
Public Class employee
Private emp_number As Integer
Private emp_name As String
End Class
‫ﻛﻮد‬
53 D'F 5D iHD 'S ‫م‬$+\‫ אن א‬، Y3$+\‫ א‬h nD 'd AIC J! NQ$ 5P‫و‬
:ً ^3‫א‬KPT YO&'\‫א‬
C#
public class users
{
employee[] emp = new employee[3];
users()
{
emp[0] = new employee(10, "Ahmed");
emp[1] = new employee(20, "Khaled");
emp[2] = new employee(30, "Ali");
}
}
‫ﻛﻮد‬
VB
Public Class users
Private emp As employee() = New employee(2) {}
Private Sub New()
emp(0) = New employee(10, "Ahmed")
emp(1) = New employee(20, "Khaled")
emp(2) = New employee(30, "Ali")
End Sub
End Class
‫ﻛﻮد‬
:B‫אم‬$+ًMQ‫ א‬for each ‫אم‬$+ ً MQ‫א‬YO&'\‫אאضא‬NNP>
176
C#
foreach (employee e in emp)
{
}
‫ﻛﻮد‬
VB
For Each e As employee In emp
‫ﻛﻮد‬
Next
. IEnumerable ‫אل‬03:‘nNW‫א‬C$\‫'א‬S‫א‬WS ،Y3VNDD loop K03
: IEnumerable nF\‫ א‬interface K9‫א‬KPT‫א‬
C#
public interface IEnumerable
{
IEnumerator GetEnumerator();
}
‫ﻛﻮد‬
VB
Public Interface IEnumerable
Function GetEnumerator() As IEnumerator
End Interface
‫ﻛﻮد‬
:‫א‬KPT IEnumerator ‫'ع‬53interfaceg%‫وא‬oQ ‫'م‬7Q،ˆ‫א\^لא‬UAF‫و‬
C#
public interface IEnumerator
{
bool MoveNext ();
object Current { get;}
void Reset ();
}
‫ﻛﻮد‬
VB
Public Interface IEnumerator
Function MoveNext() As Boolean
ReadOnly Property Current() As Object
Sub Reset()
End Interface
‫ﻛﻮد‬
177
KF1MN، interfaceg%‫ א'א‬lWk implements KF ‫'م‬7 users J!K<‫ אن‬UG—N'‫א‬W
:‫א‬KPT‫'نذ‬P، GetEnumerator() ‫א‬$implement
C#
public class users:IEnumerable
{
employee[] emp = new employee[4];
users()
{
emp[0]
emp[1]
emp[2]
emp[3]
=
=
=
=
new
new
new
new
employee(10,
employee(20,
employee(30,
employee(40,
‫ﻛﻮد‬
"Ahmed");
"Khaled");
"Ali");
"Sami");
}
public IEnumerator GetEnumerator()
{
return emp.GetEnumerator();
}
}
VB
Public Class users
Implements IEnumerable
Private emp As employee() = New employee(3) {}
Private Sub New()
‫ﻛﻮد‬
emp(0) = New employee(10, "Ahmed")
emp(1) = New employee(20, "Khaled")
emp(2) = New employee(30, "Ali")
emp(3) = New employee(40, "Sami")
End Sub
Public Function GetEnumerator() As IEnumerator
Return emp.GetEnumerator()
End Function
End Class
:‫א‬KPT ً MQ‫ًא‬Q‫و‬$QW‫م‬7‫א‬NNP>
178
C#
‫ﻛﻮد‬
IEnumerator i = emp.GetEnumerator();
i.MoveNext();
employee myCar = (employee)i.Current;
VB
Dim i As IEnumerator = emp.GetEnumerator()
i.MoveNext()
Dim myCar As employee = DirectCast(i.Current, employee)
‫ﻛﻮد‬
‫ﻣﺎذا ﻧﺴﺘﻔﻴﺪ ﻣﻦ ﻫﺬه اﻟﻄﺮﻳﻘﺔ ؟‬
J!5D‫^ل‬3'SNSl‫د‬$V5‰3‫‘ن‬،'g. ‫א‬2NQ‫אن‬01Qh‫ א‬$D‫'א‬72343]!0.‫א'א‬U
‫אم‬$+g!K7N‫وא‬gN3 iz‫א‬7‫אšنא‬ND1b‫وא‬،hi$D7:,‫א‬h‫א‬53D'FnD'
.moveNext
: yield ‫اﺳﺘﺨﺪام‬
:‫'دא‬P‫א‬P.ˆ‫'دא‬P‫א‬53ً9$
C#
public IEnumerator GetEnumerator()
{
yield return emp[0];
yield return emp[1];
yield return emp[2];
yield break;
}
‫ﻛﻮد‬
„‘ KV n ‫א‬WPS‫ ‹ א^ !^^ و‬، „‫ אو‬F7‫ א‬i‫د‬D‫א א‬$ zD$‫ אول א‬03‫ و‬L‫ א‬lWS U
.yield break
KOq9CnNeCYL‫ذא‬n‫و‬، Linq „‘KV3$NDO‫א‬h3‫א‬$+9‫ א‬SC53i$‫وא‬nDfN
.g%‫א'א‬lWS 5DND
179
ICloneable interface
.4
:‫'دא‬P‫א‬GP 3$NDN‫א‬nN}،5jP¢N‫א‬FDg$V7Q clone ‫אل‬FD
C#
int x=5;
int y=x;
‫ﻛﻮد‬
VB
Dim x As Integer = 5
Dim y As Integer = x
‫ﻛﻮد‬
:‫א‬KPThJO‫א‬03N3U5P‫و‬، y „‘ x F.K7N‫'م‬7ً! N¦!
C#
car x=new car("BMW");
car y = x;
‫ﻛﻮد‬
VB
Dim x As New car("BMW")
Dim y As car = x
‫ﻛﻮد‬
KQ$ ‫א!¦نא‬W‫و‬، x F.:!W‫نא‬P\‫
‘„א‬TQVQ y ‫‘ن‬K، y „‘K7N9 x F.‫אن‬0.‫א'א‬U
@P@P‫ وא‬y F.‫ل‬$ x F.U
.Iš‫
א‬q\‫ א‬Ugs‫وو‬F7‫א‬Ui$Q$%+KFDK%‫א‬53 clone ‫אل‬FD€NS53
‫'د‬NNP>،‫ض‬q‫אא‬Wkg3‫א‬$+‫א‬5P>، clone ‫א‬$‫א‬nD 't‫ א‬ICloneable g%‫א'א‬
:
C#
public object Clone()
{
return new car(this.carName);
}
‫ﻛﻮد‬
180
VB
Public Function Clone() As Object
Return New car(Me.carName)
End Function
‫ﻛﻮد‬
:‫א‬KPT clone ‫אم‬$+i$Q$%+ KFDP3b‫אšنא‬
C#
car x=new car("BMW");
car y=(car)x.Clone();
‫ﻛﻮد‬
VB
Dim x As New car("BMW")
Dim y As car = DirectCast(x.Clone(), car)
‫ﻛﻮد‬
IComparable interface
.5
‫א אل‬WS KP, ‫'ن‬PQ ‫ אن‬1‫ א‬53 ‫א‬W‫ و‬، H7F interface ‫א אل‬WS ‫م‬$+Q ، 9‫ א‬53 s‫' وא‬S F
:‫ א‬KPTinterface
C#
public interface IComparable
{
int CompareTo(object o);
}
‫ﻛﻮد‬
VB
Public Interface IComparable
Function CompareTo(ByVal o As Object) As Integer
End Interface
‫ﻛﻮد‬
U 1F7‫א‬،‫ אو‬U 07‫א\دא‬U$Sً!،F.HF.$‫א‬$‫ (אنא‬3 NP>
.qbC ‫אول‬f1‫'نא‬U1−‫و‬،4‫אولא‬f1‫'نא‬
181
17N‫א‬KI‫א‬$‫א‬gF.‫ و‬h‫א‬HD9@‫ن‬Q‫و‬3‫'ن‬PQYNjP‫]نא‬¤
Wi‫د‬D‫א‬53D‫دא‬9ً
53:NF.3‫א‬WS‫و‬.!H7\‫‰ج‬N‫א‬،:%‰ 53'S‫و‬،i‫א‬W‫א‬U‫ن‬P\‫@א‬ONgH,‫א‬U
. equals ‫א‬$‫ لא‬I
!3„‘%U5‰K،9‫אم‬¤‫ذא‬5jP‫אא‬WS‫و‬QKS !\%rN!NSNQ$t‫א‬17N‫א‬3‫א‬
.gbœ‫א‬JO‫א‬5FsiH‫א‬0Nb¢QH‫ض‬ZON‫ و‬،qb‫אوא‬4‫א‬FgQ‫א‬
‫'אد‬9‫™א‬GP‹، IcomparableJO‫ˆא‬1Nbœ‫א‬JO‫א‬K`N،ˆ‫سא‬H$‫א‬UNF.F
:ً ^3 ‫א‬KPT‫ضא‬ZON، CompareTo ‫א‬$‫א‬U
C#
int IComparable.CompareTo(object obj)
{
Car temp = (Car)obj;
if(this.year > temp.year)
return 1;
if(this.year < temp.year)
return -1;
else
return 0;
}
‫ﻛﻮد‬
VB
Private Function CompareTo(ByVal obj As Object) As
Integer Implements IComparable.CompareTo
Dim temp As Car = DirectCast(obj, Car)
If Me.year > temp.year Then
Return 1
End If
If Me.year < temp.year Then
Return -1
Else
Return 0
End If
End Function
‫ﻛﻮد‬
‫א‬$‫א‬،‫'م‬gO\‫ א‬Kg‫א‬WS5P،1‫و‬0‫و‬1−53ً9$94‫و‬0‫و‬100−i‫د‬D‫א‬01¤
WD‫دא‬9 ً 
182
.‫אא‬WSF.gNQ‫دونאن‬a7!4‫א‬cQ G%'3.H‫אوو‬cQOb،qb‫א‬cQG.H9$KF
.O‫א‬
: Sort ‫اﻟﺪاﻟﺔ‬
‫א‬3‫א‬PNF.'L‫ א‬lWS U، myNumbers ‫م‬.H9‫א‬53 array !'OV3NQ$‫ضאن‬ZON
:ً3'gO3‫'د‬P‫نא‬P
C#
Array.Sort(myNumbers);
‫ﻛﻮد‬
VB
Array.Sort(myNumbers)
‫ﻛﻮد‬
.]1IE$R$]‫א‬WS ‫!¦ن‬gZ‫'د‬P‫אא‬WSN‫و‬،h‫א‬H‫א‬53!'OV3NQ$‫'ن‬5P‫و‬
‫א‬WS‫אم‬$+‫א‬NPFL‫א‬lWSO!، IComparable interface ‫ˆאل‬1 car JO‫'نא‬U5P
‫'ن‬PQ}H،g4 €‫€א‬F.t‫ א‬CompareTo ‫دא‬nDً‫دא‬FD‫א‬H7\‫'م‬7f'g ‫א‬$‫א‬
‫^ ًאوא‬3 check ‫دא‬53ً9$‫א‬$‫ و'د א‬interface ‫אאل‬WSˆ1‫'م‬7ً!ً‫א‬WS
2343g's‫ًوو‬79KPbœ‫א‬JO‫אمא‬$+‫א‬Kg!s9ً‫א‬WS . Fg\‫@א‬ON‫م‬7IŠ‫א‬
IŠ
‫‪183‬‬
‫اﻟﺒﺎب‬
‫‬
‫‪10‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫اﻷﺧﻄﺎء واﻗﺘﻨﺎﺻﻬﺎ‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
184
185
5P‫و‬،:! I‫و‬z1I9‫א‬g,‫]وא‬1œ‫א‬KjH3 ،gQ‫د‬O‫و‬gbN.‫א‬O‫و‬z1I‫א‬nD‫א‬WSNH‫د‬UfN
:23‫א‬UKVt‫א‬z1I‫م א‬.Cs'‫‰ج–ن‬Q‫א‬$‫א‬K.
: ‫ اﻷﺧﻄﺎء اﻟﻨﺤﻮﻳﺔ‬- Syntax Errors
.1
Visual ‫ אل‬K^3 Advanced Programming Environments U‫ و‬، Kg9‫' א‬S z1I9‫ א‬53 ‫'ع‬N‫א א‬WS
:‫א‬FŽ‫]א‬1œ‫אא‬WS‫^ل‬3،ًQH'! z1I‫א‬lWSfT‫א‬Q،Studio , netbeens ... etc
‫ﻛﻮد‬
if x.Nome = somevalue
Kg9‫ א‬Sz1I‫א‬lWSK^3،i‫'د‬%'3
— Nome bœ‫]نא‬¤4§WON‫א‬K.]1IH $`01
KjH€Rb‫ א‬Visual Studio .net 2008 U‫و‬،gDKFt‫א‬4‫א‬qJ‫ ل‬I53g!T‫א‬Q‫و‬
.7Q1‫ א‬lWgg‫'و‬gS
O5P>‫و‬QqRs‫وא‬1œ‫א‬
: ‫ اﻷﺧﻄﺎء اﻟﻤﻨﻄﻘﻴﺔ‬Logical Errors
.2
g(Q71N31I:NP‫]‰'و‬1I$%'Q 9}H‫'د‬P‫א‬$bn!،Gb‫' א‬Sz1I‫א‬53‫'ع‬N‫אא‬WS
:‫''د‬S]1œ‫אא‬WSnD‫^ل‬3a‫א‬،WON‫ א‬$ND
‫ﻛﻮد‬
Byte x = 100000
]1Ig(‫א‬WS5PQ_>$7‫א‬h‫א‬H‫א‬$b9‫א‬U5P‫و‬،$L‫אא‬WS53qb‫ א‬Byte ‫'ع‬N‫ود א‬$‫אن‬fً
.AFًQ'‰'P3FŽ‫ אنא‬
.‡‫א‬..: new KFD K. object ‫ل‬F.‫د‬N‫]א‬1œ‫אא‬WSnD^3‫א‬
ًD‫ א'א‬¤NS ‫ אن‬K ، i,3 g( z1I‫ א‬lWS K^3 €Rb‫ א‬، i$Q$Ž‫' א‬Q‫ !`'אل 'د‬h‫א‬H‫א‬$b‫ א‬03 5P
. warningsKP,nDg!T‫א‬nDH‫د‬.'Q‫`'אل'د‬O‫א‬b‫ א‬Logic Errors ‫אل‬53Gb‫א‬
:‫'אعא‬C‹ ‹„‘S‫א‬z1I‫א‬S‫ و‬Logical Errors ‫אل‬7C$N،ً‫א‬$GSW5
186
: User Error 5P،‫م‬$+\‫א‬FD5Q+:!‫'م‬7 Byte ‫א\^لאˆل‬NsZ!‫'א‬،234‫אمא‬$+‫א‬532Nz1IC
$. 5P _' F! KT\‫ א‬U G ‫م‬$+\‫ א‬53 ]1œ‫א א‬WS ، f9‫ א‬10 .H ‫ل‬I‫م د‬. ‫م‬$+\‫א‬
€‫ج‬H$N:! I‫و‬F‫א‬IUVh‫ل‬I‫ًאد‬MQ‫א‬،Y3$LF‫م{وز א‬$D53$]‫طא‬,€Os‫א‬
.‫م‬$+\‫א‬z1IC ‫א‬
: Exceptions iH'V gF Q _ ً ^3 i‫'د‬%'3 — h i$D. ‫ אو‬o3 ! ‫ )و‬، z1I‫ א‬53 g,‫'ع א‬N‫א‬
، nullable type ‫אم‬$+‫ونא‬$ null ‫و‬g‫א‬YUh‫א‬i$D.53h iz‫א‬.‫)و‬،RRb
.iH'gT\‫א‬z1I‫א‬53:! I‫و‬، ReadOnly Vo3„‘P‫)وא‬
: Bugs g3$+t‫وزא‬$NQ'‫א‬+g!} 23‫א‬4‫א‬0BU$%'‫و‬،S$D9‫و‬SV5P>9،ig,z1I‫א^א‬
iz‫א‬.‫
אو‬q3fW‫ن‬GE$$.،‫ع‬1\‫א‬H$.gQ‫د‬O‫ ‰ول‬NNP‫و‬gN323'•5i‫אد‬U،
53٪99‫ل‬g( 9$.z1I‫א‬lWS،‡‫א‬...—H!F.g‫א‬5(5‰‫و‬i‫א‬W‫א‬Uً b‫א‬i‫'د‬%'3 F.53
q3
23 ‫ א‬53 Q{ ¢ i$D ¤NS ‫'ن‬P i‫ אد‬U ‫א‬W ، a7! $‫م وא‬$+\ g( NP‫ و‬Y3$+\‫א‬
. ƒ‫א‬+N‫א‬v K.gQ$‫و‬z1I‫א‬lWS‫^ل‬3‫א‬53‫!א‬3‫[و‬
53h‫א‬zN^N‫א‬0s‫ولو‬RNًMQ‫'عאولא‬N‫א‬،S‫'א‬S‫و‬z1I‫א‬53^‫'عא‬N‫ א‬nDN‫א‬WSNH‫د‬U
`!^^‫א‬L‫ א‬3‫א‬،„‫אو‬L‫א‬US‫א‬Sˆ7R‫א‬KB5P‫مو‬$+\‫א‬h‫א‬HI‫א‬53$]‫א‬K%‫א‬
.g7K^3‫א'א‬S\‫وא‬iF\‫א‬
System.Exception ‫اﻟﻔﺌﺔ‬
.3
KQ]1IC‫!¦ن‬0.‫א'א‬U،‫(م‬N‫א‬UE$t‫א‬z1I‫ א‬03K3 .net _D U V+\‫ א‬JO‫א‬S
1œ‫אא‬WS03K3 System.Exception ‫•'ل‬lH‫و‬$W‫وא‬، CLR ‫‘„אل‬:H ‫(م‬N‫'مא‬7Q‹‫(م‬N
:‫א‬KPTJO‫א‬lWShQ') ،
187
C#
public class Exception : ISerializable, _Exception
{
// Public constructors
public Exception(string message, Exception innerException);
public Exception(string message);
public Exception();
// Methods
public virtual Exception GetBaseException();
public virtual void GetObjectData(SerializationInfo info,
StreamingContext context);
// Properties
public virtual IDictionary Data { get; }
public virtual string HelpLink { get; set; }
public System.Exception InnerException { get; }
public virtual string Message { get; }
public virtual string Source { get; set; }
public virtual string StackTrace { get; }
public MethodBase TargetSite { get; }
}
‫ﻛﻮد‬
‫ﻛﻮد‬
VB
Public Class Exception
Implements ISerializable
Inherits _Exception
' Public constructors
Public Sub New(ByVal message As String, ByVal innerException As Exception)
End Sub
Public Sub New(ByVal message As String)
End Sub
Public Sub New()
End Sub
' Methods
Public Overridable Function GetBaseException() As Exception
End Function
Public Overridable Sub GetObjectData(ByVal info As SerializationInfo, ByVal context
As StreamingContext)
End Sub
' Properties
Public Overridable ReadOnly Property Data() As IDictionary
Get
End Get
End Property
Public Overridable Property HelpLink() As String
Get
188
End Get
Set
End Set
End Property
Public ReadOnly Property InnerException() As System.Exception
Get
End Get
End Property
Public Overridable ReadOnly Property Message() As String
Get
End Get
End Property
Public Overridable Property Source() As String
Get
End Get
Set
End Set
End Property
Public Overridable ReadOnly Property StackTrace() As String
Get
End Get
End Property
Public ReadOnly Property TargetSite() As MethodBase
Get
End Get
End Property
End Class
:JO‫א‬lWk9‫ق א‬1‫*وא‬jVœ‫א‬nDf‫ولא‬RN
nN\‫א‬
bœ‫א‬
bL‫] א‬1œ‫א‬H
Message
]1œ‫אא‬Wk throw KF‫م‬.W‫ƒא‬9‫א‬o3
Source
:N3i‫د‬O9‫א‬01،KVO‫™א‬PT\‫א‬vTQ a‫א‬HnDbœ‫א‬lWS'
HelpLink
3(N IT ‫אل‬U*V+\‫مא‬$+\‫ א‬:N3$OQ}H‫و‬234F
189
Throw Exceptions - ‫رﻣﻲ اﻻﺳﺘﺜﻨﺎءات‬
.4
O N.Y3o3‫'د‬%‫مو‬$DK^33]1œ throw KF234‫'م א‬7Q‫אن‬5P>234 ¤WON‫ ل‬I
‫ضא‬ZON،]1+ throw KFg!€‫א‬G—AIC¤NSK(5P،:3K3‫]وא‬1œ‫אא‬WSiz‫א‬.
o\‫'د א‬%‫م و‬$D U ]1I H ‫'م ض‬7 ‹ 53‫ و‬o\‫'د א‬%‫م و‬$D 53 $] check KF ‫'م‬7
:ً ^3‫א‬KPT
C#
if (!System.IO.File.Exists("c:\\ahmed.txt"))
{
Console.WriteLine("there is no file");
}
‫ﻛﻮد‬
VB
If Not System.IO.File.Exists("c:\ahmed.txt") Then
Console.WriteLine("there is no file")
End If
‫ﻛﻮد‬
–!s9،i$'3z1I‫*א‬N.iH'bUG—‫و‬،a7!iz‫א‬7o\‫] 'نא‬1I‫ص‬N.7_}HNP
AIC h‫א‬HD‫و א‬C ، GQ'‫ א‬03 ^‹ i3‫ و‬Windows Forms ‫ אل‬5Fs JO‫@ א‬O ‫אم‬$+9 ‫ ج‬$.
KFD5P>h‫א‬HD9‫ א‬lWS53. g3‫א‬$+‫ א‬J!234€N'ً ^3234F throw KFDUG—
:‫א‬KPT]1œthrow
C#
‫ﻛﻮد‬
if (!System.IO.File.Exists("c:\\ahmed.txt"))
{
throw new Exception("there is no file");
}
VB
If Not System.IO.File.Exists("c:\ahmed.txt") Then
Throw New Exception("there is no file")
End If
‫ﻛﻮد‬
190
K3‫]وא‬1œ‫א‬5jiz‫א‬.ً7901،gRs‫אو‬t‫]א‬1IHg&‫م‬. 'Q‫`'אل'د‬O‫אنא‬${‫א‬WPS
.‫`'אل‬O‫א‬53ًj72NQW‫]א‬1œ‫א‬03K3F:3
catching exceptions - ‫اﻗﺘﻨﺎص اﻷﺧﻄﺎء‬
.5
‫'د‬%‫و‬U¤'‫א‬53234‫•جא‬r Try ‫אم‬$+S7Q a‫א‬،z1I‫صא‬N.‫א‬H‫دو‬z%‫אšن‬
:ً ^3‫א‬KPT،234‫א‬o.'UGQ ‫]دونאن‬1œ‫א‬
C#
try
{
x+=100;
console.writeLine("no errror");
}
catch
{
console.writeLine("some error!");
}
‫ﻛﻮد‬
VB
Try
x += 100
console.writeLine("no errror")
Catch
console.writeLine("some error!")
End Try
‫ﻛﻮد‬
234‫א‬Kb‫אذ'א‬$DF!، catch„‘‫ل‬79‫א‬i,3! 7‫א‬0FŽ‫א‬FDU]1I‫'د‬%‫و‬U
.234‫א‬f7Q‫א‬Q5‫ن‬9‫א‬KU‫و‬، gDH‫دونא\و‬
7‫*א‬jVœ‫אمא‬$+E$W‫]א‬1œ‫א‬5DKbO‫ض‬DًMQ‫ א‬NNP>
C#
try
‫ﻛﻮد‬
{
x += 100;
console.writeLine("no errror");
}
191
catch (Exception e)
{
Console.WriteLine("Method: {0}", e.TargetSite);
Console.WriteLine("Message: {0}", e.Message);
Console.WriteLine("Source: {0}", e.Source);
}
VB
Try
x += 100
console.writeLine("no errror")
Catch e As Exception
Console.WriteLine("Method: {0}", e.TargetSite)
Console.WriteLine("Message: {0}", e.Message)
Console.WriteLine("Source: {0}", e.Source)
End Try
‫ﻛﻮد‬
‫ضא\^ل‬ZON،‫אذ‬$DF!‫ضא‬D‫و‬SHI‫א‬NNPF! ،E$‫אن‬5P>t‫א‬z1I‫™א‬fN'
‫م‬D]1xHg(N‫אذ‬$DF!‫و‬، overflow G‫'ن‬PQ‫אن‬5P>]1œ‫نא‬Cf N'U‫א‬
C#
try
‫ﻛﻮد‬
{
x += 100;
console.writeLine("no errror");
}
catch (OverflowException e0)
{
Console.WriteLine("value of x more than up bound");
}
catch (Exception e)
{
Console.WriteLine("Method: {0}", e.TargetSite);
Console.WriteLine("Message: {0}", e.Message);
Console.WriteLine("Source: {0}", e.Source);
}
VB
Try
x += 100
console.writeLine("no errror")
Catch e0 As OverflowException
‫ﻛﻮد‬
192
Console.WriteLine("value of x more than up bound")
Catch e As Exception
Console.WriteLine("Method: {0}", e.TargetSite)
Console.WriteLine("Message: {0}", e.Message)
Console.WriteLine("Source: {0}", e.Source)
End Try
Finally ‫اﺳﺘﺨﺪام‬
.5.1
UG—N'ً ^F!،:3$D‫]אو‬1I‫'د‬%‫و‬USWONQ‫ و‬try - catch ¤'‫א‬Qg$WON‫م‬$+
:‫'دא‬P‫א‬GP:3$D53 x q\‫א‬U]1IE‫و‬$5D(N‫™א‬q 3*D
C#
try
‫ﻛﻮد‬
{
x += 100;
console.writeLine("no errror");
}
catch (Exception e)
{
Console.WriteLine("Method: {0}", e.TargetSite);
Console.WriteLine("Message: {0}", e.Message);
Console.WriteLine("Source: {0}", e.Source);
}
finally
{
Console.WriteLine("somehing");
}
VB
Try
x += 100
console.writeLine("no errror")
Catch e As Exception
Console.WriteLine("Method: {0}", e.TargetSite)
Console.WriteLine("Message: {0}", e.Message)
Console.WriteLine("Source: {0}", e.Source)
Finally
Console.WriteLine("somehing")
End Try
‫ﻛﻮد‬
193
break ‫اﺳﺘﺨﺪام‬
.5.2
.‫`'אل‬ON Exit Try ‫و‬C break ‫אم‬$+‫ א‬5P>،33UzN^N9‫א‬53‫وج‬+
Target Site ‫اﺳﺘﺨﺪام‬
.5.3
UgN3i‫د‬O9‫א‬5P>،]1+throw KF€3.t‫אא‬$‫ وא‬JO‫'لא‬i$Q$Dh3'3bœ‫א‬lWS!'
.]1œ‫א‬E‫و‬$‫ن‬P3!\ Debug KFD
HelpLink ‫اﺳﺘﺨﺪام‬
.5.4
ً ^3‫א‬KPT:N3i‫د‬O9‫א‬:NP>Y3N0s‫ˆو‬Q5D، g‫م‬$+\‫وא‬CJO‫مא‬$+3i‫א!د‬01
C#
try
{
m += 100;
Console.WriteLine("no errror");
}
catch (Exception e)
{
e.HelpLink = "www.ahmedgamal-space.blogspot.com";
}
‫ﻛﻮد‬
VB
Try
m += 100 Console.WriteLine("no errror")
Catch e As Exception e.HelpLink = "www.ahmedgamal-space.blogspot.com"
End Try
‫ﻛﻮد‬
194
‫ﻋﻤﻞ أﺧﻄﺎء ﺧﺎﺻﺔ‬
.6
BaseExceptionJO‫א‬53g.7,‫א‬Q‫א‬Uً79g3‫א‬$+‫א‬NP>]1I‫'ع‬N‫א‬53J!oQNP>
remote ‫ אل‬U g3‫א‬$+‫ א‬P3‫ א‬K%‫ א‬53 Iserializable g%‫ א'א‬53 7T3 gŽ ً MQC ‫ ج‬C F
:ً ^3‫א‬KPT‫ص‬I]1IoQNP>،:! I‫و‬
C#
public class NewException : BaseException, ISerializable
{
public NewException()
{
// something here
}
public NewException(string message)
{
// something here
}
public NewException(string message, Exception inner)
{
// something here.
}
// ‫אل‬F Sterilization
‫ﻛﻮد‬
protected NewException(SerializationInfo info, StreamingContext context)
{
// Add something here.
}
}
VB
Public Class NewException
Inherits BaseException
Implements ISerializable Public Sub New()
' Add something here.
End Sub Public Sub New(ByVal message As String)
' Add something here.
End Sub Public Sub New(ByVal message As String, ByVal inner As Exception)
' Add something here.
‫ﻛﻮد‬
195
End Sub ' ‫אل‬F Sterilization Protected Sub New(ByVal
StreamingContext)
' Add something here.
End Sub
End Class
info
As
SerializationInfo,
ByVal
context
As
:msdn„‘‫'ع‬%‫א‬NP>gbN.‫وא‬z1I9‫'لא‬$QF
‫رابط‬
http://msdn.microsoft.com/en-us/library/ms229014(VS.80).aspx
196
‫‪197‬‬
‫اﻟﺒﺎب‬
‫‬
‫‬
‫‬
‫‪11‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫اﻟﺘﺠﻤﻴﻌﺎت ‪Collections‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
198
199
‫ذ€אل‬K%C53،bNDi$DnD'd container KF]`3i‫د‬DO+\‫א‬4‫א‬N71U
„‘‫‰ج‬$!N‫א‬9‘.O†hJ!53nً‫
א‬I‫'صوא‬VN‫موא‬.H9‫ א‬53 array KFDNP3‫אن‬NQCH‫ و‬array
U، O+\‫ א‬collections‫אل‬h$%‫אو‬WSK%‫א‬53، array ‫אل‬NS!'t‫א‬53^9‫م א‬g\‫™א‬
.‫א‬z,‫‘ن‬gDff'‫א‬WSNH‫د‬
System.Collections ‫ ﻓﻲ‬interfaces ‫اﻟـ‬
.1
:‫א‬hg%‫א'א‬$%' collection ‫אل‬Ui‫'د‬%'\‫ א‬hg%‫א'א‬N%‫א‬H'
: Icollection
‫אم‬KPT‫א‬k،:! I‫ و‬IsSynchronized‫ وאل‬size ‫אل‬K^39‫طא‬7N‫™א‬nDg%‫א'א‬lWS'
:‫א‬
C#
public interface ICollection : IEnumerable
{
int Count { get; }
bool IsSynchronized { get; }
object SyncRoot { get; }
void CopyTo(Array array, int index);
}
‫ﻛﻮد‬
VB
Public Interface ICollection
Inherits IEnumerable
ReadOnly Property Count() As Integer
ReadOnly Property IsSynchronized() As Boolean
ReadOnly Property SyncRoot() As Object
Sub CopyTo(ByVal array As Array, ByVal index As Integer)
End Interface
‫ﻛﻮد‬
200
: Icomparer
.7gDN!
: Idictionary
gNQ‫و‬ND‫و‬YO&'\‫א‬hً ^3 5Q+g3‫א‬$+‫א‬5P>،‫د‬9‫א‬K%‫א‬53gƒ‫א‬53s‫'وא‬SF‫م‬$+
.:! I‫و‬fWL‫!وא‬s ‫دوאل‬nD'،:‫'א‬ND‫ אو‬:ƒ‫א‬9$*+T‫א‬nD‫ذ‬$H'^‫א‬5P>r
:‫א‬KPTk‫אم‬KPT‫א‬
C#
public interface IDictionary :
ICollection, IEnumerable
{
bool IsFixedSize { get; }
bool IsReadOnly { get; }
object this[object key] { get; set; }
ICollection Keys { get; }
ICollection Values { get; }
void Add(object key, object value);
void Clear();
bool Contains(object key);
IDictionaryEnumerator GetEnumerator();
void Remove(object key);
}
‫ﻛﻮد‬
VB
Public Interface IDictionary
Inherits ICollection
Inherits IEnumerable
ReadOnly Property IsFixedSize() As Boolean
ReadOnly Property IsReadOnly() As Boolean
Default Property Item(ByVal key As Object) As Object
Get
End Get
Set
End Set
End Property
ReadOnly Property Keys() As ICollection
ReadOnly Property Values() As ICollection
‫ﻛﻮد‬
201
Sub Add(ByVal key As Object, ByVal value As Object)
Sub Clear()
Function Contains(ByVal key As Object) As Boolean
Function GetEnumerator() As IDictionaryEnumerator
Sub Remove(ByVal key As Object)
End Interface
: Ienumerable
.ً7g,”
: Ienumerator
.ً7g,”
: IdictionaryEnumerator
،‫א‬$‫א‬lWg‫ אœص‬interface‫'אل‬S‫א‬WS، GetEnumerator ‫א‬$‫א‬$` IDictionary U€(9'
:‫אمא‬KPT‫א‬k
C#
public interface IDictionaryEnumerator : IEnumerator
{
DictionaryEntry Entry { get; }
object Key { get; }
object Value { get; }
}
‫ﻛﻮد‬
VB
Public Interface IDictionaryEnumerator
Inherits IEnumerator
ReadOnly Property Entry() As DictionaryEntry
ReadOnly Property Key() As Object
ReadOnly Property Value() As Object
End Interface
‫ﻛﻮد‬
202
: IhashCodeProvider
. GetHashCode‫א‬$‫אمא‬$+Y\‫ א‬collection K hash code ‫אل‬i‫د‬D*•
: Ilist
KPT‫א‬:! I‫ و‬fWL‫وא‬R‫!وא‬s g3K3‫א‬Kg‫دوאل‬i$DnD'،3‫א‬U3K‫א‬WS ،Fj.
:‫א‬KPTk‫אم‬
C#
public interface IList :
ICollection, IEnumerable
{
bool IsFixedSize { get; }
bool IsReadOnly { get; }
object this[ int index ] { get; set; }
int Add(object value);
void Clear();
bool Contains(object value);
int IndexOf(object value);
void Insert(int index, object value);
void Remove(object value);
void RemoveAt(int index);
}
‫ﻛﻮد‬
VB
Public Interface IList
Inherits ICollection
Inherits IEnumerable
ReadOnly Property IsFixedSize() As Boolean
ReadOnly Property IsReadOnly() As Boolean
Default Property Item(ByVal index As Integer) As Object
Get
End Get
Set
End Set
End Property
Function Add(ByVal value As Object) As Integer
Sub Clear()
Function Contains(ByVal value As Object) As Boolean
Function IndexOf(ByVal value As Object) As Integer
‫ﻛﻮد‬
203
Sub Insert(ByVal index As Integer, ByVal value As Object)
Sub Remove(ByVal value As Object)
Sub RemoveAt(ByVal index As Integer)
End Interface
System.Collections ‫اﻟﻔﺌﺎت ﻓﻲ‬
.2
:‫א‬hJO‫א‬nD'd
ArrayList
Hashtable
Queue
SortedList
Stack
ArrayList
•
•
•
•
•
.2.1
!s‫א‬،hi$gNQ§ 53 array ‫אل‬hƒ@ONF،9‫א‬53s‫'وא‬SF array Fj.S
.!'OV\‫א‬lWSbNDKI‫دא‬:! I‫و‬fWL‫وא‬GZ‫وא‬KQ$‫! وא‬s9‫א‬hFDKgt‫א‬Fj7‫א‬h‫א‬F\
‫אم‬$+gN3!'OV3fN،gQ‫'د‬3‫ و‬iH‫אא‬nD't‫وא‬7‫(א‬iH)J!NQ$‫ضאن‬ZON
:‫א‬3‫א‬
C#
Car[] carArray = new Car[4];
‫ﻛﻮد‬
VB
Dim carArray As Car() = New Car(3)
‫ﻛﻮد‬
gN3i$‫وא‬fWrG—}H،‫ن‬V7N ‫אو‬i‫د‬Q‫}ج‬H،a7!h‫א‬H0H9‫אج‬f5P_}H
،*jVœ‫א‬lWS03K3‫א‬Kgh‫א‬Hœ‫א‬53
^P‫ א‬array ‫אل‬N!'9AFP!،‡‫א‬...oVN\‫א‬53
.:! I‫و‬fWR 3‫ج™אوא‬R
204
oQ 'S D 3 K ، hF‫ א‬lWS ‫'ص‬Vx KT3 ‫ א‬S 5D 7 array List hz% 5P
K3‫ א‬nD ‫ ًא‬H‫د‬. ‫'ن‬P System.Collection ‫ ل‬using KF ‫'م‬7 ‫ن‬C $ – ‫ א‬7Q1 arrayList
.− ً 79g3,\‫א‬
C#
using System.Collections;
ArrayList carList = new ArrayList();
‫ﻛﻮد‬
VB
Imports System.Collections
Dim carList As New ArrayList()
‫ﻛﻮد‬
:iH!s‫א‬NP>‫وאšن‬
C#
Car temp = new Car("BMW", 1990);
carList.Add(temp);
‫ﻛﻮد‬
VB
Dim temp As New Car("BMW", 1990)
carList.Add(temp)
‫ﻛﻮد‬
:‫'دא‬P‫א‬GP^‫نא‬P\‫א‬Uً ^3iH‫!א‬s9،Y3z%U insert KFDًMQ‫א‬01
C#
‫ﻛﻮد‬
carList.Insert(3,temp);
VB
‫ﻛﻮد‬
carList.Insert(3,temp)
::.'39$Y3VND3‫و‬C،Fj7‫א‬K3301ً MQC
C#
carList.Clear();
carList.RemoveAt(4);
‫ﻛﻮد‬
205
VB
carList.Clear()
carList.RemoveAt(4)
‫ﻛﻮد‬
::OVN‫א‬9$n‫و‬C
C#
carList.Remove(temp);
‫ﻛﻮد‬
VB
carList.Remove(temp)
‫ﻛﻮد‬
:ً ^3‫א‬KPTًB gD‫אن‬H‫و‬$‫وא‬،‫د‬$‫ \!א‬Count bœ‫אمא‬$+‫א‬NNP>
C#
‫ﻛﻮد‬
for (int i = 0; i < carList.Count; i++)
{
temp = (Car)carList[i];
}
VB
For i As Integer = 0 To carList.Count - 1
temp = DirectCast(carList(i), Car)
Next
‫ﻛﻮد‬
‫אم‬$+Q‫د‬D array „‘gQ'NNP>،ً7NFF sort K^3AI‫* א‬jVœ‫אم™א‬$+‫א‬NNP>
،‫א‬7Q1R ‫م‬$+ indexof ‫א‬$‫א‬،Fj7‫א‬G@P Reverse ‫א‬$‫א‬، toarray ‫א‬$‫א‬
:‫א‬KPT‫'نذ‬P،i‫'د‬%'\‫א‬h‫א‬H‫ א‬5FsgNDR‫א‬UG—‫ و‬temp iH‫א‬NQ$‫ض‬ZON
C#
int find=carList.IndexOf(temp, 0);
‫ﻛﻮد‬
VB
Dim find As Integer = carList.IndexOf(temp, 0)
‫ﻛﻮد‬
17$Q$NP>F،$QF:3 K3‫وא‬VN‫نא‬P3„‘‫'ل‬b' find q\‫אمא‬$+‫א‬01‫א‬WPS‫و‬
.ً b‫א‬g3‫א‬$+‫م א‬$D‫אو‬S
q‫دאو‬$F0R‫א‬Q‫א‬$
206
.2.2
Hash Table
_‫‘ذא‬،1\‫א‬h‫א‬5DR‫ א‬Kg9‫א‬:Fg3، data structure h‫א‬5Q§‫ق‬53$‫وא‬
:NSQ$PQ‫ لو‬I53gDfRV! K.53 hash table ‫אل‬lWSDh3$.5P
‫رابط‬
http://en.wikipedia.org/wiki/Hash_table
IndexesKj9$‫א‬53g3‫•ن‬keysO\‫א‬53D'F5DiHDShashtable~‫!نא‬،$Q$,HVI‫و‬
.9‫א‬vO\‫א‬031\‫א‬7‫א‬.‫ن‬P3„‘
T
Linked list X :! VND K aQ Linked List 5D iHD hashtable ‫ אل‬5Q'P ‫'م‬7 N ˆ‫ א‬U
0s‫و‬Uz$‫ وא‬Hashtable oQNPF! ‫אšن‬3C،O+\‫א‬:‫א‬z‫א‬%‫وא‬:‫دوא‬KF‫'م‬7N‫و‬،AI‫א‬
‫س‬H$‫א‬UlNFŸ:! I‫ و‬Remove ‫ و‬Add,AddRange Q$7‫ א‬3‫אمאوא‬$+i,3:!h‫א‬
.ˆ‫א‬
Queue
.2.3
3 Queue ‫אنאل‬s'53‫]س‬9 5PhBZ‫™א‬£‫א‬9‫א‬03‫و‬،H'1‫א‬U:!L‫א‬BZ‫א‬
‫ول‬C ،Dequeue ‫אم‬$+ g%‫א‬I‫ وא‬Enqueue ‫אم‬$+ :‘ h‫ א‬0!‫ د‬Q ، ً ! H' 9‘ 'S
.77H'5DE$RNS 5RN!Y%Hœ‫'אولא‬SYI‫א‬$‫א‬
ً9‫'ل אو‬b'ˆ9‫Žא‬3H'UgM‫אن‬1‫א‬5F!،z F‫א‬h7 23234€N‫‘ذא‬
207
hFg\‫א‬GQ ) ©\‫)א‬H'‫و‬4‫'א‬S Queue ‫^אل‬3‫א‬g,‫}א‬H‫و‬،ًMQ‫א‬h‫א
!א‬U،
hŽ\‫(א‬U:‫@א‬N95P،iH'baً‫א‬WON ‫'אول‬SH'1ً9'b‫אولو‬،©\‫‘„א‬kI‫אد‬
9 slides ‫(مאل‬N!s‫א‬Q'‫و‬9‫א‬K^3h‫'لא‬I‫د‬UPRt‫א‬bN‫ א‬53$Q$‫א‬¤NS^Q$L‫א‬
.‡‫א‬...i$‫وא‬i3 task‫אل‬WONQ
:‫א‬KPTz F‫א‬H'‫ض‬ZON،ً‫^
א‬$ ‫אن‬$Q9
C#
Queue empQueue = new Queue();
employee temp=new employee();
for (int i = 0; i < 10; i++)
{
temp.userName = Console.ReadLine();
empQueue.Enqueue(temp);
}
‫ﻛﻮد‬
VB
Dim empQueue As New Queue()
Dim temp As New employee()
For i As Integer = 0 To 9
temp.userName = Console.ReadLine()
empQueue.Enqueue(temp)
Next
‫ﻛﻮد‬
@N9ً.ً%‫و‬Ik‫و‬C‫'ن‬Pً9'I‫د‬YO&'\‫אنאولא‬$`، Dequeue KFN Loop KF‫אšن‬NF.'
.ˆ‫سא‬H$‫א‬USN,t‫א‬:! I‫ و‬CountK^3*jVœ‫אم™א‬$+‫א‬P3 ‫ن‬C
‫א‬$‫א‬3C،H'1‫א‬53i,3:!Wr‫'م‬7‫אولو‬VN‫א‬$ Dequeue ‫א‬$‫‘„אنא‬a7!
,‫א‬QgN‫א‬K.
.‫ن‬FH'1‫א‬U:ªOgNP‫و‬GZ‫א‬UVND ‫אول‬$g!Peek
Queue ‫ˆ אل‬1 O‫ و‬Data Structure €H‫ د‬$. €N ' W ‫ א‬5&C ، JO‫ א‬lWS ˆ1 03
JO‫א‬lWS03ً‫א‬$DV!‫אšن‬WN3:O2D5Ÿ
^P‫ وא‬circular queue ‫وאل‬، linked list ~‫אمא‬$+
208
Stack
.2.4
U
Iš‫א‬VN‫אنא‬، LIFO - Last Input First Output N70Q:‫אא‬$DF! Queue ‫אل‬K^3
Peek ‫אل‬، pop ‫אم‬$+g%‫א‬I‫א‬Q‫ و‬Push ‫אم‬$+bN‫لא‬I‫אد‬Q،‫אœوج‬U‫'אول‬S‫'ل‬I$‫א‬
. Stack‫ אل‬53 :!W ‫ دون‬9
ً 'I‫ د‬Iš‫ א‬N U 'S‫ אول و‬VN‫ض א‬D U S F gFg} ‫'م‬7
:‫א‬KPTQ Stack ‫אل‬oQ
C#
Stack jobStack = new Stack();
‫ﻛﻮد‬
VB
Dim jobStack As New Stack()
‫ﻛﻮد‬
:
‫اﻻﺳﺘﺨﺪاﻣﺎت‬
،‫ذ‬nD$F3'‫א‬Nh71(3‫ذאن‬، Queue ‫אل‬K%‫א‬53h3‫א‬$+‫ א‬H'VKgQ
NU:71zT‫ً™א‬Q— ‫'ن‬P}H‫א‬$UN\‫א‬j$} Stack ‫אل‬5P،ً9‫مאو‬$•ً9‫و‬CKb‫א'א‬
.'3'P‫א‬h71nDi‫ אد‬UV7Q Stack ‫אمאل‬$+‫א!¦نא‬W،77L‫א‬
:‫‘نא\د‬،H'‫و‬4‫א‬Uh9‫א\د‬K'S Stack K‫אم‬$+‫א‬aC
A + B
:‫ א‬KPTH'‫و‬4‫‘„א‬KI$
AB+
Q5SWON‫אن‬SWON stack UkI‫אد‬QH'‫و‬4‫א‬U‫و‬، postfix X'9‫אא‬WSnFQ
.ً MQ‫ א‬Compilers ‫אل‬BUIŠ‫^ل‬3،‫'ل‬b'‫א‬GZ
^^‫ א‬.O‫ א‬U P‫ א‬0QHT3 $‫ ن א‬infix ‫ و‬postfix Y KQ'R‫ א‬O s'Q 23 h7!\‫ א‬U
HI .،SWON‫ و‬stack Ugs'H'‫و‬4‫'مא‬7QO‫و‬KQ'R‫א‬O234‫ א‬s'Q،ND'F¡
FgNF!HI9‫א‬NP>‫'ز و‬3‫مאوא‬.H9‫אمא‬$+KL‫א‬NP>،h‫'א‬1œ‫ضא‬DD‫אض‬9 View
.KbO‫ً™א‬Fg3€N‫א‘ذא‬WS.iW!N‫א‬nD‫א‬53
‫رابط‬
http://vb4arab.com/vb/uploaded/3/21207604046.rar
209
:0.'\‫אא‬WS53i,3KQ'R‫א‬FD2nD‫א– ع‬NP>‫و‬C
‫رابط‬
http://scriptasylum.com/tutorials/infix_postfix/infix_postfix.html
:NS MSDN 0.'3US${KbO‫א‬53$Q3
‫رابط‬
http://msdn2.microsoft.com/en-us/library/aa289149(VS.71).aspx
€N‫‘ذא‬17N‫א‬lWS53 ‫ ق‬19‫א‬NP>، Data Structure D€ˆ1NQ‫س‬H$‫אא‬WSUˆ3K
nD ً 13 ‫'ن‬P ‫ אن‬¤$O ، \D U ‫ ^
ًא‬3 KI‫א‬$Q W‫א א_ א‬WS 5D ^P‫! א‬3 U G—
. Algorithms ‫!אل‬s‫א‬:‫א‬
537T3ًVV§^‫ א‬AI‫א‬hJ!nD'd‫و‬System.Collections.Specialized fQ3¤NSًMQC
.7‫א‬hJO‫א‬
210
‫‪211‬‬
‫اﻟﺒﺎب‬
‫‬
‫‬
‫‬
‫‪12‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ‪.net‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
212
213
.net 200803i3‫ول‬g&W‫א‬$Q$Ž‫א‬gN3 .netU4‫א‬bND™nDff'KVO‫אא‬WSU
.X‫אא‬WSUQ'gF`NF.‫א‬W،3ًD'3$73gNP‫ ًو‬.i‫'د‬%'3bNDgN3‫و‬a7!
Generic
.1
generics ‫אل‬S، .net framework 2.003i$Q$Ž‫א‬h‫א‬H'1‫א‬53i$‫وא‬03‫س‬H$‫אא‬WSUKb‫'א‬
:‫א‬KPTD13ً9^3 ‫ض‬ZON، overloading ‫'مאل‬gO\ً‫א‬$Q$%ً‫א‬$1
C#
public static void print(int x)
{
Console.WriteLine("Print As Integer {0}", x);
}
public static void print(long x)
{
Console.WriteLine("Print As Long {0}", x);
}
public static void print(string x)
{
Console.WriteLine("Print As String {0}",x);
}
‫ﻛﻮد‬
VB
Public Shared Sub print(ByVal x As Integer)
Console.WriteLine("Print As Integer {0}", x)
End Sub
Public Shared Sub print(ByVal x As Long)
Console.WriteLine("Print As Long {0}", x)
End Sub
Public Shared Sub print(ByVal x As String)
Console.WriteLine("Print As String {0}", x)
End Sub
‫ﻛﻮد‬
U01‫א‬${‫א‬WPS‫و‬،O†h‫א‬Z3H‫ل‬799‫@א‬ON‫دوאل‬E ‹ KF‫م‬.s‫'وא‬SF‫'د‬P‫א‬
$S,‫و‬O†‫ א'אع‬D1hFDi$DX%،‫'ص‬VN‫ אو‬longs K‫مאو‬.H D1‫אא‬$‫א‬zD$‫'د א‬P‫א‬
:‫א‬3‫א\^لאوא‬KnD،D1‫א‬B
214
C#
print("Ahmed");
print(12);
print(1000000000000);
‫ﻛﻮد‬
VB
print("Ahmed")
print(12)
print(1000000000000)
‫ﻛﻮد‬
:‫א‬KPTD1‫א‬2‫'ن‬P
K،h‫
א‬q\‫א‬53ًN3ًD'K79‫دא‬oQ‫אšن‬P3‫ אن‬،ًD'‫'م‬gO\‫
א‬q Generics ‫אل‬
‫א‬KPT7‫ א‬E ^‫وאلא‬$‫אضא‬Z!‫א‬01$.‫א‬W،‫س‬9‫אא‬WSnD:3K3‫< و‬T> K7 S
C#
public static void print<T>(T x)
{
Console.WriteLine("Print As {0}: {1}",typeof(T), x);
‫ﻛﻮد‬
}
VB
Public Shared Sub print(Of T)(ByVal x As T)
Console.WriteLine("Print As {0}: {1}", GetType(T), x)
End Sub
‫ﻛﻮد‬
215
:2N‫'نא‬PQf'،ˆ‫@ א\^لא‬ONN71U‫وאšن‬
Structure and Class Generics
.1.1
Structs ‫ وאل‬Classes ‫ ً אل‬MQ‫ א‬، Generics ‫ˆ אل‬1 t‫ א‬methods ‫ אل‬nD N! ˆ‫س א‬H$‫ א‬U
nDˆ1NQ class ‫אل‬nDˆ1NQ3‫ و‬class ‫^لאل‬3‫ض‬ZON،gh‫'م ™א‬gO\‫אא‬WSˆ1gNP>
. struct ‫אل‬
S‫و‬9‫א‬nD‫'عאول‬N‫'א‬d0jM‫א‬53YD'NQ$ ‫وאن‬،0jM‫א‬nD ' J!‫ض‬ZON
،‫'د‬H‫ א‬nD'iS%AIC0jM‫אوאد(و‬¹Ž‫א‬53‫)א'ع‬K[‫ א‬UgNV Qt‫א‬0jM‫א‬
.AIC0jMU.H‫ و‬0jM‫™א‬U‫א‬nD'd$. Identify K7‫אن‬2N7Q1‫א‬lWg
€N3‫אذא‬$Q$R71N3F.0s‫و‬f‫א(و‬5CU‫و‬C، ºVON3 YJ!‫'د‬%‫ و‬4‫ن‬$7‫א‬KL‫א‬
lWSU، ‫'م‬gO\‫אא‬WS
q” Generics ‫אل‬035P، numbner ‫אل‬K7‫ אم‬name ‫אل‬K7‫م‬$+
:‫א‬KPTJO‫א‬VL‫א‬
C#
public class product<T>
{
private T Identify;
public product(T val)
{
‫ﻛﻮد‬
216
Identify = val;
Console.WriteLine(Identify);
}
}
VB
Public Class product(Of T)
Private Identify As T
‫ﻛﻮد‬
Public Sub New(ByVal val As T)
Identify = val
Console.WriteLine(Identify)
End Sub End Class
:‫א‬KPT ‫'عאول‬N‫א‬535joQcNP>‫وאšن‬
C#
product<int> prd = new product<int>(1001);
‫ﻛﻮد‬
VB
Dim prd As New product(Of Integer)(1001)
‫ﻛﻮد‬
:‫א‬KPT^‫'عא‬N‫ א‬53‫و‬C
C#
product<string> prd2 = new product<string>("Some Product");
‫ﻛﻮد‬
VB
Dim prd2 As New product(Of String)("Some Product")
‫ﻛﻮد‬
Generic Collection
.1.2
Generic KFD nD ‫ אšن‬H‫و‬$‫ א‬b‫ א‬، Generic Class KFD NP3 ‫س אˆ אن‬H$‫ א‬U N! F
NFF، Add,Delete ... etc K^3hFDi$‫'م‬7Q‫ و‬hJ! i$D K7 J! KF‫'م‬7N، Collection
:3 Collection nD‫^ل‬3‫א‬WS ،ً7
217
C#
public class MyCollection<T>
{
private List<T> myList = new List<T>();
public T GetItem(int pos)
{
return myList[pos];
}
public void AddItem(T it)
{
myList.Add(c);
}
public void ClearCars()
{
myList.Clear();
}
}
‫ﻛﻮد‬
VB
Public Class MyCollection(Of T)
Private myList As New List(Of T)()
Public Function GetItem(ByVal pos As Integer) As T
Return myList(pos)
End Function
Public Sub AddItem(ByVal it As T)
myList.Add(c)
End Sub
Public Sub ClearCars()
myList.Clear()
End Sub
End Class
‫ﻛﻮد‬
nFQ3‫א‬WS،:! I‫و‬Rً b‫א‬i!'3
q‫*א‬jVœ‫}™א‬H‫*و‬jVœ‫ א‬53
^P‫!א‬s‫א‬P3ً
Q‫ אد‬Colelctions ‫ل אل‬$ :D ‫د‬FD9‫ א‬79 K‫א‬3 U 5P> Generic Collection ~
: ً ^3‫ א‬KPT،h‫א‬Hœ‫א‬53‫ ‘„—
ذ‬Employee .... ‫ אو‬Car K7Q‫אن‬5P>
C#
MyCollection<Car> myCars = new MyCollection<Car>();
myCars.AddItem(temp);
MyCollection<Employee> myCars = new MyCollection<Employee>();
myCars.AddItem(tempEmployee);
‫ﻛﻮد‬
218
VB
Dim myCars As New MyCollection(Of Car)()
myCars.AddItem(temp)
Dim myCars As New MyCollection(Of Employee)()
myCars.AddItem(tempEmployee)
‫ﻛﻮد‬
:‫م‬.H‫ א‬n‫و‬C
C#
MyCollection<int> myCars = new MyCollection<int>();
myCars.AddItem(12);
‫ﻛﻮد‬
VB
Dim myCars As New MyCollection(Of Integer)()
myCars.AddItem(12)
‫ﻛﻮد‬
.name K^3 *jVI nD 'd N ‫ אœص‬Generic Collection ‫'ن אل‬P ˆ PT3 N hg& NS
t‫ وא‬Where i‫א[`'ز‬FP‫ א‬Nhz%NS53،ً ^3‫م‬.H ‫ אو‬hJO‫א‬KPً ^3!'Q93‫א‬WS‫و‬،gs
.‫دم‬7‫سא‬H$‫א‬UgNDE$RN
Where T ‫اﺳﺘﺨﺪام‬
.1.3
$]‫وط‬T‫א‬0s‫و‬NNP>،hJO‫™א‬A'K79‫ אن‬Generic Collection ‫אل‬KFDU‫ط‬T‫אא‬WSNQ
:‫قא‬1‫א‬
nN\‫א‬
‫ط‬T‫א‬
ValueTpe ‫'ع‬N‫א‬53 h‫
א‬q3A'K7Q9r
where T : struct
RefernceType‫'ع‬N‫א‬53A' K7Q9
where T : class
Constructor nD'd‫אن‬$9
where T : new()
interface ˆ1Q‫אو‬Y3 class 53ˆT3‫'ن‬PQ ‫אن‬$9
where T : classname
where T : Iinterfacename
.Y3
:Q'‫א\^لא‬AN،gM03‫وط‬,i$D23‫د‬NNP>7Q1‫א‬lWg
219
C#
public class Example <T> where T : class, IComparable, new()
‫ﻛﻮد‬
VB
Public Class Example(Of T As {Class, IComparable, New})
‫ﻛﻮد‬
. Constructor nD'‫ و‬IComparable g%‫ˆא'א‬1، reference ‫'ن‬P‫אن‬$9 T ‫אن‬cQ‫א‬WS
:‫ًא\^لא‬MQC
C#
public class Example<K, T> where K : class, new()
where T : IComparable<T>
‫ﻛﻮد‬
VB
Public Class Example(Of K As {Class, New}, T As IComparable(Of T))
‫ﻛﻮد‬
IComparable g%‫ˆא'א‬1‫ אن‬$9 T F! constructor k‫ و‬Refernce ‫'ن‬P‫אن‬$9 K ‫אن‬cQ‫א‬WS
.0F`'O3g%53ً9$ T UzT‫™א‬PR‫א‬P3 b‫א‬،‫وאšن‬
Delegates
.2
. Delegates‫אل‬03i\‫א‬lWS$D'3 ، advanced .net programming ‫אل‬03NHKb‫'א‬
.g3‫א‬$+‫'م‬7‫ \ذא‬vT‫'م‬7N،g3K3‫א‬O‫و‬gvT‫אن‬K.
:‫א‬KPT‫ א‬nDS‫و‬،KQ'R‫א‬hFbIًMQ‫ א‬int $‫ و‬int K7‫دوאل‬i$D‫ض‬ZON
C#
public int ConvertEGToD(int EG)
{
return EG * 5.45;
}
public int ConvertRSToD(int RS)
{
‫ﻛﻮد‬
220
return RS * 3.75;
}
public int ConvertEGToRS(int EG)
{
return EG * 1.45;
}
public int ConvertDToRS(int D)
{
return D * 3.75;
}
public int ConvertDToEG(int D)
{
return D / 5.45;
}
public int ConvertRSToEG(int RS)
{
return RS / 1.45;
}
VB
Public Function ConvertEGToD(ByVal EG As Integer) As Integer
Return EG * 5.45
End Function
Public Function ConvertRSToD(ByVal RS As Integer) As Integer
Return RS * 3.75
End Function
‫ﻛﻮد‬
Public Function ConvertEGToRS(ByVal EG As Integer) As Integer
Return EG * 1.45
End Function
Public Function ConvertDToRS(ByVal D As Integer) As Integer
Return D * 3.75
End Function
Public Function ConvertDToEG(ByVal D As Integer) As Integer
Return D / 5.45
End Function
Public Function ConvertRSToEG(ByVal RS As Integer) As Integer
Return RS / 1.45
End Function
221
‫ل‬Q‫ وא‬V\‫ א‬NŽ‫ א‬، h FD E ‹ Y O+\‫ א‬h Q'R ‫م‬$+ ‫ دوאل‬i$D g! ، ً ! €(9 F
.PQ3‫א‬H9‫و‬$‫א'دوא‬
‫دوאل‬03ً ^3‫ذ‬KFD015NNP،KQ'R‫א‬.HK^>
q3‫ل‬H‫وא‬i$‫ دאوא‬UgFDNNP>ً
.s'‫אא\^ل‬Wg!‫א‬W،O†‫و‬4‫א‬
‫ א دא‬$Q$R switch ‫ אو‬if ‫ط‬, B ‫م‬$+ ‹ 53‫ و‬، ‫م‬$+\‫ א‬53 h‫ א‬C7N N U ‫אšن‬
:X'P\‫'دא‬PV† ‫א‬WS،g‘h‫لא‬H‫'م‬7N
C#
if (Operation == 0)
result = ConvertDToEG(userInput);
else if(Operation == 1)
result = ConvertRSToD(userInput);
‫ﻛﻮد‬
VB
If Operation = 0 Then
‫ﻛﻮد‬
result = ConvertDToEG(userInput)
ElseIf Operation = 1 Then
result = ConvertRSToD(userInput)
End If
‫א‬WS،ً79SWONN‫م‬$+F gsD‫و‬SWON‫دون‬F‫!'عא‬3‫אšن 'د‬a7!N‫ضא‬ZON5P‫و‬
U3ˆO9CًMQ‫א‬،F‫א‬WONi3‫مو‬$+\‫א‬nD‫ ض‬i3،Y3HI9‫א‬h‫א‬W‫'م‬7NN‫א‬cQ
‫ ‘ذא‬Operation ‫אل‬.A'ªO9€3‫د‬3‫و‬،YO†YP3UY3F‫א‬WON ‫ج‬$.‫א‬
.AICi3‫ط‬T‫א‬KBKF1M
. Delegates‫אل‬h$%‫אو‬WSK%C53
Delegates ‫ﺗﻌﺮﻳﻒ ال‬
.2.1
h‫א‬Z3H‫دא‬$D@O53‫وאل‬$‫ א‬lWS‫'ن‬P‫אن‬:‘‫‰ج‬3‫אول‬،‫دوאل‬D'F¡ Delegates oQ‫د‬H‫'א‬
:‫א‬KPTN‫وא‬$‫ אœص‬Delegate ‫'نאل‬P‫א‬W، output ‫ وאل‬input ‫@אل‬OkًMQC
222
C#
public delegate int myDelegate(int value);
‫ﻛﻮد‬
VB
Public Delegate Function myDelegate(ByVal value As Integer) As Integer
‫ﻛﻮد‬
‫א‬W ،gND‫ول‬p\‫אא‬$‫ א‬−BZ‫€ א‬Rb‫ ‘ن‬−™Q'O‫אא‬Wk‫د‬$‫אنא‬T‫א‬BUD3K‫وאšن‬
‫א‬KPTiV+\‫א‬N‫و‬,‫'ن‬P
C#
if (Operation == 0)
{
myDelegate aDelegate = new myDelegate(ConvertDToEG);
result = aDelegate(userInput);
}
else if (Operation == 1)
{
myDelegate aDelegate = new myDelegate(ConvertRSToD);
result = aDelegate(userInput);
}
‫ﻛﻮد‬
VB
If Operation = 0 Then
Dim aDelegate As New myDelegate(ConvertDToEG)
result = aDelegate(userInput)
ElseIf Operation = 1 Then
Dim aDelegate As New myDelegate(ConvertRSToD)
result = aDelegate(userInput)
End If
‫ﻛﻮد‬
، AIC i3 g3‫א‬$+‫א‬H‫א‬P‫ אو‬، QgN Delegate ‫ אل‬WON ‫'م‬7Q W‫
א‬I‫ط א‬T‫
א‬I] P3 MQ‫א‬
‫'د‬P‫א‬NP>‫א‬W، ‫אšن‬F‫ א‬lWSWON*§‫אدא‬f€Rb‫א‬$. aDelegate ‫אنאل‬
:‫א‬KPT
C#
if (Operation == 0)
{
myDelegate aDelegate = new myDelegate(ConvertDToEG);
‫ﻛﻮد‬
223
}
else if (Operation == 1)
{
myDelegate aDelegate = new myDelegate(ConvertRSToD);
}
// NS3‫™אوא‬WO
result = aDelegate(userInput);
VB
If Operation = 0 Then
Dim aDelegate As New myDelegate(ConvertDToEG)
ElseIf Operation = 1 Then
Dim aDelegate As New myDelegate(ConvertRSToD)
End If
‘NS3‫™אوא‬WO
‫ﻛﻮد‬
result = aDelegate(userInput)
$]‫א‬$C53ˆ7‫دونאن‬133‫وא‬CCWON53gNn‫א‬$‫א‬zD$‫
א‬I]NP>،‫א‬WPS‫و‬
.i$‫وא‬lWS،AICi3
KF‫א‬Uً‫^
א‬$OQ‫א‬WS،WONS% Delegate‫אل‬i‫د‬D‫وא‬VON3‫دא‬U$]‫א‬KFDNP>^‫وא‬
.hD'FKP,nD
Events ‫اﻷﺣﺪاث‬
.2.2
(‡‫א‬...‫אم‬$b‫א‬E‫)د‬iH9‫و‬C(‡‫ א‬... ‫ض‬3)$NDo&'3Y3E$KF‫'م‬7‫אšنאن‬N%'
‫و‘ذא‬،:E$Lbœ‫אא‬$‫א‬QF‫'م‬7‫و‬،ً ^3 Event DelegatesˆQ5Dً7W‫'م‬7N
SWON”t‫א‬E‫א‬$9 ListKFD01‫!א‬3nDH‫د‬.€]! Delegates ‫ אل‬U€'$.€N
. Delegate ‫אאل‬WSnD
... Event i‫א[`'ز‬FP‫ˆא‬Q5Di$Q$% 7Q13‫א‬N‫אšن‬
*K7QDelegateKF ً ^3iHKVt‫א‬E‫א‬$‫!א‬5D‫ول‬p3 Delegate Q‫א‬$‫ א‬UfN
:'1\‫אא‬
224
C#
public delegate void CarEventHandler(string msg);
‫ﻛﻮد‬
VB
Public Delegate Sub CarEventHandler(ByVal msg As String)
‫ﻛﻮد‬
:E‫א‬$9‫™א‬oQ‫'م‬7N‫وאšن‬
C#
public event CarEventHandler Exploded;
public event CarEventHandler Damaged;
‫ﻛﻮد‬
VB
Public Event Exploded As CarEventHandler
Public Event Damaged As CarEventHandler
‫ﻛﻮد‬
:‫א‬KPTg!E$‫א‬WON‫'د‬P‫ لא‬I53NP>‫אšن‬
C#
Damaged("my car");
‫ﻛﻮد‬
VB
Damaged("my car")
‫ﻛﻮد‬
ً ^3iH‫א‬KS!\، 9‫م‬C‫ ذ‬K.:. ‫\!‘ذאن”א‬9‫ אم‬event==null ‫א‬HI‫א‬NP>ً MQC‫و‬
.9‫م‬CS
3$”
:5jP‫ ‘„א‬E$L‫! دאא‬s9،17IŠ
C#
Car.EngineHandler d = new Car.CarEventHandler(CarExploded);
‫ﻛﻮد‬
VB
Dim d As Car.EngineHandler = New Car.CarEventHandler(CarExploded)
‫ﻛﻮد‬
225
W‫وא‬K\‫*א‬N‫א‬nDzNHHg&‫א‬S‫'و‬1\‫א‬Fg\‫א‬WON CarExploded‫א‬$‫א‬oQQ
:ً ^3‫א‬KPT،DamagedE$L‫א‬U:H‫”א‬
C#
public void CarExploded(string msg)
{
Console.WriteLine(msg);
}
‫ﻛﻮد‬
VB
Public Sub CarExploded (ByVal msg As String)
Console.WriteLine(msg)
End Sub
‫ﻛﻮد‬
C#‫ ﻓﻘﻂ ﻓﻲ‬Anonymous Methods ‫اﻟـ‬
.3
q3 ‫אم‬$+‫دא‬zD$‫א‬P3‫ن‬C¤H$€]! Delegates ‫אل‬5Dˆ‫سא‬H$‫€א‬D'‫ א‬$.€N‫‘ذא‬
. Delegate ‫'ع‬N‫א‬53
:4€F.W‫א‬E$L‫א‬K^F‫!אدא‬s‫א‬P3‫אن‬¤H$€Rb‫ א‬Events X‫سאœص‬H$‫א‬$‫و‬
:ً ^3‫ א‬KPT
C#
t.SomeEvent += new SomeDelegate(MyEventHandler);
‫ﻛﻮد‬
53‫אو‬$‫א‬oQoP\‫א‬53‫'ن‬P ‫א‬W،a7!‫ن‬P\‫אא‬WSUA'‫א‬$‫א‬zD$‫א‬$Q9‫ضא‬ZON‫وאšن‬
oQ P3 Anonymous Methods fQ 3 N g(Q NS ، Delegate U SzD$‫‹ א‬
. ‫'د‬P‫א‬a‫אو‬$‫א‬
:ً ^3‫'دא‬P‫א‬AN
C#
t.SomeEvent += delegate{
Console.WriteLine("Some Text");
}
‫ﻛﻮد‬
226
، a7! g3‫א‬$+‫ א‬0.'3 U ‫א‬$‫ א‬oQ P3 ‫ אšن‬b‫ א‬A F . C# 03 a7! 5P‫ و‬Rb ‫א‬WS :ً ^3‫א‬KPTh‫א‬Z3Hi$DK7‫א‬$‫'ن א‬P‫ًאن‬MQ‫א‬5P>
C#
t.SomeEvent += delegate(object sender, CarEventArgs e){
Console.WriteLine("Some Text {0}",e.msg);
}
‫ﻛﻮد‬
.g!gOQ”t‫אא‬$‫א‬Ui‫'د‬%'\‫א‬h‫
א‬q\‫‘„א‬KV‫ אن‬Anonymous method ‫نאل‬P3ًMQC
‫اﺳﺘﻨﺘﺎج اﻧﻮع اﻟﻤﺘﻐﻴﺮات‬
.4
:‫א‬KPT:D' $Q$‫
دون‬q3oQnD5QH‫د‬.N،6‫`'אل‬O‫مא‬QCU
VB
Dim x
x=10
‫ﻛﻮد‬
UًD'NŸ39‫אא‬WSK^3‫ن‬YU، Object ‫'ع‬N‫א‬53ًj$3gOQ‫'م‬7Q ‫`'אل‬O‫نא‬0.‫א'א‬U
.‫א‬jD0t‫א‬hq‫א‬
:ً ^3‫א‬KPT:D'$Q$„‘%L‫ونא‬$
q3oQXH,‫نא‬P3b‫ א‬،.net 200803
C#
var x = 2.3 // double
‫ﻛﻮد‬
VB
Dim x = 2.3 ‘ double
‫ﻛﻮد‬
ً ^3NP>5!،ً‫א‬HW55P،h‫א‬53‫א 'ع‬K"nDH‫د‬.
q3oQ'SF‫א‬lWS53f$k‫א‬
‫ن‬C var K5P>9ً‫
א‬IC،k return value ‫אل‬U‫و‬C‫א‬$‫א‬h‫א‬Z3HU ‫אو‬،i,3JO‫א‬U var oQ
. = null F. KFd
:g! var ‫אم‬$+‫א‬5P>9 t‫א‬z1I‫א‬0F®‫א\^لא‬
227
C#
class classname
{
// i,3JO‫א‬U:OQ5P>9
‫ﻛﻮد‬
private var varInt = 10;
// ¤‫אو‬Z3HoQ‫א‬5P>9 return value .
var functionname(var x, var y)
{
}
void somefunction()
{
// F.KFd‫אن‬5P>9 null
var varNull=null;
// F.KFd‫אن‬5P>97Q1‫א‬lWgn‫ و‬null
var? varNullable = 12;
// F.Y53$9
var m;
}
}
Extension Methods ‫اﻟﺪوال اﻟﻤﻤﺘﺪة‬
.5
nD KQ$‫ א‬bœ‫ א‬lWS  ، i$Q$Ž‫ א‬.net 2008 ‫'אص‬I 53 i$‫ وא‬Extension Methods ~‫א‬
.i$Q$%‫ودوאل‬C‫!دא‬s‫ًوא‬73i‫'د‬%'3hJ!
‫م‬$+‫دא‬KF‫'م‬7N،‫و‬ZP9‫א‬$Q4‫א‬Rb53$]‫'م‬7 string JO‫!دא‬s‫א‬$QN‫ضא‬ZON
:ً ^3‫א‬KPTRegex
C#
public static class Extensions
{
Public static bool IsValidEmailAddress(this string s)
{
Regex regex = new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$");
return regex.IsMatch(s);
}
}
‫ﻛﻮد‬
228
‫ﻛﻮد‬
VB
Imports System.Runtime.CompilerServices
Module StringExtensions
<Extension()>_
Public Function IsValidEmailAddress(ByVal s As String) As Boolean
Dim regex As New Regex("\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*")
Return regex.IsMatch(s)
End Function
End Module
:‫א‬KPT string q3oQKPNNP>،‫وאšن‬
C#
string mailExample = "email@mail. com";
MessageBox.Show(mailExample.IsValidEmailAddress.toString());
‫ﻛﻮد‬
VB
Dim mailExample As String = "email@mail. com"
MessageBox.Show(mailExample.IsValidEmailAddress.toString())
Automatic Properties
‫ﻛﻮد‬
.6
:ً ^3‫א‬KPTP‫وא‬iz‫א‬7 Get ‫ و‬Set ‫دوאل‬oQ‫'م‬7N Properties zT‫א‬K%‫א‬53‫ًو‬7
C#
public class myclass
{
private string _name;
public string name
{
get {return _name}
set {_name=value}
}
‫ﻛﻮد‬
VB
Public Class [myclass]
Private _name As String
Public Property name() As String
‫ﻛﻮد‬
229
Get
Return _name
End Get
Set
_name = value
End Set
End Property
End Class
:‫א‬KPT ‫'د‬P‫א‬P3b‫אšنא‬
C#
public class myclass
{
public string name{get; set;}
}
‫ﻛﻮد‬
VB
Public Class [myclass]
Public Property name() As String
Get
End Get
Set
End Set
End Property
End Class
‫ﻛﻮد‬
Lambda Expressions ‫ﺗﻌﺒﻴﺮات ﻻﻣﺪا‬
.7
‫ن‬P3 U ‫א‬$‫ 'د א‬53 NNPe t‫ א‬Anonymous Methods 5D ˆ ‫'ع‬s'3 U N‹$ $. N
K7t‫אدא‬$D‫א‬5DRg!‫'م‬7!'OV3‫ض‬ZON ،a7!i$‫وא‬i3A'gD$5N3‫د‬3SzD$‫א‬
:2nDF7‫א‬
C#
static void TraditionalDelegateSyntax()
{
List<int> list = new List<int>();
list.AddRange(new int[] { 20, 1, 4, 8, 9, 44 });
Predicate<int> callback = new Predicate<int>(IsEvenNumber);
‫ﻛﻮد‬
230
List<int> evenNumbers = list.FindAll(callback);
Console.WriteLine("Here are your even numbers:");
foreach (int evenNumber in evenNumbers)
{
Console.Write("{0}\t", evenNumber);
}
}
static bool IsEvenNumber(int i)
{
return (i % 2) == 0;
}
VB
Private Shared Sub TraditionalDelegateSyntax()
Dim list As New List(Of Integer)()
list.AddRange(New Integer() {20, 1, 4, 8, 9, 44})
Dim callback As New Predicate(Of Integer)(IsEvenNumber)
Dim evenNumbers As List(Of Integer) = list.FindAll(callback)
Console.WriteLine("Here are your even numbers:")
For Each evenNumber As Integer In evenNumbers
Console.Write("{0}" & Chr(9) & "", evenNumber)
Next
End Sub Private Shared Function IsEvenNumber(ByVal i As Integer) As Boolean
Return (i Mod 2) = 0
End Function
‫ﻛﻮد‬
:fF‫א‬KPTgND1 b‫ א‬C# 2008 53 Anonymous Methods KN3‫א‬$+‫א‬03
C#
List<int> list = new List<int>();
list.AddRange(new int[] { 20, 1, 4, 8, 9, 44 });
‫ﻛﻮد‬
List<int> evenNumbers = list.FindAll(delegate(int i)
{ return (i % 2) == 0; } );
Console.WriteLine("Here are your even numbers:");
foreach (int evenNumber in evenNumbers)
{
Console.Write("{0}\t", evenNumber);
}
KPT g 5P> t‫ وא‬، Lambda Expressions fQ 3 ‫אم‬$+‫' א‬S .net 2008 U $Q$Ž‫א‬
:‫א‬
231
‫ﻛﻮد‬
X => f(X)
:‫א‬KPT i%2==0 U True $t‫وא‬Nbœ‫אא‬$‫'نא‬P‫א‬W
C#
(int i) => (i % 2) == 0;
‫ﻛﻮد‬
VB
Function(i As Integer) (i Mod 2) = 0
‫ﻛﻮد‬
f' Lambda ‫–ن‬Z3H‫'عא‬oQ5DzNq9‫א‬nNP>، int :D'‫و‬،Z3H‫ א‬S i ‫אنאل‬
:‫א‬KPTK3P‫'دא‬P‫'نא‬P‫א‬W،ًj7:Df
C#
List<int> list = new List<int>();
list.AddRange(new int[] { 20, 1, 4, 8, 9, 44 });
List<int> evenNumbers = list.FindAll(i => (i % 2) == 0);
Console.WriteLine("Here are your even numbers:");
foreach (int evenNumber in evenNumbers)
{
Console.Write("{0}\t", evenNumber);
}
‫ﻛﻮد‬
VB
Dim list As New List(Of Integer)()
list.AddRange(New Integer() {20, 1, 4, 8, 9, 44})
Dim evenNumbers As List(Of Integer) = list.FindAll(Function(i) (i Mod 2) = 0)
Console.WriteLine("Here are your even numbers:")
For Each evenNumber As Integer In evenNumbers
Console.Write("{0}" & vbTab, evenNumber)
Next
‫ﻛﻮد‬
: return value
:‫א\^لא‬nD‫ ع‬9‫א‬NP>،a7! true , false ‫و‬Ci$‫وא‬F.i‫د‬D‫א‬a7!@NNP>
232
C#
List<int> evenNumbers = list.FindAll((i) =>
{
Console.WriteLine("value of i is currently: {0}", i);
bool isEven = ((i % 2) == 0);
return isEven;
});
‫ﻛﻮد‬
...‫א‬$‫א‬G‫وذ‬،Z3H53^‫א‬Qe NNP>ًMQC
: Lambda ‫ﻣﻮاﺻﻔﺎت‬
.–‫א‬bILambdae9−
.Overrides‫و‬COverloadsK^3OOP‫د¨אل‬3™‫אم‬$+‫א‬5P>9−
.ًj7h‫
א‬q\‫جא‬N‫א‬Q‫ذ‬539$‫و‬i‫א\د‬F7‫'عא‬$Q$RAS.‫م‬$+9−
.ًMQC‫دא‬zD$‫א‬5P>‫و‬،IŠzToQ@‫'د'دو‬%‫و‬53$9
‫א‬KI‫دא‬−
.i,3‫א‬$‫א‬.i‫د‬D‫א‬QKReturn‫אم‬$+‫א‬Q9−
.LambdaU{}‫و‬CEnd$%'Q9−
.VBUOptinal‫אم‬$+‫א‬5P>9−
.Generic‫אم‬$+‫א‬5P>9−
Object Initializer Syntax ‫ﺻﻴﻎ اﻧﺸﺎء اﻟﻜﺎﺋﻨﺎت‬
.8
9‫*א‬jVI't‫א‬YO&'\‫א‬J! 5DQ^3‫א‬i$‫ض‬Na7!،‫س‬H$‫אא‬WSUً‫^
א‬K15
.G\‫وא‬F‫وא‬
: .net 2008 K.3‫א\^لאول‬
C#
public class Employee
{
private string _name;
private string _age;
private string _salary;
public string name
{
get {return _name;}
set { _name = value; }
‫ﻛﻮد‬
233
}
public string age
{
get {return _age;}
set { _age = value; }
}
public string salary
{
get {return _salary;}
set { _salary = value; }
}
}
VB
Public Class Employee
Private _name As String
Private _age As String
Private _salary As String Public Property name() As String
Get
Return _name
End Get
Set
_name = value
End Set
End Property Public Property age() As String
Get
Return _age
End Get
Set
_age = value
End Set
End Property Public Property salary() As String
Get
Return _salary
End Get
Set
_salary = value
End Set
End Property
End Class
‫ﻛﻮد‬
234
:ˆ‫س‬H‫د‬USNFt‫ א‬automatic property ‫אم‬$+‫ و‬.net 2008 03^‫א\^لא‬
C#
public class Employee
{
public string name{get;set;}
public string age{get;set;}
public string salary{get;set;}
}
‫ﻛﻮد‬
VB
Public Class Employee
Public Property name() As String
Get
End Get
Set
End Set
End Property
‫ﻛﻮد‬
Public Property age() As String
Get
End Get
Set
End Set
End Property
Public Property salary() As String
Get
End Get
Set
End Set
End Property
End Class
„‘ ‫'ل‬b'‫ א‬$Q ، .net 2008 53 $Q$Ž‫ א‬Object Initializer Syntax ‫אم‬$+‫ א‬03‫א\^ل א^ و‬
:‫ א‬KPT‫'د‬GPNˆ‫א‬U،7‫قא‬1‫א‬$]gOQNˆt‫*א‬jVœ‫א‬
C#
Employee e = new Employee();
e.Name="Ahmed";
e.Age=15;
e.salary=6000;
‫ﻛﻮد‬
235
VB
Dim e As Employee = New Employee()
e.Name = "Ahmed"
e.Age = 15
e.salary = 6000
‫ﻛﻮد‬
:NS$Q$Ž‫א‬
C#
Employee e = new Employee { Name = "Ahmed", Age = 15, salary=6000 };
‫ﻛﻮد‬
‫ﻛﻮد‬
VB
Dim e As Employee = New Employee With {.Name="Ahmed" ,.Age=15,.Salary=1500}
Anonymous Types ‫اﻻﻧﻮاع اﻟﻤﺠﻬﻮﻟﺔ‬
.9
nD f f' ‫س‬H$‫א א‬WS U ، .net 2008 U i$Q$Ž‫* א‬jVœ‫ א‬v, ‫س‬H$‫א א‬WS U Kb‫'א‬
.Anonymous Types
$ !‫אšن‬3‫א‬،XH,‫א‬U var FP‫אمא‬$+'gh‫
א‬q3oQNP3‫ אن‬NFN‫א‬nN9
‫'د‬P‫א(‘„א‬،3$7\‫א‬Uً‫ ^
א‬K‫א‬5،ًMQ‫'א‬g‫א'אع‬oQP3Ka7!Q'k‫'א‬gh‫
א‬q3
: ‫א‬
C#
var e = new { Name = "Ahmed", Age = 20 };
‫ﻛﻮد‬
VB
Dim e = New With {.Name = "Ahmed", .Age = 20}
‫ﻛﻮد‬
. ً b‫ א‬JO‫א‬oQ‫ون‬$ e.Age ‫ و‬e.Name iz‫א‬.P3b‫אšنא‬
:VjVI nD 'd 'g! ‫א‬W System.Object „‘ i,3 l‫د‬N‫ א‬Q Anonymous Types ‫! ً אل‬
.9‫א‬
236
.
‫ﻣﺎذا اﺳﺘﻔﻴﺪ ؟‬
9‫ א م و‬B 2 iz‫א‬. ‫ 'د‬N‫ض א‬ZON ، ‫ م‬9‫ א‬B 2N a J! oQ NNP> LINQ U
:‫א‬KPT‫ذ‬Q،2N‫א‬KP,ً‫א‬$Q$
C#
var result = from emp in employee select new { emp.Name, emp.Salary };
‫ﻛﻮد‬
VB
Dim namePriceQuery = From emp In employee Select emp.Name, emp.Salary
‫ﻛﻮد‬
: Key Properties ‫اﻟﺨﺼﺎﺋﺺ اﻟﻤﻔﺘﺎﺣﻴﺔ‬
H'3Ci$Q‫אد‬5DO\‫*א‬jVœ‫א‬o§
Y'gYD'Yi‫א\وא‬H7\a7!O\‫*א‬jVœ‫مא‬$+−
a7!iz‫א‬7Fj‫دא‬g!O\‫*א‬jVœ‫א‬.
q5P>9−
.'g¡‫א'אعא‬K%C53%Z\‫א‬l$'QW‫א‬Hash Code~‫א‬5FsgNFMQO\‫*א‬jVœ‫א‬a7!−
Equality ‫اﻟﻤﺴﺎواة‬
3} ©\‫'م א‬7Q‫'ل و‬g¡‫'ع א‬N‫@ א‬ON h‫
א‬q3 ‫'ن‬P 3$ND Q‫و‬3 'g¡‫ א'אع א‬h‫
א‬q3 ‫'ن‬P
:‫وطא‬T‫א‬Fg!h!'‫'ع‘ذא‬N‫@א‬O535Q
qF5Q
q3
.Scope‫@אل‬OUFgNDQV‫”א‬−
L
—zƒ‫א‬H73‫'ن‬P‫و‬GZ‫@א‬ONgNDQV‫'عو”א‬N‫وא‬9‫@א‬OFgVjVIe −
.f‫א‬
.C*jV+i‫د‬$)g!*jVœ‫@א‬O−
.K.‫א‬nDi$‫وא‬CbI‫'ع‬K>−
.a7!:ONQ‫و‬3‫'ن‬PQO3bIC>9‫'ل‬g‫'ع‬5DQV‫وא‬
...O\‫*א‬jVœ‫א‬.
q5P>9:C@N9F
237
Partial Methods
.10
53^‫א‬U JO‫א‬P3‫אن‬K،i$‫ وא‬71N3U JO‫א‬0s‫و‬nDً‫א‬4‫אšن‬$_،$Q$,HVI
J!0Q'SKi$Q$%J!@lWS‫אن‬nD‫ل‬$JO‫אא‬UPartialFP‫مא‬$+‫אن‬OPQ،0s'3
:ً ^3‫א‬KPT،IŠ‫ن‬P3 U!3
C#
partial class Car
{
}
‫ﻛﻮد‬
VB
Partial Class Car
‫ﻛﻮد‬
End Class
$ _ ، Partial Methods fQ 3 ‫ ًא‬Ip3g& ‫ ذ‬$ 5P‫ و‬، .net 2005 VD 03 ‫א‬WS ‫ن‬
:‫א‬KPT‫ذ‬Q،ًMQ‫א‬$‫نوא‬P3U‫א‬$‫א‬Pً‫א‬1M3
C#
partial void methodname(string parm)
{
‫ﻛﻮد‬
}
VB
Private Partial Sub methodname(ByVal parm As String)
‫ﻛﻮد‬
End Sub
oQ„‘%L‫ونא‬$k‫ودوא‬9‫א‬hJO‫*א‬jVIQ'1U ‫'ع^
ًא‬s'\‫אא‬WS‫!د‬C،ª Fً
.gN3i$Q$%+
238
Garbage Collector
.11
Qn3‫و‬i‫א‬W‫א‬UgNQ§QoNO‫_ ]ل‬NNP‫و‬،‡‫א‬..hJ!‫و‬h‫
א‬q3fN7‫א‬N‫و‬H‫ لد‬I
. GC ‫ وאل‬Object lifetime ‫אل‬SO3‫ ل‬I53‫س‬H$‫אא‬WSUgD G<f'J9‫א‬lWS،g!W
‫א‬WS„‘
TQ refernce XًPŸV0.‫ !¦ 'א‬OBJECT FROM CLASS J!535jPOQ$ND
.234‫ص‬I stack UًMQ‫א‬$%'Q reference ‫אאل‬WS، heap ‫אل‬U‫'د‬%'\‫א‬5jP‫א‬
:‫'א‬S1‫'نא¯لא‬P، stack ‫אل‬53 reference ‫אل‬fWQ‫א‬$‫א‬zg‫אوא‬234‫א— قא‬$
garbage ‫ אل‬dQ ، k TQ 53 ${ 9 t‫ א‬hNjP‫ א‬hJ} i‫א‬W‫ א‬±e f' L‫ א‬lWS U‫و‬
77L‫א‬U‫אو‬،3$+\‫—
א‬hJO‫א‬fWr‫'م‬7Q‫אא¯ل‬WS53 GC ‫ ًא‬HVI‫א‬:3QW‫وא‬collector
.234‫א‬KI‫دא‬53g‘‫'ل‬b'‫א‬P3$Q_t‫א‬hJO‫א‬0B fWr‫'م‬7Q'g!
GC 03 ‫ אšن‬3‫ א‬، ‫ אول ]ول‬3$+3 q‫
א א‬q3 fWr ‫'م‬7 ‫ض אن‬ZO\‫ א‬53 ‫ ن‬C++ ‫م אل‬Q‫ א‬U
.T‫ دونאن‬SWONQ‫م‬g\‫א‬K%€Rb!
53NjfWL GC Ki,3iH,‫א‬1Q9‫א‬WS0.‫א'א‬U، =null KF ‫'م‬7‫אن‬SًD',^9‫א‬L‫א‬
.ً ^3i‫א‬W‫א‬±e3$ND،gPR‫א‬NP>93(LU:!W:NP ،i‫א‬W‫א‬
GC ‫اﻟﻔﺌﺔ‬
.11.1
Pro X 53 iH'b lWS ، g3 ,\‫ א‬K3‫ א‬53 NPe t‫אول א‬$‫ א‬53 ‫د‬$D nD GC JO‫' א‬
:g3‫א‬$+‫وאلوא‬$‫א‬Csharp 2008
239
: Finalize()
K. ‫م‬g\‫ ™ א‬WON‫ و‬: overriding KFD NP> ، 5jP‫ א‬fW €.‫ص و‬N.‫ א‬53 E$L‫א א‬WS NP>
.5jP‫
א‬3$
:‫א‬KPT‫ذ‬Q
C#
class example
{
~example()
{
Console.Beep();
}
}
‫ﻛﻮد‬
240
VB
Class example
Protected Overrides Sub Finalize()
Try
Console.Beep()
Finally
MyBase.Finalize()
End Try
End Sub
End Class
‫ﻛﻮد‬
Operator Overloading
.12
53
q\‫^ ًא‬F!،gN37T\‫א‬hJO‫א‬nDhFD WONO+\‫א‬h 3\‫مא‬$+،Nj‫'אعא‬9‫א‬U
.‡‫א‬...v:‫א‬nD−،0B:‫א‬nD + K3\‫א‬gOQ Integer ‫'ع‬
.‫א‬WPS‫و‬،YV23$:‫א‬nDً ^3+
q\‫א‬gO String ‫'ع‬53h‫
א‬q\‫ ً א‬MQ‫א‬
:ً ^3‫א‬KPT Point ‫'ع‬53 Structure KFNF.'‫אšن‬
C#
public struct Point
{
private int x, y;
public Point(int xPos, int yPos)
{
x = xPos;
y = yPos;
}
}
‫ﻛﻮد‬
VB
Public Structure Point
Private x As Integer, y As Integer
Public Sub New(ByVal xPos As Integer, ByVal yPos As
Integer)
x = xPos
y = yPos
End Sub
End Structure
‫ﻛﻮد‬
241
53، 2N‫ א‬$ST‫אن‬:.'3،‫ط‬7N‫א‬v‫و‬0FŽ −‫אو‬+K3\‫אمא‬$+‫وא‬،‫ط‬7i$DoQ X%‫אšن‬
U‫א‬9‘،ً3FgB‫و‬C، y ‫אאل‬W‫ אو„و‬53^‫א‬17N‫א‬U x ‫אل‬v5DiHD‫'ن‬PQ‫ن‬C‫ض‬ZO\‫א‬
v1‫وא‬0FŽ‫א‬h 33 D$Q9 Point nF\‫ א‬structure ‫]ن‬¤$O]1IHnDA'KV 50.‫א'א‬
:ˆ‫ א‬structure ‫‘„אل‬v‫و‬0Bh 33!s‫'م‬7N‫אšن‬
C#
public struct Point
{
private int x, y;
public Point(int xPos, int yPos)
{
x = xPos;
y = yPos;
}
public static Point operator + (Point p1, Point p2)
{ return new Point(p1.x + p2.x, p1.y + p2.y); }
public static Point operator - (Point p1, Point p2)
{ return new Point(p1.x - p2.x, p1.y - p2.y); }
}
‫ﻛﻮد‬
VB
Public Structure Point
Private x As Integer, y As Integer
Public Sub New(ByVal xPos As Integer, ByVal yPos As
Integer)
x = xPos
y = yPos
End Sub
Public Shared Operator +(ByVal p1 As Point, ByVal p2
As Point) As Point
Return New Point(p1.x + p2.x, p1.y + p2.y)
End Operator Public Shared Operator -(ByVal p1 As Point, ByVal p2
As Point) As Point
Return New Point(p1.x - p2.x, p1.y - p2.y)
End Operator
End Structure
‫ﻛﻮد‬
:‫א‬KPT‫'د‬NP>‫אšن‬
242
C#
Point p3 = p1 + p2;
‫ﻛﻮد‬
VB
Dim p3 As Point = p1 + p2
‫ﻛﻮد‬
. Points ‫אل‬0BFRRV‫`א‬N‫א‬nDKVR
:i,3‫'د‬NP>ً MQC
C#
p2-=p1;
‫ﻛﻮد‬
VB
p2-=p1
‫ﻛﻮد‬
53 Static function oQnD A'ً‫א‬H‫د‬.‫'ن‬P5C 'S‫'ع‬s'\‫אא‬Wg ˆQF!:DfN3IŠ
.K33 overloading KFDK%‫א‬
53 ‫ ذ 'ع‬KFD NP> K ، overloading KFD 5P> 53 a7! v1‫ وא‬0FŽ‫ א‬h 33 €
:a7!XH,‫א‬U−−‫و‬++ً ^F!،h 3\‫א‬
C#
public static Point operator ++(Point p1)
{ return new Point(p1.x+1, p1.y+1); }
public static Point operator --(Point p1)
{ return new Point(p1.x-1, p1.y-1); }
‫ﻛﻮد‬
‫א‬$ overriding KFD 03 ً 7 NF 3 K^3 77 =! ‫و‬C == KFD‫ و‬i‫وאل א\وא‬$ N 3‫@ א‬O
:‫א‬KPT‫א‬$‫א‬lWSnDNS$FN،Equals
C#
public override bool Equals(object o)
{
return o.ToString() == this.ToString();
}
public static bool operator ==(Point p1, Point p2)
{
return p1.Equals(p2);
‫ﻛﻮد‬
243
}
public static bool operator !=(Point p1, Point p2)
{
return !p1.Equals(p2);
}
VB
Public Overloads Overrides Function Equals(ByVal o As Object) As Boolean
Return o.ToString() = Me.ToString()
End Function
Public Shared Operator =(ByVal p1 As Point, ByVal p2 As Point) As Boolean
Return p1.Equals(p2)
End Operator
Public Shared Operator <>(ByVal p1 As Point, ByVal p2 As Point) As Boolean
Return Not p1.Equals(p2)
End Operator
‫ﻛﻮد‬
:h 3\‫א‬lWS53 overloading KFDP3‫אن‬${‫א‬WPS‫و‬
Pointers ‫اﻟـﻤﺆﺷﺮات‬
.13
!W5P_'3C،W5P_ '3C، pointer nN3¤H$$]€]!، C++ 2343€N‫‘ذא‬
*§t‫ وא‬pointer type ‫ًאل‬MQ‫א‬¤NS، refernce type ‫ وאل‬value type ‫!‘„אل‬s9:‫א‬f‫אن‬
.i‫א‬W‫א‬UN3 53‫‘„א‬iH,9
‫ذ‬KF unsafe code ‫אم‬$+91MK،1‫'دא‬P‫א‬Ug3K3 5‫א‬:!3‫ول‬CQ‫א‬$
g3‫א‬$+ON vFً9‫אو‬.‫א‬W، pointers ‫אل‬03K3ًs‫א‬Z!‫א‬F5XH,‫ن א‬C
:‫א‬KPT
244
:ً ^3‫א‬KPT pointers ‫אل‬03K3Q‫ 'د‬NP>‫'دאœص‬P‫ لא‬I53‫وאšن‬
C#
class Program
{
static void Main(string[] args)
{
unsafe
{
// Work with pointer types here!
}
// Can't work with pointers here!
}
}
‫ﻛﻮد‬
:^3‫א‬U‫'ص‬q‫אن‬K. pointers‫אل‬03K3‫א‬nDNNt‫א א‬h‫אدوא‬nDfN‫אšن‬
‫אم‬$+9‫א‬
h‫אدوא‬
pointeroQ‫م‬$+
*
i‫א‬W‫א‬U
q\‫'אنא‬ND !\
&
t‫ א‬JO‫ א‬KI‫ دא‬3 K7 „‘ ‫'ل‬b' ‫م‬$+
->
pointer ‫אل‬g‘
TQ
.:! I‫و‬H7\‫وא‬h‫א‬,p\‫א‬5Fs¤R‫א‬
!=،== ،- ،+ ،-- ،++
UKF‫'א‬g@ON‫'ن‬PQ5 unsafe code ‫אل‬03K3‫אنא‬oTPf' ‫س‬H$‫אא‬WSUH‫א‬F‫א‬03
.Q‫אد‬XH,‫ ل‬I 53safe code
245
‫ ؟‬unsafe code ‫وﻟﻜﻦ ﻟﻤﺎذا اﺳﺘﺨﺪم ال‬
.F‫—אض‬C
•
. pointers ‫ ل‬I53ً b‫א‬KFt‫ א‬COM Components ‫ אوאل‬dll's ‫™אل‬3‫א‬$+‫א‬
•
.i‫א‬W,\‫'لא‬b'‫ ل א‬I53N3Fg3D‫و‬z‫אدא‬Y‫)و‬
•
‫ ن‬Image Processing hFD ™ KF 3 iH'b pixels iz‫א‬. zN‹C‫ و‬N ‫ج אœص‬+‫وع א‬T3 U
Q'FD‫'ن‬P€gNP‫و‬،P‫وא‬iz‫א‬7H'Vbœ‫ א‬SetPixel ‫ و‬GetPixel ‫אمدوאل‬$+‫א‬NP3
‫ אل‬03 K3‫ وא‬unsafe code ‫אم‬$+ ‫ ن‬KQ$‫ א‬KL‫ א‬، 7Q1‫ א‬lWg pixels ~‫ א‬nD H‫و‬F ‫ ًא‬$%
‫ و‬Getpixel 7Q1 YH'bv1‫^ ً'د‬3X%،iH'Vbœ‫ א‬pixels ‫אل‬nDH‫و‬Fi,3pointers
... ‫ق‬HO4IC‫ و‬،pointers ‫אم‬$+AICi3g%‫س‬H$‫א‬lWS$‫و‬،setpixel
...‫اﻵن ﺳﻨﻌﻮد ﻣﺮة أﺧﺮى ﻟﻨﺸﺮح ﻣﻦ اﻟﺒﺪاﻳﺔ‬
:‫א‬KPT pointer oQ‫אšن‬NP>
C#
public Node* Left;
‫ﻛﻮد‬
:‫א‬KPT unsafe ‫'ع‬N‫א‬53 class ‫ אو‬structure oQP3K،a7!‫א‬WS@
C#
public
{
public
public
public
}
‫ﻛﻮد‬
unsafe struct Node
int Value;
Node* Left;
Node* Right;
246
:ً MQ‫ودאא‬C
C#
public
{
public
public
public
}
‫ﻛﻮد‬
unsafe struct Node
int Value;
Node* Left;
Node* Right;
VB
unsafe static void SquareIntPointer(int* myIntPointer)
{
// Square the value just for a test.
*myIntPointer *= *myIntPointer;
}
‫ﻛﻮد‬
:‫א‬KPT & ‫אم‬$+Z3H‫א‬KN‫‘ذن‬،Z3H‫ א‬U
q\‫א‬oQ*N3$+‫א‬$.N\‫و‬
C#
SquareIntPointer(&myInt2);
‫ﻛﻮد‬
:ً ^3‫א‬KPT -> ‫م‬$+N Node ‫אل‬U Left q\‫'ل‘„ א‬b'ًMQC
C#
n->Left=5;
‫ﻛﻮد‬
‫ ؟‬VB.net ‫وﻣﺎذا ﻋﻦ‬
i) Marshal JO‫ '! א‬5P‫ و‬، i,3 h‫א‬,p\‫ א‬53 i‫د‬O9‫ א‬NP> 5! VB.net 2343 €N '
:C#‫'دא‬P‫ضא‬ZON،h‫א‬,p\‫_א‬D53Q.
C#
unsafe
{BitmapData bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width,
bitmap.Height),
‫ﻛﻮد‬
247
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
byte * pixel = (byte*)(void*)bmpData.Scan0;//the last syntax is equivalent to:
//byte* pixel = (byte*)bmpData.Scan0.ToPointer();
pixel[0] = 255;
pixel += 4;
pixel[0] = 0;
}
:‫א‬KPTVBUg71
‫ﻛﻮد‬
VB
Dim width As Integer = bitmap.Width
Dim height As Integer = bitmap.Height
Dim bmpData As BitmapData = bitmap.LockBits(New Rectangle(0, 0, width, height) _
, System.Drawing.Imaging.ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb)
Marshal.WriteByte(bmpData.Scan0, bmpData.Stride, 255)
Marshal.WriteByte(bmpData.Scan0, bmpData.Stride + 4, 0)
bitmap.UnlockBits(bmpData)
.‫א\^ل‬Gb$‫žو‬ PT‫א‬03***
Query Expressions
.14
HVI NS gD fN ، LINQ _D U ‫ אو„ وא‬i'1œ‫ א‬S Query Expressions ‫ אل‬4
K3‫א‬C$FN3‫د‬7‫'لא‬VOKbO‫א‬. K%pNF! .net 2008 h‫Ÿא‬53i$Q$%iF$Q$,
.h‫א‬$D‫'א‬.03O‫א‬
:ً ^3‫אא\^ل‬WSAN
C#
from d in developers
where d.Language =="C#"
select d.Name;
‫ﻛﻮد‬
VB
From d In developers
‫ﻛﻮد‬
248
Where d.Language ="C#"
Select d.Name
:‫א‬KPTً7gnDh‫'د‬t‫ مא‬9‫ א‬BA')'SaM‫א‬WS
SQL Server
select name from developers where language=’C#’
‫ﻛﻮد‬
‫إذن ﻟﻤﺎذا ﻫﺬا اﻟﺸﻜﻞ اﻟﺠﺪﻳﺪ ؟‬
KP, nD 2N ‫ و'د‬h‫ א‬i$D. U SWON ‫ م‬9‫ א‬B ‫ل‬H ‫'م‬7 N ˆ‫ א‬U
.g4‫'م‬7t‫ א‬q‫א‬hQ')53z%‫ م‬9‫א‬KB€Rb‫אšنא‬3C،5PQFg3‫و‬CDataReader
:‫א‬WSzƒ‫ لא‬$QH'53$ ! LINQ nDKF
C#
using System.Linq;
‫ﻛﻮد‬
VB
Imports System.Linq
‫ﻛﻮد‬
nDhF‫ ™א‬X`N‫א‬W،gN3z%C‫و‬C Array 5DiHDSh‫א‬i$D.‫אن‬nD LINQ ‫אل‬$F
:ً ^3‫א‬KPT‫ضא‬ZON، Array ‫אل‬
‫ﻛﻮد‬
C#
string[] userNames = {"Ahmed", "Ali","Mohammed", "Ahmed","Ramy", "Khaled"};
VB
Dim userNames As String() = {"Ahmed", "Ali", "Mohammed", "Ahmed", "Ramy",
"Khaled"}
‫ﻛﻮد‬
‫ﻣﻼﺣﻈﺔ‬
„‫' אن אو‬S ‫ق‬HO‫ א‬، Query Expressions ‫ ل‬S‫ א‬3 H$. LINQ ~ S‫ א‬9 NS c] ‫ ^
ًא‬¤‫ אذ‬5
‫ق‬1‫ دون א‬a7! P‫ א‬O F g! ^‫ א‬3‫ א‬gD‫ א'א‬o+} h‫ א‬$D‫'א‬. 03 K3 bI
.h‫ א‬$D‫'א‬.*jVœ
249
BzN‫ول‬RN‫אšن‬،IŠ z,C‫'ن‬P$.، XML o3‫'ن‬P$.،h i$D.‫'ن‬P$.!'OV\‫א‬lWS
"Ahmed"‫و‬t‫א‬zƒ9‫א‬iz‫א‬7 ‫א م‬
C#
IEnumerable<string> subset = from users in userNames
where users == "Ahmed" orderby users select users;
‫ﻛﻮد‬
VB
Dim subset As IEnumerable = From users In userNames Where users =
"Ahmed"OrderBy users Select users
‫ﻛﻮد‬
:‫ א‬KPTgD‫אšن‬NP>‫א‬W، array ً MQ‫'نא‬P2N‫א‬
C#
foreach (string s in subset)
Console.WriteLine("Item: {0}", s);
‫ﻛﻮد‬
VB
For Each s As String In subset
Console.WriteLine("Item: {0}", s)
Next
‫ﻛﻮد‬
E ‹53‫א'ل‬zƒ9‫ضא‬RRb‫א‬FŽ!‫א‬W، C# ‫دوאل‬53‫אمאدא‬$+‫ א‬01NP>
:f‫و‬
C#
IEnumerable<string> subset = from users in userNames
where users.Length > 3 orderby users select users;
‫ﻛﻮد‬
VB
Dim subset As IEnumerable = From users In userNames Where users.Length > 3
OrderBy users Select users
‫ﻛﻮد‬
2N‫אنא‬K753^‫א‬5D€N 'ًb'VI،S(‫א‬h‫!'عא‬3nDً‫א‬H‫د‬.‫'ن‬P9$.ًMQC
9}HًMQ‫א‬،ً7SN,t‫ א‬Data Type ‫ون‬$ Dim ‫وאل‬C var ‫ אل‬i$j!Ng(NS،J!‫'ن‬PQ‫אن‬$9
ˆ‫س‬H‫ د‬UًMQ‫א‬SN,t‫ وא‬Nullable Types ‫אل‬i$j!NS0%ZN‫א‬W`N‫ م‬9‫ א‬B‫'د‬
250
.3‫د‬.3UgDfN‫و‬، Lambada ‫אم‬$+KFŽ‫א‬lWSPAIC7Q
Preprocessor Directives
.15
:ً ^3‫א‬KPT‫א‬nD^3U h‫ دوא‬n‫و‬CiSŽ‫א‬0QHTF‫אو‬23‫א‬4ROV‫ ل‬Iً‫^
א‬
g. —‫وא‬gR!QrN3‫ود‬$5Fs‫'אد‬9‫א‬53D'F0s' 7Qg‫א‬fFD$nD€N‫و‬
Regions ‫אل‬lWS‫ن‬C‫س‬H$‫אא‬WSU:!3‫אن‬9‘،‫'د‬P‫א‬zN‹C¼Q'T‫م א‬$D‫ن‬FM'g
.‫س‬H$‫א א‬WSUً VOgDfNt‫ א‬Preprocessor Directives ‫אل‬53D'FSg! I‫و‬
#region, #endregion
.15.1
:ً ^3‫א‬KPTg5P>،ً7‫ذ‬F‫ אœص‬cs o3U ‫'د‬P‫א‬g(3ˆNi‫د‬D‫م‬$+
C#
#region "Class Employee"
public class Employee
{
private string _name;
private string _age;
private string _salary;
public string name
{
get { return _name; }
set { _name = value; }
}
public string age
{
get { return _age; }
set { _age = value; }
‫ﻛﻮد‬
251
}
public string name
{
get { return _salary; }
set { _salary = value; }
}
}
#endregion
VB
#Region "Class Employee"
Public Class Employee
Private _name As String
Private _age As String
Private _salary As String
Public Property name() As String
Get
Return _name
End Get
Set
_name = value
End Set
End Property
Public Property age() As String
Get
Return _age
End Get
Set
_age = value
End Set
End Property
Public Property name() As String
Get
Return _salary
End Get
Set
_salary = value
End Set
End Property
End Class
#End Region
‫ﻛﻮد‬
252
:ً ^3‫א‬KPTًF(N3¤‫'ن'د‬PQr ،f1‫א‬53g. —‫وא‬gR!NP>‫אšن‬
#if, #elif, #else, #endif
.14.2
N3h9U‫'د‬P‫א‬53N3z‫א‬%‫א‬WON‫م‬$+‫و‬، Conditional Code Compilation ‫א‬gDˆ1Q
‫'د‬P‫א‬GP Release ‫€אل‬.‫و‬U@‫ و‬Debug ‫€אل‬.‫و‬9‘a7!KFQ9‫'د‬P‫א‬53z%KŽ ً ^F!،a7!
‫א‬KPT
C#
#if DEBUG
Console.WriteLine("App directory: {0}",
Environment.CurrentDirectory);
Console.WriteLine("Box: {0}",
Environment.MachineName);
Console.WriteLine("OS: {0}",
‫ﻛﻮد‬
253
Environment.OSVersion);
Console.WriteLine(".NET Version: {0}",
Environment.Version);
#endif
VB
#If DEBUG Then
Console.WriteLine("App directory: {0}", Environment.CurrentDirectory)
Console.WriteLine("Box: {0}", Environment.MachineName)
Console.WriteLine("OS: {0}", Environment.OSVersion)
Console.WriteLine(".NET Version: {0}", Environment.Version)
#End If
‫ﻛﻮد‬
. elif ‫ و‬else ‫אم‬$+‫א‬5P>7Q1‫@א‬ON
#define, #undef
.15.3
‫ص‬I symbol oQNP>‫אو‬، Debug K symbol oQNP> ً ^3،Y3 symbol oQ‫م‬$+
KFD Q ‫'د‬P‫א א‬WS ‫ אن‬cQ Symbol oQ ‫^ ص‬3 ‫ א\^ل א‬، ً 79 :3‫א‬$+‫ ] א א‬
. Mono nDa7! :Debug
:‫א‬KPT‫'د‬NP>ً79
C#
‫ﻛﻮد‬
254
#define DEBUG
#define MONO_BUILD
using System;
namespace PreprocessorDirectives
{
class Program
{
static void Main(string[] args)
{
#if MONO_BUILD
Console.WriteLine("Compiling under Mono!");
#else
Console.WriteLine("Compiling under Microsoft .NET");
#endif
}
}
}
VB
#Define DEBUG
#Define MONO_BUILD
Imports System
Namespace PreprocessorDirectives
Class Program
Private Shared Sub Main(ByVal args As String())
#If MONO_BUILD Then
Console.WriteLine("Compiling under Mono!")
#Else
Console.WriteLine("Compiling under Microsoft .NET")
Dim INDEXERS As n, OPERATORS As n, [AND] As n
POINTERS
413
#End If
End Sub
End Class
End Namespace
‫ﻛﻮد‬
255
XML Commenting
.16
،i
P‫א‬0QHT\‫ א‬Uًb'VIFS‫א‬Q—Uً‫א‬3C$Q‫'אد‬ Comments KFD‫!¦ن‬0.‫א'א‬U
$ '‫ و‬n :D ‫ل‬F9‫ وא‬¤‫! 'د‬3 $gŽ‫ א‬53 K7 IŠ *+, ‫ א‬01Q F ¤‫ 'د‬.‫א‬3 01
.‫ ًא‬$%Q' iZO‫'د‬P‫@א‬OUKF‫א‬5DO.'
‫ א‬KPT Comment ‫אل‬KFDQ،‫وس‬H$‫א‬lWShQ‫א‬$UN!DF‫و‬
C#
// here we will do something, set x=startvalue
x = FirstClass.Default();
‫ﻛﻮد‬
VB
' here we will do something, set x=startvalue
x = FirstClass.Default()
‫ﻛﻮد‬
Q‫א‬3 i$D N !'Q } XML X'] Comments ‫ אل‬53 NNPe ، i$Q$% 7Q nD fN ‫אšن‬
.‫س‬H$‫ لא‬IgDfN
‫ﻣﻼﺣﻈﺔ‬
. javadoc ‫ من خالل‬Java ‫من اوائل اللغات التي طبقت ھذه الطريقة كانت‬
W‫'دوא‬PbIh3 DC0s‫و‬01 3 ‫א‬lWS0s‫و‬$،///0s‫ لو‬I53Q‫א‬$‫ذ‬Q
KMOQt‫א‬7‫א‬bN‫א‬53D'F¤NS، XML ¨‫د‬3ˆ1Q‫ دאم‬3 XML ‫ن‬CnDً7903K3‫א‬
.SO\‫ א‬$'g3‫א‬$+‫א‬
‫אم‬$+9‫א‬
VN‫א‬
o†ax ‫ض‬Q‫ن‬C$9ˆ ‫אنא‬$Q$R
<c>
‫'د‬P :3K3‫א‬19‫دא‬$‫אن‬$Q$R
<code>
X'P\‫'دא‬P‫א‬vT‫^ل‬3$Q$
<example>
‫א‬WS 5D 2N ‫ אن‬5P> t‫ א‬z1I‫ وא‬h‫א‬zN^9‫ א‬nD 'd W‫ א‬o\‫א‬
<exception>
JO‫و א‬C‫'د‬P‫א‬
256
Documentation‫אل‬KI‫אولدא‬$%Fj.‫אج‬H‫אد‬
<list>
Y3Z3HvT
<param>
Y3 zŽQFL‫א‬Kj‫و‬ob‫و‬
<permission>
Build‫אل‬h‫א‬HI
<remarks>
return;‫א‬$‫א‬2ob‫و‬
<returns>
Documentation‫אل‬53IŠzŽIŠa‫א‬H
<see>
(ً MQ‫)א(א‬5P‫و‬،ˆ‫א‬K^3
<seealso>
v‫و‬T\‫ א‬z`B‫א‬ob‫و‬
<summary>
N3bIob'
<value>
‫ ﻣﺎ ﻫﻲ اﻟﻔﺎﺋﺪة اﻟﺘﻲ ﺳﺘﺠﻨﻴﻬﺎ إذا اﺳﺘﺨﺪﻣﺖ ﻫﺬه اﻟﻄﺮﻳﻘﺔ‬، ‫واﻵن‬
‫ﻻ ﻣﻦ اﻟﻄﺮﻳﻘﺔ اﻟﺘﻘﻠﻴﺪﻳﺔ ؟؟؟‬
ً ‫ﺑﺪ‬
:ً ^3YO&'\‫א‬JO Q3ً ^3X%،ً9‫و‬C
C#
/// <summary>
/// Employee Class of the company
/// </summary>
partial class Employee
{
/// <summary>
///
/// </summary>
/// <param name="Firstname">first name of the employee</param>
/// <param name="Lastname">last name of the employee</param>
/// <param name="age">age of the employee</param>
public Employee(string Firstname, string Lastname, int age)
{
}
}
‫ﻛﻮد‬
VB
''' <summary>
''' Employee Class of the company
''' </summary>
Partial Class Employee
‫ﻛﻮد‬
257
'''
'''
'''
'''
'''
'''
<summary>
</summary>
<param name="Firstname">first name of the employee</param>
<param name="Lastname">last name of the employee</param>
<param name="age">age of the employee</param>
Public Sub New(ByVal Firstname As String, ByVal Lastname As String, ByVal age As
Integer)
End Sub
End Class
:‫א‬iH'V‫א‬ª9،‫'د‬P‫א‬KFD‫אšن‬X%‫و‬
‫؟‬W@‫א‬،7Q!43.ًRs‫وא‬g(Q‫'د‬P‫א‬b‫א‬،‫ق‬HO‫(€א‬9 KS
: Documentation ‫ﻧﻘﻄﺔ أﺧﺮى‬
lWS nD ‫د ًא‬FD‫ א‬D‫و‬T\ 3 Documentation ‫אج‬I‫ א‬NP> ، Build ‫ אل‬h‫א‬HI 5Fs 53‫ ً و‬MQ‫א‬
:‫א‬KPT XML o3‫אج‬HI.‫ و‬Build HI.‫وع‬T\‫*א‬jVI53 ‫א‬W،‫א''م‬
258
:‫א‬WSK^3ًJ,$`،lHI€F.W‫א‬o\‫אא‬Wk‫'ل‬b'‫ א‬X%
: ‫ ﻣﺮة أﺧﺮى‬Documentation ‫ﻧﻘﻄﺔ ﺛﺎﻟﺜﺔ‬
5P> 5P ، 3'gO3 qV ˆ‫ א‬XML ‫ אل‬KQ'R s‫א‬Z!‫ א‬i‫ אدא‬Visual Studio 2008 !'Q 9 o :iH'V‫א‬lWSK^3 „‘ˆ‫א‬o\‫א‬KQ'R NDoc K^3i‫دא‬C‫אم‬$+‫א‬
259
... Comments ‫אل‬53a7! ‫א‬WSK
:‫א‬a‫אא‬53Sourceforge‫אل‬nD+„‘Kb'‫א‬NP>
‫رابط‬
http://ndoc.sourceforge.net/
.net assemblies
.17
F! g! 9‫ط א‬7N‫ א‬fN NNP‫ ^
ًא و‬g! K1 5 ، .net assemblies ‫ אل‬03 iZO‫ א‬lWS $D'3
msdn ‫ ل‬I53gND$Q\‫א‬nD‫ ع‬9‫א‬NP>
namespace ‫اﻟـ‬
.17.1
i$Q$Ž‫א‬QHT3U‫ًو‬3‫אدو‬W،™‫א‬gMA‫אن‬: h'P\‫א‬0FŽ5P> namespace ‫@אل‬OU
h'P30FŽ $'3 namespace K%‫א‬
C#
namespace example
{
‫ﻛﻮد‬
260
class someclass
{
void method(){
}
}
}
VB
Namespace example
Class someclass
Private Sub method()
‫ﻛﻮد‬
End Sub
End Class
End Namespace
7‫אא‬$‫א‬5Fs‫'دא‬P‫א‬NP>5!،IŠ namespace U classCar J!NQ$‫'ن‬3C
:method
C#
void method()
{
classCar x=new classCar();
}
‫ﻛﻮد‬
VB
Private Sub method()
Dim x As New classCar()
End Sub
‫ﻛﻮد‬
‫א‬KPTJO‫א‬oQ 535PF example K import KFDNNP>5P
C#
using example;
namespace example
{
class someclass
{
void method(){
}
classCar x=new classCar();
}
}
‫ﻛﻮد‬
261
VB
Imports example
Namespace example
Class someclass
Private Sub method()
‫ﻛﻮد‬
End Sub
Private x As New classCar()
End Class
End Namespace
Default Namespace ‫ﺗﻐﻴﻴﺮ ال‬
.17.2
:s‫א‬Z!9‫א‬zƒ9‫
لא‬q
Format of a .NET Assembly ‫ﺷﻜﻞ ﻣﻠﻒ اﻻﺳﻤﺒﻠﻲ‬
.17.3
bN‫א‬53‫'ن‬PQƒ9‫א‬oP3‫ن‬Cª ‫אن‬NP>ً ^3 dumpbin.exe Xƒ9‫א‬o3O€F.‫‘ذא‬
:‫א‬
Win32 file header
53KqT‫(א‬nDlWONO‫ و‬dll ‫ אم‬GUI ‫ אم‬console 'SKS،o\‫אא‬WS‫'ع‬5Dh3'3$`NS
. ‫وز‬$NQ‫و‬
CLR file header
262
‫ אل‬7Q nD 'd ، gFD$Q ‫ אن‬.net application $ 9 t‫ א‬h3'\‫ א‬nD 'd
.:! I‫و‬:3$D53 resources ‫'دאل‬%‫وو‬managed file
Q3'zN‫€ج‬N3‫‘ذא‬A'g3K35،Y7‫ א‬Y17N7‫א‬h3'\‫^
אًא‬Fg9
.net .KFDJ €‫ص‬I
CIL code
‫‘ن‬K73‫س‬H‫د‬gND‫'ن‬P،ً7gND N‹$t‫ א‬JIT ‫אم‬$+ً‫א‬H'!:BQ،4‫'دאœص‬P‫א‬
‫א‬z,
Type metadata
.Ug3$+t‫א‬%Hœ‫'אع א‬9‫א‬KbOnD'
An assembly manifest
.:! I‫ƒو‬9‫א‬H‫א‬$b‫د א‬$،O+\‫ƒא‬9‫א‬hO3Ya‫אא‬
Optional embedded resources
.:! I‫و‬h'7Q‫وא‬H'b„‘
T‫س‬H'Q‫א‬hO3 53‫د‬$D‫א‬nD'd‫אن‬5P>ƒ‫א‬o3‫א‬
Private Assemblies
.17.4
visual ‫אل‬RQ5،ˆ1‫אو א‬234‫א‬H3‫ ل‬I53KFQƒ‫א‬o3 Private Assemblies ‫אل‬
.:ND 234‫ א‬H3 U R a7! ، IŠ ‫ن‬P3 C U ‫ אو‬Z®‫ א‬U z‫ 'א‬o\‫א א‬WS 5D studio
i,3 : setup KFD$ˆ1‫א‬K7NP>ًMQ‫א‬،:3hO\‫א‬lWSfWQfW U
.‫(م‬N‫•*א‬z,C03K3Q9:'
.‫'ع‬N‫אא‬WS53SgF‫'م‬7t‫ א‬dll ‫אوאل‬s‫א‬Z!9‫ƒא‬9‫ א‬hO3
263
Shared Assemblies
.17.5
^‫א‬03K3‫א‬o\‫نא‬P3¦‫‘ن‬K،‫א‬WS dll ‫אل‬o3‫م‬$+Q53¤$‫'نو‬P 5NS،^‫'عא‬N‫'א‬S‫א‬WS
ƒ9‫ א‬o3 U S${ 3 i‫د‬D ، System.Windows.Forms.dl ً ^3 ، ‫ز‬gŽ‫@ א‬O nD ˆ1 53
.fW03g!WQ9‫وزو‬$NQ'‫א‬U‫'د‬%'\‫א‬
9no\‫אא‬Wk unique ‫'د א‬%‫و‬iH‫و‬s'S‫'ع‬N‫אא‬WS53ƒ‫א‬o3zT–g3K317‫ول‬C
COM globally unique fQ 3 ¤NS ‫ ن‬COM‫م אل‬QC ، AI‫ א‬hO\‫ א‬. 03 XHMQ
fQ 3 lz1D‫ א‬D b‫ אšن א‬، $Q$% COM KP O† zƒ‫ א‬z1D‫ א‬Q ، identifier (GUID)
:l$Q$U‫א‬h'P\‫א‬¤ZT‫م‬.H9‫א‬53€ 128 :'‫و‬$Q9W‫ وא‬strong name .ƒ9‫א‬o3‫א‬
•
.ƒ9‫א‬o3+
•
AssemblyKeyFile Ui‫'د‬%'\‫א‬- public key value
•
. AssemblyCulture UF.‫א‬h‫אد‬$D‫'دאא‬%‫و‬U
•
. public key ‫ƒوאل‬9‫א‬o3 hQ')Y hash ‫אم‬$+:NQ'PQdigital signature
•
:ً ^3‫א‬KPT SDK’s sn.exe 234‫مא‬$+ public key KF
‫ﻛﻮد‬
sn -k MyTestKeyPair.snk
264
Multithreading ‫اﻟﻤﺴﺎرات اﻟﻤﺘﻌﺪدة‬
.18
‫ﻣﻘﺪﻣﺔ‬
.18.1
@OUFg353^‫א‬WONP3‫א‬cQ 3'S‫ و‬multitasking systems g]^Q$L‫א‬KqT‫(א‬f
.€.'‫@א‬OU23‫ א‬i$DKqTP3‫ن‬C${‫א‬W،€.'‫א‬
53^‫א‬WONnDH‫د‬.$‫א'א‬234‫אنא‬23‫א‬4‫™א‬Uª NP،ًs‫א‬Z!‫'ع א‬N‫אא‬WS53 .net 23‫א‬
. multithreading fQ3‫א‬WS،‫ض‬H3
‹]Fk‫'ن‬PQ‫ن‬C‫€دون‬.'‫@א‬OUFD
*+,53^‫א‬03E$R‫
אوא‬3P‫אمא‬$+‫وא‬Q$L‫وא‬hO3‫ل‬H‫ א‬Q`N\‫א‬23‫אن‬${‫א‬W
gM 5D$‫א'א‬234‫א‬KI‫مدא‬g\‫א‬lWSKVOQ5PQ_':Dً‫א‬H‫د‬.`N\‫א‬5PQ_3 'S‫و‬،€.'‫@א‬ON
.L‫א‬NH‫'ند‬FM3'S‫א‬WS،
‫ﻣﻼﺣﻈﺔ‬
‫ لذا قم‬، System.Threading‫جميع األوامر التي سنتعامل معھا ھنا تقع تحت نطاق األسماء‬
ً ‫باستيراده أوال‬
:S ‫א‬WSzƒ9‫لא‬KI‫دא‬9‫א‬bN‫א‬
ob'‫א‬
VN‫א‬
:3K3‫وא‬$Q$% Thread oQ
Thread
gNF!K3‫א‬k5P> Threads ‫אل‬53D'F
ThreadPool
Threadh9i$DnD'dEnum
ThreadState
Thread UWON‫ א‬z$
ThreadStart
Thread ‫אאل‬WSQ'‫אو‬$Q$
ThreadPriority
265
:„‘!s9
Semaphore .1
Mutex .2
Monitor .3
‫א‬zŽ‫א‬UgDfNt‫א‬53‫אא‬h3QH'Ž‫א‬53D'FS‫و‬
synchronization ‫اﻟﺠﻮرﻳﺰﻣﺎت اﻟﺘﺰاﻣﻦ‬
.18.2
Thread 53^FQ9r Synchronization 53‫אא‬hF‫م‬$+h3QH'Ž‫سא‬9‫ א‬US‫و‬
:NS53z$‫א‬5P>h3QH'Ž9‫ א‬lWSnDf‫א‬53$Q\،€.'‫@א‬OUH‫د‬V\‫@א‬O„‘‫'ل‬b'
‫رابط‬
http://en.wikipedia.org/wiki/Semaphore_(programming)
http://en.wikipedia.org/wiki/Mutual_exclusion
http://en.wikipedia.org/wiki/Monitor_(synchronization)
System.Threading.Thread
.18.3
JO‫א‬lWSh'P3، gD O+\‫א‬N3g3WON‫ و‬threads zT‫א‬N،‫א‬WSzƒ9‫لא‬U9‫ א‬JO‫א‬
:S9‫א‬
ob'‫א‬
‫'ن‬P\‫א‬
€.'‫א‬53iZO thread ‫אل‬KFDo.'
Sleep()
9‫אم‬KFQ‫ زאل‬3 thread ‫‘ذאنאل‬s'F.
IsAlive
backgroundUKFQ thread ‫‘ذאنאل‬
IsBackground
266
L‫א‬Q'‫אو‬
Priority
Thread‫אل‬
ThreadState
thread‫אאل‬
Name
‫وج‬I
Abort()
joinUE$L‫ א‬E‫و‬$n thread ‫אل‬KFDo.'
Join()
:!7Q‫א‬$KF‫א‬fNJ‫א‬
Resume()
„‫אو‬iF KF‫א‬z$
Start()
ً .p3KF‫א‬f7Q‫א‬
Suspend()
fNJ9S$‫'د‬،€.'‫@א‬OU YFg3WONQ‫אن‬nN3nD‫ل‬9$ Q{KFQ‫א‬$‫'م‬7N
.‫'ع‬s'\bœ‫א‬SO\‫א‬v,
:‫'دא‬P‫`א‬.
C#
static void Main(string[] args)
{
order1();
order2();
Console.ReadKey();
}
static void order1()
{
for (int i = 0; i < 100; i++)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(i.ToString() + " ");
}
}
static void order2()
{
for (int i = 100; i > 0; i--)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(i.ToString() + " ");
}
}
‫ﻛﻮد‬
267
VB
Private Shared Sub Main(ByVal args As String())
‫ﻛﻮد‬
order1()
order2()
Console.ReadKey()
End Sub
Private Shared Sub order1()
For i As Integer = 0 To 99
Console.ForegroundColor = ConsoleColor.Green
Console.Write(i.ToString() + " ")
Next
End Sub
Private Shared Sub order2()
For i As Integer = 100 To 1 Step -1
Console.ForegroundColor = ConsoleColor.Red
Console.Write(i.ToString() + " ")
Next
End Sub
،‫ز‬N‫‹ א‬53‫و‬$DV‫א‬D'S1‫א‬2N‫א‬،ً‫ز‬N‫ًو‬Q$DV‫م‬.H‫א‬D1 ‫'م‬7Qs‫'وא‬SF‫'د‬P‫א‬
:ً ^3‫א‬KPT2jN‫א‬,,‫'ن‬P ˆQO"^‫وא‬MI„‫אאو‬$‫א‬2jDQYU
oQ ‫'م‬7N ‫ אšن‬3C ، zg9‫ א‬n ^‫ ‹ א‬53‫ و‬zg9‫ א‬n „‫א אو‬$‫ א‬WON Q ، 1‫א א‬WS‫و‬
@OUH'‫و‬4‫ א‬nDSWONgN3$‫وא‬nD‫دא‬KWONQrWONO† threads
:ً ^3‫'دא‬P‫א‬،€.'‫א‬
C#
static void Main(string[] args)
{
System.Threading.Thread t1 = new System.Threading.Thread(order1);
‫ﻛﻮد‬
268
t1.Start();
System.Threading.Thread t2 = new System.Threading.Thread(order2);
t2.Start();
Console.ReadKey();
}
static void order1()
{
for (int i = 0; i < 100; i++)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(i.ToString() + " ");
}
}
static void order2()
{
for (int i = 100; i > 0; i--)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(i.ToString() + " ");
}
}
VB
Private Shared Sub Main(ByVal args As String())
Dim t1 As New System.Threading.Thread(AddressOf order1)
t1.Start()
‫ﻛﻮد‬
Dim t2 As New System.Threading.Thread(AddressOf order2)
t2.Start()
Console.ReadKey()
End Sub
Private Shared Sub order1()
For i As Integer = 0 To 99
Console.ForegroundColor = ConsoleColor.Green
Console.Write(i.ToString() + " ")
Next
End Sub
Private Shared Sub order2()
For i As Integer = 100 To 1 Step -1
Console.ForegroundColor = ConsoleColor.Red
Console.Write(i.ToString() + " ")
Next
End Sub
269
.2jN‫א‬AN‫אšن‬
‫ن‬C$`،2jN‫א‬X%‫و‬gN3$‫^ ً'א‬3 Priority ‫
אل‬qX%، i3KSF‫'ن‬P52jN‫א‬01
:ً ^3‫'دא‬P‫א‬،^‫א‬K.:N3zg9‫א‬QnD‫ א‬Q'‫אو‬Gb
C#
t1.Priority = System.Threading.ThreadPriority.Highest;
‫ﻛﻮد‬
VB
t1.Priority = System.Threading.ThreadPriority.Highest
‫ﻛﻮد‬
:‫א‬KPT2jN‫א‬V
.€.'‫אא‬WSUQ'SWON”5Q‫'د‬P‫نא‬C'S$ST‫א‬5P ،WON‫א‬Uh! I‫א‬$`
270
Priority ‫اﻷوﻟﻮﻳﺔ‬
.18.4
‫ ذو‬thread ‫אنאل‬،H'‫و‬4‫א‬nD threads ‫لאل‬I‫אد‬Q3$NDWON‫א‬Q'‫و‬C Priority ‫دאل‬$
: NQ$‫ضאن‬ZO‫'م‬gO\‫א‬GQ7،WONh‫א‬3‫د‬$n(dnD‫א‬Q'‫و‬9‫א‬
.A'V.Q'‫אو‬1Fg3 .1
.A'V.Q'‫אو‬2Fg3 .2
.‫א‬WPS‫و‬1‹،2‹،H'‫و‬41Fg\‫لא‬I‫אد‬QL‫ א‬lWSU
:‫א‬KPT3‫'نא‬PQ،K.‫א‬Q'‫אو‬h‫ ذא‬2Fg3‫ل'ن‬U3C
zg9‫א‬n‫א‬WPS‫و‬... 2Fg\‫א‬، 1Fg\‫א‬، 1Fg\‫ א‬، 1Fg\‫א‬، 2Fg\‫א‬، 1Fg\‫א‬، 1Fg\‫א‬، 1Fg\‫א‬
.FS$‫א‬53
‫ א'אع‬i$D${،NS53z$‫א‬NP>i‫د‬Q‫א‬h‫د‬HC'‘،H'‫و‬4‫א‬h3QH'Ž‫ א‬v,‫ن‬P3‫א‬WS@
: scheduling ‫אل‬53
‫رابط‬
http://en.wikipedia.org/wiki/Scheduling_%28computing%29
:‫ א‬enum ‫مאل‬$+NQ$Fg3C Priority $Q$R،AICi3‫'د‬
C#
public enum ThreadPriority
{
AboveNormal,
BelowNormal,
Highest,
Idle,
Lowest,
Normal, // Default value.
TimeCritical
‫ﻛﻮد‬
271
}
VB
Public Enum ThreadPriority
AboveNormal
BelowNormal
Highest
Idle
Lowest
Normal
' Default value.
TimeCritical
End Enum
‫ﻛﻮد‬
:ً ^3‫א‬KPT‫'د‬P‫א‬VQ‫و‬
C#
t1.Priority = System.Threading.ThreadPriority.Highest;
‫ﻛﻮد‬
VB
t1.Priority = System.Threading.ThreadPriority.Highest
‫ﻛﻮد‬
suspend ، i$\ WON‫ א‬f7Q9 sleep ‫אم‬$+‫ א‬P3 ‫ אن‬nN 9 ، 9‫ א‬0s‫ א\'א‬5D $‫ א‬K.
.‫س‬H$‫אא‬WkN,gC$t‫طא‬7N‫א‬53‡‫א‬...€.p3f7Q9
ParameterizedThreadStart
.18.5
5P،KVON3 thread USWONk start KF‫'م‬7‹53‫אو‬$‫ א‬HN‫א\^لאˆא‬U€(9
‫؟‬h‫א‬Z3HK7‫א‬$‫א‬lWS €'‫ذא‬3
:ً ^3‫א‬KPT ParameterizedThreadStart ‫אم‬$+ ،aKL‫א‬
C#
Thread t = new Thread(new ParameterizedThreadStart(functionname));
t.Start(parms);
‫ﻛﻮد‬
272
VB
Dim t As New Thread(New ParameterizedThreadStar(functionname))
t.Start(parms)
‫ﻛﻮد‬
‫ﻣﻼﺣﻈﺔ‬
‫ ولكن يمكن استخدام‬ThreadStart ‫لو كنت تود استخدام دالة تعود بقيمة فال يمكن استخدام‬
()EndInvoke ‫)( وقراءة الناتج في‬BeginInvoke
foreground and background
.18.6
: threads ‫אل‬53‫ن‬D'¤NS
0BWON53zg9‫א‬QnˆqQ‫אن‬5P> 9234‫אنא‬cQ‫א‬WS :
Foreground Thread
.‫'ع‬N‫אא‬WS53'SlzT‫'م‬7 thread s‫א‬Z!9‫'عא‬N‫ א‬،:!i‫'د‬%'\‫ א‬foreground threads‫אل‬
‫!אل‬WONQ_ 'n:. —‫א‬Q‫אن‬5P>234‫אنא‬cQ‫א‬WS :
Background Thread
:ً ^3‫א‬KPT:FDQ،background threads
C#
t.IsBackground = true;
‫ﻛﻮد‬
VB
t.IsBackground = true
‫ﻛﻮد‬
Threads Synchronization
.18.7
3‫א”א®د‬W،O+\‫א‬FDh‫א‬H3YKI‫א‬$KVd9C5FMQ$C ! Threads‫אل‬03KF3$ND
.ˆ‫س‬H‫د‬Uً‫א‬V†g‘,‫א‬t‫א‬53‫د¨אא‬3ˆ1QW‫وא‬SyncLock~fQ
،KI‫א‬$CKVd9gI‫'ددא‬P‫א‬YFMQt‫ وא‬SyncLock…End SyncLock‫אم‬$+‫א‬Q
KPT ، zg–‫ א‬$ 9‘ KI‫א‬$ zƒ‫@ ل א‬O U ‫ 'د‬F 9‫و‬H\‫א א‬WSH‫د‬V3 ‫'م — ق‬7
:ً ^3‫א‬
273
C#
lock (myLock) {
for (i = 0; i <= 1000; i++) {
Console.WriteLine(i.ToString());
}
Console.Write(number);
}
‫ﻛﻮد‬
VB
SyncLock myLock
For i=0 To 1000
Console.WriteLine(i.ToString())
Next i
Console.Write(number)
End SyncLock
‫ﻛﻮد‬
.‫א‬W،ًMQCD1‫א‬3C‫و‬H‫א‬P‫א‬7zg‫א‬$9‘KFQ‫אن‬myLock
q\‫مא‬$+QH3FQ5
.ً ^3number
q\‫א‬F7KI‫א‬$:!KVd‫ن‬CnT§‫ن‬P3KUgs'
:−‫א‬q–‫سא‬H$‫א‬53h‫א‬H\‫א‬U53‫אא‬5D$Q\‫!א‬3NP>
‫رابط‬
http://vb4arab.com/vb/showthread.php?t=6341
ThreadPool
.18.8
U ¼Q'T 53 : G 3‫ و‬U h‫א‬H\‫ א‬i^P KQ$‫ א‬S – ‫ א‬b ‫ – ‘ن‬h‫א‬H\‫ א‬i
r
h‫א‬H\‫ א‬53 D'F 5Q'P ‫ ذ‬Q ، :! I‫ و‬H‫د‬V\‫ وא‬53‫ אא‬3‫وא‬C G aœ‫ א‬53 ^P‫ وא‬234‫א‬
:234‫א‬Ui^PSWONQ9t‫א‬h‫א‬H\‫א‬Ui‫^א!د‬C‫'نذ‬PQ‫و‬،ZT\‫א‬
C#
for (int i = 1; i <= 5; i++) {
ThreadPool.QueueUserWorkItem(sometask.Execute);
}
‫ﻛﻮد‬
274
VB
For i As Integer = 1 To 5
ThreadPool.QueueUserWorkItem(AddressOf sometask.Execute)
Next
‫ﻛﻮد‬
:−‫א‬q–‫سא‬H$‫ لא‬I53‫'ع‬s'\‫אא‬WS5D$Q\‫!א‬3NP>
‫رابط‬
http://vb4arab.com/vb/showthread.php?t=6340
BackgroundWorker
.18.9
53،2349‫א‬H\‫א‬5Dً‫א‬$ ً Q'ً.‫و‬WI]N3Fg3WON BackgroundWorker ‫مאل‬$+
53 h‫ ™ א‬G% ‫ אو‬H'V‫Ž א‬3 hFD ‫و‬C web service 53 iz‫א‬7 bœ‫وאل א‬$‫^ ذ א‬3C
.$3‫א‬Q'hF‫א‬53D'Fz‫א‬%‫אوא‬،rFD WON‫و‬CIŠ'3'
‫ن‬C 9‘ ، $7 thread U SWON ˆQ 5D ‫وאل‬$‫ א‬lWS KFD P3¦ ‫ ن‬C 03‫و‬
U G— t‫א א‬$ thread ~‫ א‬HI‫ א‬NP>  ، PR‫ א‬53 $Q3 1 BackgroundWorker
E$ WON Q WON‫ א‬zg‫ א‬$ ‫
ًא‬IC ، RunWorkerAsync()ˆQ 5D gqT ‹ 53‫ و‬SWON
.Fg\‫א‬lWSWONzg‫ א‬$2jN‫ضא‬Dً ^3:!NP>t‫وא‬RunWorkerCompleted
،Fg\‫א‬WONz$3‫א‬H‫ز‬0s‹53‫و‬h‫دوא‬9‫™א‬.، Windows Form KF .KFz$
:ً ^3‫א‬KPT BackgroundWorker i‫دא‬CGR.ً‫
א‬I‫وא‬
275
RunWorkerCompletedE$L‫ وא‬، WON‫ א‬z$ €.‫ و‬lzD$‫ א‬Q W‫ وא‬DoWork NS FS Y‫ دא‬SC
:ً ^3 ‫א‬KPTWON‫א‬53zg9‫א‬$:. ‫א‬QW‫وא‬
‫ﻛﻮد‬
C#
private void ProcessNumbersBackgroundWorker_DoWork(object sender,
DoWorkEventArgs e)
{
}
private void ProcessNumbersBackgroundWorker_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
}
‫ﻛﻮد‬
VB
Private Sub ProcessNumbersBackgroundWorker_DoWork(ByVal sender As Object,
ByVal e As DoWorkEventArgs)
End Sub
Private Sub ProcessNumbersBackgroundWorker_RunWorkerCompleted(ByVal sender As
Object, ByVal e As RunWorkerCompletedEventArgs)
End Sub
:‫א‬KPTWONz$‫א‬Qً79
C#
ProcessNumbersBackgroundWorker.RunWorkerAsync(args);
‫ﻛﻮد‬
VB
ProcessNumbersBackgroundWorker.RunWorkerAsync(args)
‫ﻛﻮد‬
. DoWork E$L‫א‬U‫'د‬%'\‫'دא‬P‫א‬WONQ
276
‫‪277‬‬
‫اﻟﺒﺎب‬
‫‬
‫‬
‫‬
‫‪13‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫اﻻدﺧﺎل واﻻﺧﺮاج ﻓﻲ ‪.net‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
278
279
System.IO ‫اﻟﻔﺌﺎت اﻻﺳﺎﺳﻴﺔ ﻓﻲ‬
.1
Binary KP,nD‫و‬iz‫א‬. 
Files
‫ن‬C 5P> t‫ א‬Buffer h €.p3 ‫†ن‬
BinaryReader
BinaryWriter
BufferedStream
i‫א‬W‫ً‘„א‬79g7QWI]
7\‫א‬h3'\‫وא‬h‫א‬$¡‫א‬03K3*†
g
h‫א‬$‫ و‬5D h3'\‫! א‬3‫ و‬K3 *†
Directory
DirectoryInfo
DriveInfo
Driver¤‫ز‬g%U5Q+‫א‬
gˆQ3K‫و‬hO\‫א‬03K3*†
nD h‫ض א‬D‫ و‬hOF ‫'ل‬b'‫ א‬53 NP>
File
FileInfo
FileStream
StreamKP,
C1t‫א‬h Q$¤HI‫وא‬$‫ אو‬o3.‫א‬3
FileSystemWatcher
:D
KQ'R VN‫ א‬h‫
א‬q\‫ א‬03 K3 *†
Path
KqT‫(مא‬N3'gO3H'b„‘h‫א‬H\‫א‬
ViH'VhO\‫‘„א‬P‫وא‬iz‫א‬7‫א‬
Reader ‫ אن אل‬f I‫ א‬03 a7! ، ˆ‫@ א‬O
String‫ אل‬53lzT‫א‬Q Writer ‫وאل‬
StreamReader
StreamWriter
StringReader
StringWriter
.ً 3‫א‬$+‫א‬S^C‫و‬Sg,CSlWS5P‫و‬،zƒ9‫ א‬53‫אא¡ل‬WSUAI‫א‬hJ!¤NS
Directory ‫ و‬DirectoryInfo ‫اﻟﻔﻮارق ﺑﻴﻦ‬
.2
3‫ א‬Object 53 i,3 7T3 Directory ‫ אن‬، g ‫ אœص‬structure ‫ אل‬U 'S ‫ق א‬HO‫א‬
K3‫א‬U‫ق‬HO‫ א‬3‫א‬، Objects ‫אل‬53SH‫و‬$7T\‫ א‬FileStreamInfo53 7T3g! DirectoryInfo
280
03 3‫ א‬، i,3 g3‫א‬$+‫ א‬5P> r Static ‫'ع‬N‫ א‬53 k‫ دوא‬f Directory JO‫' אن א‬g!
.‫وאل‬$‫אمא‬$+‫א‬K. +oQ39‫א‬G1Qo†39!DirectoryInfo
... FileInfo ‫ و‬File Y‫ق‬O‫א‬nDˆ1NQ39‫@ א‬O
*jVœ !s‫ א‬FileStreamInfo‫ل‬9‫*א‬jVœ‫א‬g3KF FileInfo ‫ و‬DirectoryInfo YJO‫ א‬
:S‫و‬،h‫א‬$¡‫وא‬hO\‫א‬03K3‫א‬
ob'‫א‬
bœ‫א‬
5D o\‫و א‬C $`F !s‫ א‬. QF *§
Attributes
nF\‫א‬
enumeration
‫אل‬
ˆQ
FileAttributes
zT9‫א‬¢QH‫و‬iz‫א‬.
CreationTime
9‫م‬C‫'د‬%'3o\‫א‬KS!3
Exists
o\‫אدא‬$3‫א‬$
Extension
$`F‫و‬CoF ً 3H\‫א‬nD‫'ل‬VL‫א‬
FullName
‫ אو‬o\‫ א‬nD ‫'ل‬I$ ¢QH IŠ ‫ و‬iz‫א‬.
LastAccessTime
$¡‫א‬
LastWriteTime
‫אو‬o\‫אא‬WSUP¢QHIŠ‫و‬iz‫א‬.
$¡‫א‬
Name
$¡‫وא‬Co\‫!אא‬3
DirectoryInfo ‫اﻟﻔﺌﺔ‬
.3
:‫وאلא‬$‫א‬nDJO‫א‬lWS'، FileStreamInfo 537‫*א‬jVœ‫א‬nDSz‫'א‬9!s‫א‬
ob'‫א‬
bœ‫وא‬C‫א‬$‫א‬
‫د‬$[‫א‬H\‫א‬UD!$ ‫אو‬$zT‫א‬
Create()
CreateSubdirectory()
Delete()
:Q')K3‫و‬$¡‫א‬fW
281
DO‫א‬h‫א‬$¡‫א‬zƒ‫א‬s'zƒ9‫א‬53!'OV3$
GetDirectories()
hO\‫ ! א‬nD ' FileInfo 53 Array !'OV3 $
GetFiles()
$¡‫אא‬WSU i‫'د‬%'\‫א‬
$Q$%‫ن‬P3„‘:Q')!‫و‬$¡‫א‬K7
MoveTo()
$¡‫אא‬WS5349‫א‬$¡‫!א‬3
Parent
$¡‫אא‬Wg‫ אœص‬Driver ‫\!אل‬
Root
$T\‫ א‬U :N3 z$‫ 'د א‬W‫ن א‬P\‫ א‬Qe NP> ، JO‫ א‬lWS 53 + oQ %r €‫ א‬، z$‫ א‬K.
:( 234‫א‬H\)ً ^3‫א‬KPTConstructor
C#
DirectoryInfo dir1 = new DirectoryInfo(".");
‫ﻛﻮد‬
VB
Dim dir1 As New DirectoryInfo(".")
‫ﻛﻮد‬
:‫د‬DH3„‘‫و‬C
C#
DirectoryInfo dir1 = new DirectoryInfo(@"C:\Ahmed");
‫ﻛﻮد‬
VB
Dim dir1 As New DirectoryInfo("C:\Ahmed")
‫ﻛﻮد‬
‫ﻣﻼﺣﻈﺔ‬
K^3AICh3‫א‬$+‫א‬k‫*–ن‬VN‫ א‬h3 DKI‫دא‬S$‫\و‬0s‫مو‬$D53$ !XH,2343€N'
.‫א\^ل‬UF@!s‫ˆא‬Q5Di,3g]KI‫א‬$ h‫'عא‬$Q$NP>5P،:! I‫\و‬n \r
lzT‫‹א‬53‫'دو‬%'3 —$„‘a‫א‬NP>K،‫'د‬%'3$03a‫א‬P3a7!@
C#
DirectoryInfo dir1 = new DirectoryInfo(@"C:\Ahmed\Test");
dir1.Create();
‫ﻛﻮد‬
282
VB
Dim dir1 As New DirectoryInfo("C:\Ahmed\Test") dir1.Create()
‫ﻛﻮد‬
:$¡‫ א‬KI‫دא‬hO\‫ًאאض!א‬MQ‫א‬NP>
C#
FileInfo[] imageFiles = dir.GetFiles();
‫ﻛﻮد‬
VB
Dim imageFiles As FileInfo() = dir.GetFiles()
‫ﻛﻮد‬
‫^ ًض‬F! ،$¡7\‫א‬h3'\‫!א‬nD't‫ א‬FileSystemInfo *jVI‫אم‬$+‫ א‬NP>
:$¡‫א‬zT‘¢QH
C#
Console.WriteLine(dir1.CreationTime);
‫ﻛﻮد‬
VB
Console.WriteLine(dir1.CreationTime)
‫ﻛﻮد‬
@N9،g ‹53‫ و‬GIF a7!VN‫א‬hO\‫אضא‬9ً ^3،a7!Y3‫'ع‬53hO3‫ אאض‬NP>‫و‬C
.gD FileSsystemInfo *jVIˆ15P>‫ و‬FileInfo ‫'ع‬532N‫אنא‬
‫ﻛﻮد‬
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
DirectoryInfo dir1 = new DirectoryInfo(@"C:\Users\Ahmed\Documents\Visual
Studio 2008\WebSites\WebSite4");
283
FileInfo[] imageFiles = dir1.GetFiles("*.gif");
foreach (FileInfo f in imageFiles)
{
Console.WriteLine("Name: {0} - Creation Date: {1} . \n\n", f.Name,
f.CreationTime);
}
Console.ReadKey();
}
}
}
‫ﻛﻮد‬
VB
Imports System Imports System.Collections.Generic Imports System.Linq Imports System.Text Imports System.IO Namespace ConsoleApplication7 Class Program Private Shared Sub Main(ByVal args As String()) Dim dir1 As New DirectoryInfo("C:\Users\Ahmed\Documents\Visual Studio
2008\WebSites\WebSite4") Dim imageFiles As FileInfo() = dir1.GetFiles("*.gif") For Each f As FileInfo In imageFiles Console.WriteLine("Name: {0} - Creation Date: {1} . " & Chr(10) & "" &
Chr(10) & "", f.Name, f.CreationTime) Next Console.ReadKey() End Sub End Class End Namespace
:ً ^3‫א‬KPT‫'ن‬P2N‫א‬
284
Directory‫اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻔﺌﺔ‬
.4
ً%)‫'ن‬P5K7\‫א‬U‫ و‬FileSystemInfoJO‫ لא‬I53\‫* א‬jVœ‫א‬$7Oa7!،$Q$%z,9
fWL‫א‬Fً ^3‫א‬KPTi,3JO‫א‬nDKF‫א‬NP>‫א‬W،KFz$‫ א‬K.+oQ
C#
System.IO.Directory.Delete(@"C:\ahmed");
‫ﻛﻮد‬
VB
System.IO.Directory.Delete("C:\ahmed")
‫ﻛﻮد‬
DriveInfo ‫اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻔﺌﺔ‬
.5
X53i,3‫אא\^ل‬WS،gNDh3'\‫!™א‬3‫و‬¤‫ز‬g%U Drivers ‫אאضאل‬JO‫א‬lWS
:Pro.CSharp 2008
C#
Console.WriteLine("***** Fun with DriveInfo *****\n");
// Get info regarding all drives.
DriveInfo[] myDrives = DriveInfo.GetDrives();
// Now print drive stats.
‫ﻛﻮد‬
285
foreach(DriveInfo d in myDrives)
{
Console.WriteLine("Name: {0}", d.Name);
Console.WriteLine("Type: {0}", d.DriveType);
// Check to see whether the drive is mounted.
if (d.IsReady)
{
Console.WriteLine("Free space: {0}", d.TotalFreeSpace);
Console.WriteLine("Format: {0}", d.DriveFormat);
Console.WriteLine("Label: {0}", d.VolumeLabel);
Console.WriteLine();
}
}
Console.ReadLine();
VB
Console.WriteLine("***** Fun with DriveInfo *****" & Chr(10) & "") ' Get info regarding all drives. Dim myDrives As DriveInfo() = DriveInfo.GetDrives() ' Now print drive stats. For Each d As DriveInfo In myDrives Console.WriteLine("Name: {0}", d.Name) Console.WriteLine("Type: {0}", d.DriveType) ' Check to see whether the drive is mounted. If d.IsReady Then Console.WriteLine("Free space: {0}", d.TotalFreeSpace) Console.WriteLine("Format: {0}", d.DriveFormat) Console.WriteLine("Label: {0}", d.VolumeLabel) Console.WriteLine() End If Next Console.ReadLine()
‫ﻛﻮد‬
FileInfo ‫اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬
.6
: - Q‫*אد‬jV+01 !s‫א‬−JO‫א‬lWSUj‫وאلא‬$‫א‬
ob'‫א‬
‫א‬$‫אوא‬bœ‫א‬
o\‫א‬UP StreamWritter zT‫א‬
AppendText()
286
o\‫א‬¢
CopyTo()
FileStream5ji‫د‬D‫وא‬o3zT‫א‬
Create()
o\‫א‬UP StreamWriter zT‫א‬
CreateText()
o\‫א‬fW
Delete()
$¡‫!א א‬3
Directory
$¡‫א‬H3!3
DirectoryName
o\‫!` א‬3
Length
‫'ل‬7N\‫א‬oF$Q$%‫א‬$Q$NP>،K7N‫א‬
MoveTo()
o\‫א א‬
Name
:! I‫و‬P‫وא‬iz‫א‬7‫א‬P3‫א‬03o\‫!א‬
Open()
a7!iz‫א‬7o\‫!א‬
OpenRead()
StreamReader‫אم‬$+o\‫!א‬
OpenText()
a7!Po\‫!א‬
OpenWrite()
nDfN.‫وس‬H$‫א‬lWS53 ˆ9z%Uً VOgDfNt‫ وא‬StreamReader ‫'אص‬I5Dً‫א‬$
.*jVœ‫א‬.
: Create ‫אم‬$+ً ^3 o3zT9
C#
FileInfo f = new FileInfo(@"C:\Test.txt");
FileStream fs = f.Create();
‫ﻛﻮد‬
VB
Dim f As New FileInfo("C:\Test.txt") Dim fs As FileStream = f.Create()
‫ﻛﻮد‬
bœ‫א‬a7!،ˆF FileSystemInfo Ui‫'د‬%'\‫*א‬jVœ‫א‬53C‫אم‬$+‫א‬P3 ‫ن‬C@N9ً
o\‫‘ذאنא‬$Q$ k I53NP>،KbOi$DKFT3ًD'iŸbISAttributes
.‡‫א‬...a7!iz‫א‬7،S&‫אم‬O†
‫؟‬9‫م‬CO†o\‫א‬KS!\ً ^3
287
C#
if ((File.GetAttributes(path) & FileAttributes.Hidden) == FileAttributes.Hidden)
{
}
‫ﻛﻮد‬
‫ﻛﻮد‬
VB
If (File.GetAttributes(path) And FileAttributes.Hidden) = FileAttributes.Hidden Then
End If
:ً ^3‫א‬KPT OR K3\‫مא‬$+o\‫א‬zOI93C
C#
File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
‫ﻛﻮد‬
VB
File.SetAttributes(path, File.GetAttributes(path) Or FileAttributes.Hidden)
‫ﻛﻮد‬
Open ‫اﻧﺸﺎء وﻓﺘﺢ اﻟﻤﻠﻔﺎت ﺑﺎﺳﺘﺨﺪام‬
.6.1
:‫ א‬$O3S‫ و‬FileMode.OpenOrCreatebœ‫א‬03 Open ‫א‬$‫مא‬$+N‫א‬$`‫'د א‬P‫א‬U
:lzT.l${_'،:RO.o\‫א‬h$%‫'و‬
C#
FileInfo f2 = new FileInfo(@"C:\Test2.txt");
FileStream fs2 = f2.Open(FileMode.OpenOrCreate,FileAccess.ReadWrite,
FileShare.None);
‫ﻛﻮد‬
VB
Dim f2 As New FileInfo("C:\Test2.txt")
Dim fs2 As FileStream = f2.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite,
FileShare.None)
‫ﻛﻮد‬
288
:hO\‫א‬zT‫وא‬OًMQCAICh9¤NS
ob'‫א‬
L‫א‬
IOException]1IKF.:$%‫'و‬،i,3$Q$%o3]T‫א‬
CreateNew
‫'د‬%'\‫!'قא‬lzT.:$%‫و'و‬o3zT.
Create
FileNotFoundException]1IKF.l${_'‫و‬o\‫א!א‬
Open
‫'د ًא‬%'35PQ_ 'l]T‫وא‬C‫'د‬%'3‫'ن‬o\‫!א‬
OpenOrCreate
:Q') !3‫وא‬o\‫א!א‬
Truncate
ً‫'دא‬%'3o\‫ א‬5PQ_'،P‫א‬FDz$lIšK7‫وא‬o\‫א‬O.
Append
Ug(9Sً3'FD،:‫و‬C53Pz$‫وא‬$Q$%$‫وא‬O.
OpenWriteUa7!‘‫ و‬Open ‫אم‬$+O‫א‬
: enum ‫אאل‬WSUD'Fh9E ‹: ً MQ‫ א‬FileAccess ‫אل‬
C#
public enum FileAccess
{
Read,
Write,
ReadWrite
}
‫ﻛﻮد‬
VB
public enum FileShare
{
None,
Read,
Write,
ReadWrite
}
‫ﻛﻮد‬
289
.6.2
‫ و‬OpenRead ‫ﻓﺘﺢ واﻧﺸﺎء اﻟﻤﻠﻔﺎت ﺑﺎﺳﺘﺨﺪام‬
OpenWrite
.hF‫א‬53a7!$‫'عوא‬Nً33‫'ن‬P‫אא‬$D ،ˆ3K^3
OpenText ‫ﻓﺘﺢ اﻟﻤﻠﻔﺎت ﺑﺎﺳﺘﺨﺪام‬
.6.3
:ً ^3‫א‬KPT، FileStream@‫ و‬StreamReader ‫ 'ع‬53‫'ن‬Pi‫א\د‬F7‫'אنא‬S$'‫قא‬HO‫א‬
C#
FileInfo f5 = new FileInfo(@"C:\boot.ini");
StreamReader sreader = f5.OpenText();
‫ﻛﻮد‬
VB
Dim f5 As New FileInfo("C:\boot.ini") Dim sreader As StreamReader = f5.OpenText()
‫ﻛﻮد‬
AppendText ‫ و‬CreateText ‫اﻟﻔﺘﺢ ﺑﺎﺳﺘﺨﺪام‬
.6.4
. StreamWritter‫'ع‬53‫'ن‬Pi‫ א\د‬F7‫אنא‬5P>a7!‫ق‬HO‫א‬،7‫א‬K^3
File ‫اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻔﺌﺔ‬
.7
KF‫א‬NP>K Static gً‫(א‬gN3+oQnDً‫א‬4‫'ن‬P 5،h‫א‬$¡‫א‬U‫ذ‬3@O
.i,3gD
:SP‫ وא‬iz‫א‬7‫א‬hFJO‫א‬Ui$Q$%AIC‫دوאل‬¤NS
ob'‫א‬
‫א‬$‫א‬
array of bytesKP,nDh‫א‬iz‫א‬.
ReadAllBytes()
19‫א‬53!'OV3 KP,nDh‫א‬iz‫א‬.
ReadAllLines()
290
i$‫وא‬h‫א‬0Biz‫א‬.
ReadAllText()
byte by byte
WriteAllBytes()
1‫ א‬KP,nDP‫א‬
WriteAllLines()
i$‫وא‬PP‫א‬
WriteAllText()
: ProCSharp 2008X53−ً ^3‫א‬KPTg3‫א‬$+‫א‬5P>‫و‬
C#
string[] myTasks = {
"Fix bathroom sink", "Call Dave",
"Call Mom and Dad", "Play Xbox 360"};
// Write out all data to file on C drive.
File.WriteAllLines(@"C:\tasks.txt", myTasks);
// Read it all back and print out.
foreach (string task in File.ReadAllLines(@"C:\tasks.txt"))
{
Console.WriteLine("TODO: {0}", task);
}
‫ﻛﻮد‬
‫ﻛﻮد‬
VB
Dim myTasks As String() = {"Fix bathroom sink", "Call Dave", "Call Mom and Dad",
"Play Xbox 360"}
' Write out all data to file on C drive.
File.WriteAllLines("C:\tasks.txt", myTasks)
' Read it all back and print out.
For Each task As String In File.ReadAllLines("C:\tasks.txt")
Console.WriteLine("TODO: {0}", task)
Next :‫ﻣﻌﻠﻮﻣﺔ اﺿﺎﻓﻴﺔ‬
g!W ‹53‫نو‬P3UgOQ‫'م‬7‫ אن‬IDisposable ‫ ل‬implemented €‫‘ذא‬JO5P>، .net U
:ً ^3‫א‬KPT‫ق‬1N‫אא‬WS‫ج‬HI
C#
using (CarClass newCare)
{
// do operations
}
‫ﻛﻮد‬
291
VB
Using newCare As CarClass
' do operations
End Using
‫ﻛﻮد‬
:ً ^3‫ א‬KPTi‫א‬W‫א‬U73n79nhO\‫א‬03ًMQ‫א‬g3‫א‬$+‫ولא‬RN‫א‬W
C#
FileInfo f = new FileInfo(@"C:\test.txt");
using(StreamReader reader = f.OpenText())
{
// code here
}
‫ﻛﻮد‬
VB
Dim f As New FileInfo("C:\test.txt")
Using reader As StreamReader = f.OpenText()
' code here
End Using
‫ﻛﻮد‬
Stream
.8
nD5Q‫ز‬g%Y‫אو‬YO3Y‫ن ذ‬z‫'א‬K73‫و‬H$V3Y3h‫א‬K7‫!ˆאو‬$:$V7Q Stream ‫אل‬
o\‫א‬Qgnsequance of bytesKP,nDGq‫א‬U h‫א‬K7Q،:! I‫و‬C‫و‬CPT‫א‬
.h‫وא‬C
'،ً79gJ!G—03K3Nt‫אمא‬JO‫א‬4t‫ وא‬System.IO.Stream JO‫א‬¤NS، .net U
: ‫א‬j‫*א‬jVœ‫وאلوא‬$‫ א‬nDJO‫א‬lWS
ob'‫א‬
‫א‬$‫وא‬Cbœ‫א‬
K7 lWS Stream ‫ אل‬FD € ‫! ‘ذא‬3  *jVI
CanRead, CanWrite
S
—‫و‬iz‫א‬7‫وא‬CP‫א‬FD
292
:! I‫و‬hO353gˆQ3K‫و‬F‫א— قא‬
Close()
_'، Buffer Uًi‫'د‬%'\‫א‬hK7\‫א‬hQ$
Flush()
z,]‫'م‬79 ‫א‬$‫א‬lWg! Buffer ‫'د‬%‫و‬D$F‫ א‬lWS5PQ
0.‫א'א‬U
€Q stream ‫`אل‬$bI
Length
stream ‫אل‬U‫ن‬P\‫دא‬$
Position
bytes53D'F‫€אو‬Qiz‫א‬.
Read(), ReadByte()
stream‫אאل‬WSU$Q$%‫ن‬P3U ,p\‫א‬0s‫و‬
Seek()
L‫ א‬stream ‫'لאل‬$Q$
SetLength()
bytes‫אل‬53D'F‫€אو‬Q
Write(), WriteByte()
File Stream ‫اﻟﻔﺌﺔ‬
.8.1
03 streaming ‫ אل‬03 K3 a7! *§ ˆ‫ א‬abstract class Q$D7‫ א‬JO‫ˆ א‬1 t‫ א‬JO‫ א‬lWS
.hO\‫א‬
‫‰ج‬a7!P‫ א‬K.−'P\‫א‬h‫א‬iz‫א‬.‹53‫و‬o\‫א‬5353Ci$DUP‫א‬s'Q‫א\^ل א‬
.i'1œ‫א‬lWS@N9‫א‬W bytes „‘‫א‬KQ'R
C#
private void filestreamexample(string msg, string beforeendmsg)
{
using(FileStream f1 = File.Open(@"C:\test.txt",
FileMode.Create))
{
byte[] msgArray = Encoding.Default.GetBytes(msg);
byte[] beforeendmsgArray = Encoding.Default.GetBytes(beforeendmsg);
f1.Seek(0, SeekOrigin.Begin);
f1.Write(msgArray , 0, msgArray.Length);
f1.Position = f1.Lenght-10;
f1.Write(beforeendmsgArray , 0, msgAsByteArray.Length);
// view total message.
long totalLenght=msgArray.Length + msgAsByteArray.Length;
byte[] filemsg = new byte[totalLenght];
‫ﻛﻮد‬
293
for (int i = 0; i < totalLenght; i++)
filemsg[i] = (byte)f1.ReadByte();
Console.WriteLine(Encoding.Default.GetString(filemsg));
}
}
‫ﻛﻮد‬
VB
Private Sub filestreamexample(ByVal msg As String, ByVal beforeendmsg As String)
Using f1 As FileStream = File.Open("C:\test.txt", FileMode.Create)
Dim msgArray As Byte() = Encoding.[Default].GetBytes(msg)
Dim beforeendmsgArray As Byte() = Encoding.[Default].GetBytes(beforeendmsg)
f1.Seek(0, SeekOrigin.Begin);
f1.Write(msgArray, 0, msgArray.Length)
f1.Position = f1.Lenght - 10
f1.Write(beforeendmsgArray, 0, msgAsByteArray.Length)
' view total message.
Dim totalLenght As Long = msgArray.Length + msgAsByteArray.Length
Dim filemsg As Byte() = New Byte(totalLenght - 1) {}
For i As Integer = 0 To totalLenght - 1
filemsg(i) = CByte(f1.ReadByte())
Next
Console.WriteLine(Encoding.[Default].GetString(filemsg))
End Using
End Sub
‫اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻔﺌﺎت اﻟﻤﺸﺘﻘﺔ‬
.8.2
‫ ذ‬stream UP‫وא‬iz‫א‬7‫א‬53‫א'אع‬i$DNQ$‫ن‬C‫אج‬I–‫لوא‬I‫د‬9‫'عא‬s'3UN‫و‬H‫ولد‬CU‫ذ‬
BinaryReader, ‫و‬
StringWriter, StringReader‫و‬
StreamWriter, StreamReadergN3
.‫אšن‬gDf‫א‬UC$N3S‫و‬،BinaryWriter
294
StreamWriter, StreamReader
.8.3
P‫ א‬F 9‫وאل א‬$‫ א‬nD ' ، 7‫ א‬E ^‫ א‬hJO‫ א‬Y 53 ً 3‫א‬$+‫ وא^ א‬g,‫ א‬hJO‫א‬
:‫ א‬iz‫א‬7‫وא‬
StreamWriter
ob'‫א‬
bœ‫وא‬C‫א‬$‫א‬
‫א— ق‬
Close()
buffer‫אل‬hQ')!3
Flush()
$Q$%1
NewLine
Q‫د‬D
Write()
$Q$%103
WriteLine()
StreamReader
:7‫א‬i7O‫א‬U„‫אو‬E ^‫وאلא‬$‫!‘„א‬s9'
ob'‫א‬
bœ‫وא‬C‫א‬$‫א‬
‫ دون‬L‫ن א‬PF i,3 ‫ א‬fL‫ א‬iz‫א‬.
Peek()
,p\‫نא‬P3
q
iz‫א‬7‫א‬
Read()
buffer‫אل‬Ugs‫אوو‬$‫א‬53D'Fiz‫א‬.
ReadBlock()
K31iz‫א‬.
ReadLine()
QgN‫א‬n,p\‫نא‬P353iz‫א‬.
ReadToEnd()
:‫أﻣﺜﻠﺔ‬
:Vo3„‘P‫وא‬iz‫א‬7‫א‬tFD0F® ‫^ل‬3
295
C#
private void write( string msg)
{
using(StreamWriter w1 = File.CreateText("test.txt"))
{
w1.Write("Start");
w1.Write(writer.NewLine);
w1.WriteLine(msg);
}
}
private string read()
{
using (StreamReader s1 = File.OpenText("test.txt"))
{
string input = null;
string msg="";
while ((input = sr.ReadLine()) != null)
{
Console.WriteLine(input);
msg+=input;
}
return msg;
}
}
‫ﻛﻮد‬
VB
Private Sub write(ByVal msg As String)
Using w1 As StreamWriter = File.CreateText("test.txt")
w1.Write("Start")
w1.Write(writer.NewLine)
w1.WriteLine(msg)
End Using
End Sub
Private Function read() As String
Using s1 As StreamReader = File.OpenText("test.txt")
Dim input As String = Nothing
Dim msg As String = ""
While (input = sr.ReadLine()) IsNot Nothing
Console.WriteLine(input)
msg += input
End While
Return msg
‫ﻛﻮد‬
296
End Using
End Function
:o\‫ א‬UP‫א‬FD2
: Console‫אل‬nDiz‫א‬7‫א‬FD2‫و‬
‫ﻣﻼﺣﻈﺔ‬
‫ناتج المتغير النصي سيكون بدون عالمة السطر الجديد والذي سينتج عن الدالة‬
StringWriter, StringReader
.8.4
‫א‬KPTFD53NP>3'S‫ و‬string U‫'د‬Q2N‫א‬a7!،ˆFD‫ق‬H!‫ א‬$%'Q9ً7‫ذ‬F
:ً ^3
C#
StringBuilder stbuilder = strWriter.GetStringBuilder();
stbuilder.Remove(0, 10);
stbuilder.Insert(0, "Ahmed Gamal");
‫ﻛﻮد‬
297
VB
Dim stbuilder As StringBuilder = strWriter.GetStringBuilder()
stbuilder.Remove(0, 10)
stbuilder.Insert(0, "Ahmed Gamal")
BinaryReader, BinaryWriter
‫ﻛﻮد‬
.8.5
nD '‫ و‬System.ObjectJO‫ א‬53 7T3 ، binary hO3 U 5Q+‫ وא‬iz‫א‬7‫ وא‬P‫ א‬53 NPe
‫א‬WS، hQ'[‫'عא‬G ReadXXXX() ‫א‬$‫!‘„א‬s‫א‬.7‫א‬hJ!0H9‫א‬Ui‫'د‬%'\‫وאل א‬$‫א‬G—C
:JO‫א‬lWS‫אم‬$+P‫وא‬iz‫א‬7‫א\^ل‬
C#
FileInfo f = new FileInfo("Binary.dat");
using(BinaryWriter bwriter = new BinaryWriter(f.OpenWrite()))
{
double dbl = 1234.67;
long lng = 34567000;
string str = "A, B, C";
// Write differnt data.
bwriter.Write(dbl);
bwriter.Write(lng);
bwriter.Write(str);
}
// Reading using ReadXXX;
using(BinaryReader breader = new BinaryReader(f.OpenRead()))
{
Console.WriteLine(breader.ReadDouble());
Console.WriteLine(breader.ReadInt64()); // == long as i think , i am not sure.
Console.WriteLine(breader.ReadString());
}
‫ﻛﻮد‬
VB
Dim f As New FileInfo("Binary.dat")
Using bwriter As New BinaryWriter(f.OpenWrite())
Dim dbl As Double = 1234.67
Dim lng As Long = 34567000
Dim str As String = "A, B, C"
' Write differnt data.
bwriter.Write(dbl)
bwriter.Write(lng)
‫ﻛﻮد‬
298
bwriter.Write(str)
End Using ' Reading using ReadXXX;
Using breader As New BinaryReader(f.OpenRead())
Console.WriteLine(breader.ReadDouble())
Console.WriteLine(breader.ReadInt64())
' == long as i think , i am not sure.
Console.WriteLine(breader.ReadString())
End Using
FileSystemWatcher
.9
h‫
א‬q‫א‬53gD C1Q
q‫!א‬3‫و‬Y3o3¤'.‫א‬3UN—HUً‫א‬$%i$O3JO‫ א‬lWS4
:‫א‬h‫
א‬q‫ א‬53‫א‬G.‫א‬QW‫ وא‬System.IO.NotifyFilters enum‫אل‬Ui‫'د‬%'\‫א‬
C#
public enum NotifyFilters
{
Attributes, CreationTime,
DirectoryName, FileName,
LastAccess, LastWrite,
Security, Size,
}
‫ﻛﻮد‬
VB
Public Enum NotifyFilters
Attributes
CreationTime
DirectoryName
FileName
LastAccess
LastWrite
Security
Size
End Enum
‫ﻛﻮد‬
‫א دא‬،E‫א‬$913SWONQ‫دوאل‬oQً‫א‬H'!‫ج‬RN،h‫
א‬q‫ و‬events 5D E$RN‫ً}א‬
:‫ א‬delegate KP,nD‫'ن‬P‫אن‬$9:! I‫
و‬q‫وא‬KQ$‫א‬K^3E‫א‬$‫א‬iz‫א‬7‫م‬$+
299
C#
void MyNotificationHandler(object source, FileSystemEventArgs e)
{
‫ﻛﻮد‬
}
VB
Private Sub MyNotificationHandler(ByVal source As Object, ByVal e As
FileSystemEventArgs)
‫ﻛﻮد‬
End Sub
:‫ א‬KPT0Q‫ن‬C$99‫
א‬qE$3C
C#
void MyNotificationHandler(object source, RenamedEventArgs e)
{
‫ﻛﻮد‬
}
VB
Private Sub MyNotificationHandler(ByVal source As Object, ByVal e As
RenamedEventArgs)
‫ﻛﻮد‬
End Sub
$ !234‫א‬2jA‫אن‬UG—N‫ًو‬،hO\‫ א‬.‫'م}א‬7Q،‫د‬D23oQ‫'م‬7N‫אšن‬
NP3 ‫ ن‬windows Forms U N ' ، ً ^3 q f ‫م‬$+\‫ א‬aqMQ n KFQ 234‫ א‬K< ‫אن‬
fWL‫!وא‬s9‫‹א‬$L c:\ GV‫صא‬7‫א‬UVN‫א‬hO\‫!א‬G.‫א‬N‫א‬WSN^3U،ًi,3.‫א\א‬
C#
FileSystemWatcher watcher = new FileSystemWatcher();
// monitor files at:
watcher.Path = @"c:\";
// monitor files when
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite |
NotifyFilters.FileName| NotifyFilters.DirectoryName;
// watch files of type
watcher.Filter = "*.txt";
// watch events:
‫ﻛﻮد‬
300
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.EnableRaisingEvents = true;
Console.WriteLine("Press 'q' to quit app.");
while (Console.Read() != 'q') ;
VB
Dim watcher As New FileSystemWatcher()
' monitor files at:
watcher.Path = "c:\"
' monitor files when
watcher.NotifyFilter = NotifyFilters.LastAccess Or NotifyFilters.LastWrite Or
NotifyFilters.FileName Or NotifyFilters.DirectoryName
‫ﻛﻮد‬
' watch files of type
watcher.Filter = "*.txt"
' watch events:
AddHandler watcher.Created, AddressOf OnChanged
AddHandler watcher.Deleted, AddressOf OnChanged
watcher.EnableRaisingEvents = True
Console.WriteLine("Press 'q' to quit app.")
While Console.Read() <> "q"C
End While
KP ‫* دא‬V§ 5P> ، OnChanged ‫א‬$‫ א‬zD$ ‫'م‬7 N¦! E$ C E$d 3$ND ، €(9 F
o\‫ضא‬D −ً ^3‫א‬KPT OnChanged ‫א‬$‫א‬NNP>،‫^ل‬3a7!‫א‬WS5PGF‫و‬CE$
- :
q‫€א‬.‫
وو‬q‫وא‬
‫ﻛﻮد‬
C#
static void OnChanged(object source, FileSystemEventArgs e)
{
Console.WriteLine("File Changed, File Path: {0} , Change: {1}, DateTime:
{2}", e.FullPath, e.ChangeType,DateTime.Now.ToString());
}
‫ﻛﻮد‬
VB
Private Shared Sub OnChanged(ByVal source As Object, ByVal e As
FileSystemEventArgs)
Console.WriteLine("File Changed, File Path: {0} , Change: {1}, DateTime: {2}",
e.FullPath, e.ChangeType, DateTime.Now.ToString())
End Sub
301
...234‫ א‬X%‫وאšن‬
:( i,3‫ א‬53)AICi3:‫د‬D‫אوא‬53o3fWL0.'3‫אج‬iH'V‫א‬
Object Serialization
.10
. Object Serialization ‫'مאل‬gO35DًQ‫س‬H$‫אא‬WSUfN
Serialization ‫اﻟﺘﻌﺎﻣﻞ ﻣﻊ ال‬
.10.1
: Serializable ‫ﻋﻤﻞ اﻟﻔﺌﺔ اﻟﺨﺎﺻﺔ ﺑﻚ ﻟﺘﻜﻮن‬
:ً ^3‫א‬KPTJO‫א א‬nD‫ א‬: [Serializable] FP‫א‬0M‫ن‬C3‫א‬U3K
C#
[Serializable]
public class serial
{
}
‫ﻛﻮد‬
VB
<Serializable()> _
Public Class serial
End Class
‫ﻛﻮد‬
302
‫ ؟‬Serializable ‫ﻣﺎذا اﺳﺘﻔﻴﺪ ﻣﻦ ﻛﻮن اﻟﻔﺌﺔ اﻟﺨﺎﺻﺔ ﺑﻲ‬
„‘ i,\‫ א‬P‫ א‬K^3 *jVœ‫ ™ א‬53 i‫د‬O Serializable g'  9‫ א‬hJO‫( א‬3
:‫אא\^ل‬WS،ً7NFFGV‫صא‬7‫א‬hO3
C#
serial sample =new serial();
using(Stream fs1 = new FileStream("data.txt",
FileMode.Create, FileAccess.Write, FileShare.None))
{
binFormat.Serialize(fw1, sample );
}
‫ﻛﻮد‬
‫ﻛﻮد‬
VB
Dim sample As New serial()
Using fs1 As Stream = New FileStream("data.txt", FileMode.Create, FileAccess.Write,
FileShare.None)
binFormat.Serialize(fw1, sample)
End Using ‫ﻣﺎذا أﻳﻀ ًﺎ ؟‬
‫אل‬gN3، Serializable €'9‘ bœ‫א‬hJO‫א‬03K3‫א‬K79$.t‫א‬hNjP‫א‬53
‫د‬$D¤NS
. ASP.net ‫אل‬hRObUView State
: BinaryFormatter gN3،NjP Serialization KF‫ق‬1‫ א‬53$Q$‫א‬¤NS
C#
BinaryFormatter binFormatter = new BinaryFormatter();
using(Stream fs1 = new FileStream("data.txt",
FileMode.Create, FileAccess.Write, FileShare.None))
{
binFormat.Serialize(fs1, myobject);
}
‫ﻛﻮد‬
‫ﻛﻮد‬
VB
Dim binFormatter As New BinaryFormatter()
Using fs1 As Stream = New FileStream("data.txt", FileMode.Create, FileAccess.Write,
FileShare.None)
303
binFormat.Serialize(fs1, myobject)
End Using
: Deserializing KF‫و‬
C#
BinaryFormatter binFormatter = new BinaryFormatter();
using(Stream fs1 = File.OpenRead("data.txt"))
{
newobject car =
(objectclass)binFormatter.Deserialize(fs1);
}
‫ﻛﻮد‬
VB
Dim binFormatter As New BinaryFormatter()
Using fs1 As Stream = File.OpenRead("data.txt")
Dim car As newobject = DirectCast(binFormatter.Deserialize(fs1), objectclass)
End Using
XmlSerializer
‫ﻛﻮد‬
.10.2
53h‫א‬$D‫'א‬.hP3‫א‬Y0F® : ‫( ًא‬h‫ א‬5Q§_DUE$‫'عא‬N‫ א‬XML ‫אل‬$Q
KPT XML o33‫א‬qV‫א‬،VN‫א‬hO\‫א‬UFg3K3‫'א‬gY 0F®‫و‬:! I‫و‬R‫א‬
:‫א‬
‫ﻛﻮد‬
<root>
<Member>
<Name>AHmed</Name>
<Age>22</Age>
</Member>
</root>
.AttributenF Age ‫ و‬Name 3C Element nF22‫و‬$"C
:NS 53z$‫א‬NP> XML ‫'ل‬$Q\‫\!א‬
‫رابط‬
http://www.w3schools.com/xml/xml_whatis.asp
304
: System.Xml.Serialization ‫اﻟﻌﻨﺎﺻﺮ اﻷﺳﺎﺳﻴﺔ اﻟﻤﻮﺟﻮدة ﻓﻲ‬
ob'‫א‬
VN‫א‬
Attribute:‫א‬nDVN‫אא‬WSKQ'Q
XmlAttributeAttribute
Element:‫א‬nDVN‫אא‬WSKQ'Q
XmlElementAttribute
Root‫אل‬$Q$R
XmlRootAttribute
XML Text‫ ل‬gQ'Q
XmlTextAttribute
: Serialization FDˆQ 5D XML „‘JO‫א‬lWSKQ'Rً ^F!
C#
class Members
{
[XmlAttribute]
string Name;
[XmlAttribute]
int Age;
}
‫ﻛﻮد‬
VB
Class Members
<XmlAttribute()> _
Private Name As String
‫ﻛﻮد‬
<XmlAttribute()> _
Private Age As Integer
End Class
o3KP, nD2N‫א‬$` SerializationKFD‹53‫و‬JO‫א‬lWSnDh‫א‬53‫!א'ع‬s‫ א‬$‫وאšن‬
.ˆ‫א‬XML
‫‪305‬‬
‫اﻟﺒﺎب‬
‫‬
‫‬
‫‬
‫‪14‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫ﺑﺮﻣﺠﺔ اﻟﻨﻮاﻓﺬ ﻓﻲ ‪.net 2008‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
306
307
‫ﻣﻘﺪﻣﺔ‬
.1
hg%‫وא‬FVKT\R‫א‬KL‫א‬S4‫א‬hqG—‫א‬03 3‫ ز‬3€Rb‫א‬t‫ א‬Viusal FP‫א‬4
303،‫'د‬Pg%‫وא‬HnD4‫'ن‬P€N Visual 4‫א‬hqK.3 VDU،‫م‬$+FN3
.FV‫א‬A'3‫ض‬Oµ‫!‘„א‬s‫א‬WON‫€א‬.‫و‬U
I]‫'و‬b53‫ ذ‬:NQ
¤NS،N3g%‫وא‬FV:‘‫ج‬3K‫م‬$7 System.Windows.Forms P\‫א‬hz% .net U
3‫אوא‬53D'F‫ ل‬I533'‫א‬zOi‫د‬Q‫ز‬53NPe GDI+ f API ‫دوאل‬D'FًMQC
Windows Presentation N7 €!'‫و‬PQ3 N hz% .net 3.0 03‫
ًא و‬IC ،D 2 h3' VV+\‫א‬
0O3 $L 4‫ א‬h71 5Fs h3'‫ א‬izO 53 $Q WPF ‫ ًא‬HVI‫ א‬f 3 ‫ אو‬Foundation
.‫ ًא‬$%
‫ ﺑﺎﻟﻜﻮد‬Windows Forms ‫ﺑﻨﺎء‬
.2
‫'م‬7‫אن‬KMOQ، Visual Studio 5Fs€!'‫و‬PQ3Ng!‫و‬t‫א‬iSŽ‫ א‬hŽ\‫אمא‬$+C$‫ن‬CK.
. Windows Forms KFDOg!01ngNDً‫א‬$‫ 'ذج‬zN‫و‬R}
U C$N ‹ 53‫ و‬، WindowsForms.cs ً ^3 o3 zT . ، Notepad iPO\‫ א‬O . ‫א‬W
.‫'د‬P‫א‬
:ً ^3‫א‬KPT Forms JO‫א‬537T3J!oQ‫'م‬7Nً9‫و‬C
C#
class SimpleWindow : Form
{
}
‫ﻛﻮد‬
VB
Class SimpleWindow
Inherits Form End Class
‫ﻛﻮد‬
‫א‬W، System.Windows.FormshP3!s‫א‬nN9، :N3+zD$ Main E$U‫'م‬7N‫وאšن‬
:‫ א‬KPTK3P‫'د‬P‫'نא‬P
308
C#
using System;
using System.Windows.Forms;
namespace WindowsForms
{
class Program
{
static void Main()
{
Application.Run(new SimpleWindow ());
}
}
}
class SimpleWindow : Form
{
}
‫ﻛﻮد‬
VB
Imports System
Imports System.Windows.Forms
Namespace WindowsForms Class Program
Private Shared Sub Main()
Application.Run(New SimpleWindow())
End Sub
End Class
End Namespace
Class SimpleWindow
Inherits Form End Class
‫ﻛﻮد‬
:‫א‬K^33C‫ و‬،‫ אœص‬Cmd !'SD3Ka7!‫אšن‬
‫ﻛﻮد‬
csc /target:winexe *.cs
‫ﻣﻼﺣﻈﺔ‬
€.‫'د!`'אل‬nDKF3$NDcsc53ً9$vbc‫م‬$+‫א‬
309
ً J,2N‫'نא‬P،‫ن‬P3CU‫אم‬$+ iS%‫'ن‬P csc oQ$‫و‬،234‫ א‬H\XSW‫א‬$ً
:‫א‬WSK^3
WONn‫و‬C*jVœ‫א‬53‡‫ א‬.... !OT‫א‬.‫'لوאض‬1‫א‬K^3،*jVœ‫™א‬UPR‫א‬NP3‫وאšن‬
:ً ^3‫א‬KPT Object Browser‫ ل‬I53g‘‫'ل‬b'‫א‬5P>t‫א‬3‫אوא‬
:‫א‬KPT‫م‬H'O‫'ن'دא‬P‫א‬W،:1'‫'ل وאضو‬1‫
א‬qً ^3NP3‫אن‬$<‫א‬W
C#
class SimpleForm : Form
{
public SimpleForm (int height, int width, bool center)
{
‫ﻛﻮد‬
310
Width = width;
Height = height;
if(center) CenterToScreen();
}
}
‫ﻛﻮد‬
VB
Class SimpleForm
Inherits Form
Public Sub New(ByVal height As Integer, ByVal width As Integer, ByVal center As
Boolean)
Me.Width = width
Me.Height = height
if center=True Then
CenterToScreen()
End If
End Sub
End Class
:ً ^3‫א‬KPT،JO‫‘„א‬h‫א‬Z3H QF‫'م‬7f' Run UC@N95P
C#
static void Main()
{
Application.Run(new MainWindow(200, 300,True));
}
‫ﻛﻮد‬
VB
Private Shared Sub Main()
Application.Run(New MainWindow(200, 300, [True]))
End Sub
‫ﻛﻮد‬
...ً 7NFF Args ‫ ل‬I537‫ א‬lWSnD‫'ل‬VL‫א‬P3:‫@ًא‬N9
‫اﺿﺎﻓﺔ أدوات ﺑﺎﻟﻜﻮد‬
.2.1
‫ ل‬I530.‫ذ 'א‬Q،‫م‬H'O‫א‬nDO+\‫א‬h‫אدوא‬0s‫و‬nD‫אšن‬H‫و‬$‫א‬z%،‫'د‬P‫م‬H'O‫ א‬HNF
:‫א‬3‫אوא‬
311
ob'‫א‬
bœ‫وא‬C‫א‬$‫א‬
Add()
!s9‫א‬hF
AddRange()
fWL‫א‬hF
0FŽ‫\א‬
Remove
RemoveAt()
Clear()
Count
nDH‫א\و‬h9‫)و‬$NDً‫א‬$%i$O3bœ‫ א‬lWS0.‫א'א‬U،h‫دوא‬9‫دא‬$D
h‫אدوא‬
K${، System.Windows.Forms JO‫'د€א‬%'3gF`!،g!s‫א‬NP>t‫ א‬h‫אدوא‬3C
...gQ¯HnDh‫'د‬t‫א‬h‫دوא‬9‫א‬
‫اﺿﺎﻓﺔ اﻟﻘﻮاﺋﻢ‬
.2.2
:Fj7‫א‬U Exit H‫ز‬nDaqM ‫אœوج‬5P>‫א‬KPT‫'ل‬b'‫ولא‬RN
:Fj7‫א‬bN ToolStripMenuItem‹53‫و‬Fj7 MenuStrip oQ‫'م‬7N،ً1‫'ن‬P‫'د‬P‫א‬
C#
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
‫ﻛﻮد‬
VB
Private menuStrip1 As System.Windows.Forms.MenuStrip
Private fileToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
Private exitToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
‫ﻛﻮد‬
312
i,3‫'אد‬9‫א‬0s‫و‬53ً9$، BuildForm gƒ‫ א‬5P‫ و‬Constructor ‫אل‬U‫دא‬KFDS^‫א‬i'1œ‫א‬
. Constructor ‫אل‬U
C#
public SimpleForm()
{
Text="Example. Simple Form";
BuildForm();
}
‫ﻛﻮد‬
VB
Public Sub New()
Text = "Example. Simple Form"
BuildForm()
End Sub ‫ﻛﻮد‬
:j‫ א‬Fj7 Add ‫אم‬$+gOM‫و‬bNzƒ‫א‬0s'‫'م‬7N،‫א‬$‫א‬lWS4 ‫'م‬7N‫אšن‬
C#
fileToolStripMenuItem.Text = "&File";
menuStrip1.Items.Add(mnuFile);
exitToolStripMenuItem.Text = "E&xit";
menuStrip1.DropDownItems.Add(mnuFileExit);
‫ﻛﻮد‬
VB
fileToolStripMenuItem.Text = "File"
menuStrip1.Items.Add(mnuFile)
exitToolStripMenuItem.Text = "Exit"
menuStrip1.DropDownItems.Add(mnuFileExit)
‫ﻛﻮد‬
:‫א‬KPT Exit VNaqM‫א‬E$L Handler !s‫א‬S^‫א‬i'1œ‫א‬
C#
exitToolStripMenuItem.Click += new
System.EventHandler(this.exitToolStripMenuItem_Click);
‫ﻛﻮد‬
VB
‫ﻛﻮد‬
313
AddHandler exitToolStripMenuItem.Click, AddressOf exitToolStripMenuItem_Click
:‫م‬H'Og!s‫א‬$‫א‬KPT Form ‫ل‬bœ‫א‬Fj7‫'نא‬Pj‫א‬Fj7‫א‬$FNً‫
א‬IC
C#
Controls.Add(this.mnuMainMenu);
MainMenuStrip = this.menuStrip1;
‫ﻛﻮد‬
VB
Controls.Add(Me.mnuMainMenu)
MainMenuStrip = Me.menuStrip1
‫ﻛﻮد‬
: Exit H‫ز‬nDaqM‫אœص‬E$L‫א‬P‫'م‬7f'‫אšن‬
C#
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
‫ﻛﻮد‬
VB
Private Sub exitToolStripMenuItem_Click(ByVal sender As Object, ByVal e As
EventArgs)
Application.[Exit]()
End Sub
‫ﻛﻮد‬
:‫א‬KPTB9‫'دא‬P‫'ن א‬PQ‫א‬Wg
C#
class SimpleForm: Form
{
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
public SimpleForm()
{
Text="Example. Simple Form";
BuildForm();
}
private void BuildForm()
‫ﻛﻮد‬
314
{
fileToolStripMenuItem.Text = "File";
menuStrip1.Items.Add(mnuFile);
exitToolStripMenuItem.Text = "Exit";
menuStrip1.DropDownItems.Add(mnuFileExit);
exitToolStripMenuItem.Click += new
System.EventHandler(this.exitToolStripMenuItem_Click);
Controls.Add(this.mnuMainMenu);
MainMenuStrip = this.menuStrip1;
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
‫ﻛﻮد‬
VB
Class SimpleForm
Inherits Form
Private menuStrip1 As System.Windows.Forms.MenuStrip
Private fileToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
Private exitToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
Public Sub New()
Text = "Example. Simple Form"
BuildForm()
End Sub
Private Sub BuildForm()
fileToolStripMenuItem.Text = "&File"
menuStrip1.Items.Add(mnuFile)
exitToolStripMenuItem.Text = "E&xit"
menuStrip1.DropDownItems.Add(mnuFileExit)
AddHandler exitToolStripMenuItem.Click, AddressOf exitToolStripMenuItem_Click
Controls.Add(Me.mnuMainMenu)
MainMenuStrip = Me.menuStrip1
End Sub
Private Sub exitToolStripMenuItem_Click(ByVal sender As Object, ByVal e As
EventArgs)
Application.[Exit]()
End Sub
End Class
315
Viusal Studio.net ‫اﻧﺸﺎء ﻓﻮرم ﻋﻦ ﻃﺮﻳﻖ‬
.3
:Windows Forms ApplicationHI. File-New Fj.53،Visual Studio 2008!‫א‬a7!
:‫א‬KPT‫א‬$`، MenuStrip ZI‫ א‬Tool Box Ž‫א‬Fj7‫א‬53‫אšن‬
316
ً‫א‬S%3‫ א‬$` Exit VN‫ א‬nD Y3 aqM‫ א‬$ND ، Fj7‫ א‬FV‫ و‬$Q F ‫ع‬O . €! F‫אšن و‬
:‫א‬KPTP
.X%‫ و‬F5 nDaqs‫‹א‬53‫و‬،‫'د‬P‫א‬G‫אšنא‬
....‫^
ًא‬KgCbC0s'‫نא‬C3ˆO9C
.‫ ﺳﻨﺘﻌﺮف ﻋﻠﻰ ﻣﺤﺘﻮﻳﺎت اﻟﻮاﺟﻬﺔ اﻟﺮﺋﻴﺴﻴﺔ‬، ‫اﻵن‬
nDf‫א‬Kb‫'א‬N‫אšن‬، Visual Studiog%‫ وא‬U‫ط‬7N‫ ™ א‬nDN!‫وس‬H$‫א‬5373U
.3'‫ א‬g%‫'א‬bœ‫طא‬7N‫א‬
: ToolBox
. View - ToolBox 53lHg&‫א‬NNP>ً‫א‬S&5PQ_'، g‫‰جא‬t‫א‬j‫א‬h‫אدوא‬nD'd
!s‫א‬NP3‫زאل‬3‫ذ‬03، All Windows Forms GQ'‫€א‬i‫'د‬%'3g‘‫‰ج‬t‫א‬h‫دوא‬9‫א‬SC
W‫א‬VN‫א‬HI‫ وא‬Choose Item ‹53‫ و‬Add Tab ˆQ5D،:‘AICh‫دوא‬C!s‫وא‬$Q$%GQ'
::!G—
317
: Tabs Group
nDaqM‫א‬NP>F .gNK7N‫א‬NP>، gRO €F.t‫א‬H‫د‬V\‫ وא‬hO\‫א‬0BnD'd
:ً ^3‫א‬KPT'O\‫א‬h,T‫א‬YKQ$Ctrl+Tab
: Properties Windows
318
$‫*א‬jVIs'iH'V‫א‬lWS،‫م‬H'O‫א‬nDl$Q$QVNDgQ$ UG—t‫*א‬jVœ‫א‬g!${
. Fj7‫א‬bND
: Solution Explorer
. Resources ‫و‬H'bn‫ אو‬Classes hJ!‫و‬C Forms W!‫'א‬53 D‫و‬T3hQ')OV53NP>
: Class View
319
.:! I‫و‬k‫ودوא‬gVjVI‫ و‬Q$i‫'د‬%'\‫א‬hJO‫אאضא‬
‫ ﻓﻲ اﻧﺸﺎء اﻟﻨﻤﺎذج ؟‬Visual Studio.net ‫ﻛﻴﻒ ﻳﻌﻤﻞ ال‬
:hO3‹ ‹ Solution ExplorerFj.53Q$$`،‫'د‬PSNFt‫א‬7Q1‫@ א‬ON
: Form1.cs -1
‫א‬WSUgP€F.t‫א'אدא‬${ًMQ‫[ א‬Design] 0s'‫ˆ א‬Q5DًQ‫و‬$Q‫م‬H'O‫א‬UPR‫א‬53NPF
‫ א‬nDY3aqM‫אوא‬،Q'‫א‬Fj7‫א‬53K7NYs'‫א‬YKQ$Y4\‫ א‬53
^‫'م‬7Q،o\‫א‬
5>‫א\وسא‬H‫م‬H'O‫ א‬nDaqM‫ˆא‬Q5D^37Q1‫ذ‬KFDNP>.g‫'دאœص‬P‫א‬Oi‫אدא‬
. Class Diagramn‫و‬C Design - Code 0s'‫א‬HI‫وא‬
: Form1.Designer.cs -2
USN3$+‫א‬t‫א‬g,ً‫א'אدא‬$`:RO€F.'،‫م‬H'O‫ وא‬h‫אدوא‬zTbœ‫'אدא‬9‫א‬${NS
:‫س‬H$‫אא‬WS 53‫אول‬zŽ‫א‬
320
: Form1.rex -3
.:! I‫و‬3$+\‫א‬H‫د‬V\‫א‬nD'd
: Windows.Forms ‫ﻣﺠﺎل اﻷﺳﻤﺎء‬
.4
Windows.Forms ‫اﻟﻔﺌﺎت اﻟﺮﺋﻴﺴﻴﺔ ﻟﻌﻨﺎﺻﺮ‬
.4.1
:‫א‬hJO‫א‬53ˆT3'S‫و‬،JO‫א‬lWSU9‫ א‬VN‫'א‬S‫م‬H'O‫א‬
System.Object
.net hNjKP9‫א‬VN‫א‬
System.MarshalByRefObject
‫م‬H'O‫ ‘„ א‬byref ‫'ل‬b'‫א‬535PFN
System.ComponentModel.Component
IcomponentnF\‫ א‬Interface ‫אل‬53ˆT3
321
System.Windows.Forms.Control
.ً 79KVO:‫و‬NN
System.Windows.Forms.ScrollableControl
.bœ‫ א‬lWg 0FQ ‫ אن‬5P> gN3 ˆT3 VND ‫ א‬، Scrolls ‫אم אل‬$+‫ א‬K%‫ א‬53
System.Windows.Forms.ContainerControl
nD:I‫א‬$ 'd‫אن‬5P>gN3ˆT3VND‫א‬،AIC Controls nD'd‫אن‬5P>:%K%‫ א‬53
.AICbND
System.Windows.Forms.Form
.ً 79KVO:‫و‬NN
‫* ودوאل‬jVI 0B ‫א !¦ن‬W ، System.Windows.Forms.Form JO‫ א‬53 ˆT3 Form ‫ن אل‬C ‫ذ‬
... ‫אšن‬gDfN3S‫و‬، :K7NJO‫א‬lWSE‫א‬$C‫و‬
Form ‫ﺧﺼﺎﺋﺺ اﻟﻔﺌﺔ‬
.4.2
ob'‫א‬
bœ‫א‬
nD‫م‬$+\‫ א‬aqs$NDl3‫وא‬CWONQW‫א‬H‫א‬$Q$
AcceptButton
Enter
aTN‫א‬5–‫א‬$Q$R ‫א‬WSQ،zNC‫م‬H'O‫'ن‬PQ3$ND
ActiveMDIChild
AICh3H'O5s ‫م‬H'O‫אא‬WSK%P3‫א‬$Q$R
IsMDIChildIsMDIContainer
XML Text‫ ل‬gQ'Q
CancelButton
‫م‬$+\‫ א‬aqMQ 3$ND l3‫وא‬C WON Q W‫ א‬H‫ א‬$Q$
EscH‫ز‬nD
9‫م‬C Control Box ‫م‬H'OKS$Q$
ControlBox
‫م‬H'O‫ودא‬$KP,$Q$
FormBorderStyle
‫م‬H'O j‫א‬Fj7‫א‬$Q$
Menu
AICi$‫وא‬$`،9‫م‬C
qV‫
وא‬P‫א‬H‫ضز‬D
MaximizeBox
O‫א‬aQT‫א‬U:s‫و‬H‫ضز‬Minimize
322
9‫م‬C‫وز‬$NQ'O‫א‬aQT‫ א‬U‫אض‬$Q$
ShowInTaskbar
Q i3 ‫ ول‬lH'g& $ND ‫م‬H'O Q‫א‬$‫ א‬17 $Q$
StartPosition
nF\‫ א‬enumeration ~‫ ل א‬I
53 SHI‫א‬
FormStartPosition
‫ אل‬53 SHI‫ א‬Q t‫م وא‬H'O‫ א‬$Q$
WindowState
FormWindowStatenF\‫א‬enumeration
:‫ ﻋﻠﻰ اﻟﻌﻨﺎﺻﺮ اﻟﺘﺎﻟﻴﺔ‬FormStartPosition ‫ اﻟﻤﺴﻤﻰ‬enumeration ‫وﻳﺤﺘﻮي اﻟـ‬
: ‫ ﻓﻴﺤﺘﻮي ﻋﻠﻰ‬FormWindowState ‫أﻣﺎ‬
Form ‫دوال اﻟﻔﺌﺔ‬
.4.3
ob'‫א‬
‫א‬$‫א‬
‫م‬H'O‫א‬aTN
Activate()
‫م‬H'O‫א— قא‬
Close()
,T‫א‬oVN3 U‫م‬H'O‫א‬0s‫و‬
CenterToScreen()
S‫'د‬%‫و‬UzN‫א‬h,T‫ضא‬D‫(م‬$Q$
LayoutMDI()
$ 9‘ gOI \ ‫'ع‬%‫ א‬5P> 9 r Dialog iH'V ‫م‬H'O‫ض א‬D
ShowDialog()
g. —‫א‬
323
Form ‫أﺣﺪاث اﻟﻔﺌﺔ‬
.4.4
ob'‫א‬
E$L‫א‬
‫'م‬7Q3$ND‫ אو‬Activate 3]z‫م'א‬H'O‫א‬aTNQ3$NDE$L‫אא‬WSˆ1NQ
Activated
:P31nD1TN‫א‬iW!N‫א‬:´‫م‬$+\‫א‬
‫א–— ق‬E$C$Q3$ND
Closing
‫א–— ق‬E$gNQ3$ND
Closed
‫م‬H'O‫—
א‬IŠz,„‘PR‫א‬GSWQ3$ND
Deactivate
Load
nD ‫م‬H'O‫ א‬H'g& K. E$L‫א א‬WS ˆ1NQ 5P‫ و‬، ‫م‬H'O‫ א‬KF Q 3$ND:
-ً D',z1I‫^ א‬C53$‫وא‬GN`−ً bC,T‫א‬
S‫'د‬%‫ و‬UzN‫א‬h,T‫א‬53$‫وא‬$Q$$ND
MDIChildActive
.NSgsNt‫وא‬g‫!Ÿא‬P0FQ'g!‫א‬W‫و‬، Control JO‫א‬53ˆT3 ‫م‬H'O‫!¦نא‬،ً7ًMQ‫ذא‬F
Control ‫اﻟﻔﺌﺔ‬
.5
Controls ‫ﺧﺼﺎﺋﺺ اﻟﻔﺌﺔ‬
.5.1
ob'‫א‬
bœ‫א‬
Oœ‫'نא‬
BackColor
I‫א‬$‫*א‬N‫'نא‬
ForeColor
iH'bOI
BackgroundImage
:! I‫و‬:D'‫و‬:F`‫و‬aœ‫א‬
Font
‫م‬H'O‫وא‬Ci‫!'قאدא‬H'‫ א‬$NDg(QW‫א‬,p\‫'عא‬
Cursor
Fg3‫م‬H'O‫א‬nDh‫دوא‬9‫نא‬P3 €^t‫ وא‬Dock ‫אل‬bI03K3
Anchor
‫م‬H'O‫
`א‬q
324
gQ')G i‫ دא‬j7`
AutoSize
X '‫א‬$L‫א‬53‫م‬H'O‫אوא‬i‫دא‬9‫א‬0s'3
Top
X Q‫א‬$L‫א‬53‫م‬H'O‫אوא‬i‫دא‬9‫א‬0s'3
Left
X KO‫א‬$L‫ א‬53‫م‬H'O‫אوא‬i‫دא‬9‫א‬0s'3
Bottom
X 5>‫א‬$L‫א‬53‫م‬H'O‫אوא‬i‫دא‬9‫א‬0s'3
Right
‫ود‬$L‫א‬
Bounds
0353
ClientRectangle
‫'ل‬1‫א‬
Height
‫אض‬
Width
:3$D53‫م‬H'O‫אوא‬i‫دא‬PR‫א‬P3‫א‬$Q$
Enabled
zOI9‫وא‬H'g(‫א‬
Visible
Shift‫ و‬Ctrl ‫ و‬Alt ‫אل‬K^3 ModifierKeys ‫אل‬iz‫א‬.
ModifierKeys
(oVN\‫–א‬Q‫א‬−5>C) ‫א\وس‬53‫'ط‬qM\‫א‬H‫!א‬3
MouseButtons
TabH‫ ز‬1‫'א‬gN‫ل‬7 bN‫א‬G‫د‬$
TabIndex
TabH‫ لز‬I53VN‫'ل‬b'‫א‬0N3
TabStop
1‫و‬0Y3!OT‫ א‬%H‫د‬
Opacity
i‫دא‬9‫א‬KI‫*א\وضدא‬N‫א‬
Text
nD ‫ ًא‬H‫د‬. VN‫ ن א‬U I‫א‬$‫ א‬h‫'ل دאوא‬b'‫ א‬53 NPe
Controls
:I‫دא‬bNDX‫א‬
Controls ‫أﺣﺪاث اﻟﻔﺌﺔ‬
.5.2
ob'‫א‬
E$L‫א‬
‫ \وس‬aqM‫א‬
Click
‫\وس‬Y1qs
DoubleClick
i‫قאدא‬1„‘‫'لא\وس‬I‫د‬
MouseEnter
i‫دא‬9‫قא‬153‫وجא\وس‬I
MouseLeave
KO9 ‫א\وس‬H‫ز‬aqs
MouseDown
‫א\وس‬H‫ز‬1qs5D0b9‫א‬0!H
MouseUp
325
.MouseHover17‫א\وس !'ق‬H'D
MouseMove
Wheel‫אل‬nDaqM
MouseWheel
‫د‬H'P‫א‬53H‫ز‬aqs
KeyPress
‫'ط‬qM\‫א‬H‫א‬5D0b9‫א‬0!H
KeyUp
KOH‫א‬aqs
KeyDown
L‫א‬i‫دא‬9‫!'قא‬i‫אدא‬GR
DragDrop
AICi‫¡لאدא‬i‫'لאدא‬I‫د‬
DragEnter
‫وج‬I
DragLeave
i‫!'قאدא‬H'D
DragOver
‫א‬E$
Paint
System.Windows.Forms.Control ‫أدوات‬
.6
537T3h‫אدوא‬K‫ن‬CSg!3D17‫ول‬C،h‫'مאض אدوא‬7NN¦ˆ‫سא‬H$‫א‬U‫ذ‬
.i,3ˆ‫سא‬H$‫א‬UgTNF.t‫א‬E‫א‬$‫* وא‬jVœ0Fi‫دא‬C C ‫א!¦ن‬W Controls JO‫א‬
.NQ$j‫א‬h‫ض™ אدوא‬N‫אšن‬
Button .6.1
:K^3*jVœ‫™א‬nD'd،ً‫א‬$%‫د‬D3CH‫ز‬
.3‫א‬H‫ ز‬g(3$Q$:FlatStyle
.3‫א‬H‫ز‬53*N‫א‬0s'3:TextAlign
326
CheckBox .6.2
:K^3!s‫* א‬jVInD'd،bNDi$DHI‫א‬NNP>،‫د‬$\‫א‬HI9‫א‬H‫ز‬
.HI9‫ א‬:CheckState
.( ً j%KO3−KO3
—−KO3)^‹bI KFd:'$Q$R :ThreeState
RadioButton .6.3
panel U gN3 K 0s i3 53^ :3‫א‬$+‫ א‬$Q €N' ، $‫ وא‬HI FQ :NP‫ אˆ و‬K^3
.o†
ListBox ‫و‬ComboBox .6.4
327
.X'1\‫`א‬L‫א‬G^‫ وא‬$‫وא‬obU„‫و‬9‫א‬،h‫א‬HI5Fs53HI Fj.
.... Items.Remove ‫ و‬Items.Add K^3 Collection.List USNFt‫*א‬jVœ‫א‬0BnD'd
Textbox .6.5
: !s9‫א‬gVjVI™،gI‫دא‬P‫م‬$+FFVi‫دא‬C
.a7!iz‫א‬7g% :ReadOnly
.‫ل‬I‫* د‬N‫א‬03K%Ug(QW‫א‬3‫ א‬:PasswordChar
.1‫א‬i‫د‬$3 g´vF‫ א‬:MultiLine
.*NnV.9‫'لא‬1‫ א‬:maxLength
.QF‫א‬,‫א‬:ScrollsBar
.ً ^3‫د‬H‫وو‬23K^3i‫‘„!אدא‬:'b‫و‬$*N‫א‬fO‫א‬:WordWrap
HI‫ א‬NP3 ‫'ن‬P ‫א‬W ،System.Windows.Forms.ScrollableControl JO‫ א‬53 7T3 g‫ א‬
. ScrollBars nF\‫ א‬enumeration ‫אل‬530s‫و‬
: ‫ﺗﻄﺒﻴﻘﺎت ﺳﺮﻳﻌﺔ ﻋﻠﻰ ﻣﺮﺑﻊ اﻟﻨﺼﻮص‬
:ً ^3‫م‬.H‫א‬A'K7Q9‫'ص‬VN‫א‬03KŽ−
C#
private void TextBox1_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
if ((e.KeyChar < '0' | e.KeyChar > '9')) {
e.Handled = true;
}
}
‫ﻛﻮد‬
328
VB
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If (e.KeyChar < "0"c Or e.KeyChar > "9"c) Then
e.Handled = True
End If
End Sub
‫ﻛﻮد‬
:*N‫א‬03KI‫دא‬F5DR‫א‬−
C#
private void Button1_Click(object sender, System.EventArgs e)
{
// R‫ن`א‬P3‫אول‬nD'RW‫
א‬q\‫א‬
‫ﻛﻮد‬
int index;
//R‫א‬F
string SearchWord = "Ahmed";
//i‫دא‬ ‫ل‬79‫א‬
TextBox1.Focus();
//Q‫א‬$‫א‬UlN!DW‫
א‬q\‫א‬UFP‫א‬Q‫א‬$‫ن‬P30s‫و‬
index = TextBox1.Text.IndexOf(SearchWord);
// k'1‫و‬FP‫א‬Q‫א‬$53$Q$R‫*א‬jVI‫אم‬$+FP‫א‬$Q$
TextBox1.SelectionStart = index;
TextBox1.SelectionLength = SearchWord.Length;
}
VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
' R‫ن`א‬P3‫אول‬nD'RW‫
א‬q\‫א‬
Dim index As Integer
'R‫א‬F
Dim SearchWord As String= "Ahmed"
'i‫دא‬ ‫ل‬79‫א‬
TextBox1.Focus()
'Q‫א‬$‫א‬UlN!DW‫
א‬q\‫א‬UFP‫א‬Q‫א‬$‫ن‬P30s‫و‬
‫ﻛﻮد‬
329
index = TextBox1.Text.IndexOf(SearchWord)
' k'1‫و‬FP‫א‬Q‫א‬$53$Q$R‫*א‬jVI‫אم‬$+FP‫א‬$Q$
TextBox1.SelectionStart = index
TextBox1.SelectionLength = SearchWord.Length
End Sub
Label .6.6
.a7!–KQ$.
— ‫'ص‬VN‫ض א‬i‫دא‬C
Panel ‫و‬GroupBox .6.7
.gI‫א‬$AICh‫دوא‬C0s‫و‬5P>Q‫و‬h‫دوא‬C
RichTextBox .6.8
330
Y ‫ق‬HO‫' א‬S TextBox Y‫ و‬gN ‫ق‬HO‫ א‬، O† h7N nD ' ‫ אن‬gQ'[ F * i‫دא‬C
.H'b‫و‬h7NnD'd0\7‫א‬iH'V‫א‬، Wordpad ‫و‬Notepad
:‫!א‬s9‫*א‬jVœ‫א‬nD'
.*N‫א‬fO‫א‬$Q$R :Wordwrap
.1‫دא‬$D$Q$R:Lines
.‫و'ل‬Q‫א‬$17‫אو‬،Qg‫و‬Q‫א‬$17ˆQ 5D*N‫א‬53z%$Q$R :Select
.SelectionColor‫א'ن‬K^3،‫د‬$[‫א‬z` aIˆN$Q$R:SelectionXXX
.‫ل‬7 .g%‫ًو‬j7€Z9‫א‬5Q‫و‬ND$Q$R:DetectUrls
:‫!א‬s9‫وאلא‬$‫א‬nD'd F
.Y3H353Vo3 O :LoadFile
.Y3‫ن‬P3Uo\‫א‬ªOL :SaveFile
: ‫أﻣﺜﻠﺔ ﺳﺮﻳﻌﺔ‬
:IŠo3UªOL‫‹א‬53‫و‬Vo353*N‫א‬i‫אدא‬hQ')iz‫א‬7−
C#
RichTextBox1.LoadFile("C:\Ahmed.txt", RichTextBoxStreamType.PlainText);
RichTextBox1.SaveFile("C:\Ahmed2.txt", RichTextBoxStreamType.PlainText);
‫ﻛﻮد‬
VB
RichTextBox1.LoadFile("C:\Ahmed.txt", RichTextBoxStreamType.PlainText)
RichTextBox1.SaveFile("C:\Ahmed2.txt", RichTextBoxStreamType.PlainText)
‫ﻛﻮد‬
„‘ ‫'ع‬N‫ א‬aM ‫'م‬7N! rtf ‫'ع‬N‫ א‬53 h7N nD 'd V o\‫و' ن א‬
:ً ^3‫א‬KPTRichTextBoxStreamType.RichText
C#
RichTextBox1.LoadFile("C:\Ahmed.rtf ", RichTextBoxStreamType.RichText);
‫ﻛﻮد‬
331
RichTextBox1.SaveFile("C:\Ahmed2.rtf ", RichTextBoxStreamType.RichText);
VB
RichTextBox1.LoadFile("C:\Ahmed.rtf ", RichTextBoxStreamType.RichText)
RichTextBox1.SaveFile("C:\Ahmed2.rtf", RichTextBoxStreamType.RichText)
‫ﻛﻮد‬
R‫א‬2jK5Q'‫'م‬7Ni\‫א‬lWS5P‫و‬،*N‫א‬i‫دא‬:FDˆW‫א‬R‫^لא‬3ˆ1$N‫وאšن‬
:AIi$‫وא‬S$Q$53ً9$
C#
‫ﻛﻮد‬
int index=0;
while((index = richTextBox1.Text.IndexOf(textBox1.Text, index))!=-1)
{
richTextBox1.Select(index, textBox1.Text.Length);
richTextBox1.SelectionColor = System.Drawing.Color.Red;
index += textBox1.Text.Length;
}
MessageBox.Show("hFP‫א‬5Q'53zg9‫;)"”א‬
VB
Dim index As Integer = 0
While (index = richTextBox1.Text.IndexOf(textBox1.Text, index)) <> -1 richTextBox1.[Select](index, textBox1.Text.Length)
richTextBox1.SelectionColor = System.Drawing.Color.Red
index += textBox1.Text.Length
End While
‫ﻛﻮد‬
MessageBox.Show("hFP‫א‬5Q'53zg9‫)"”א‬
:‫א‬KPTWON‫א‬2‫'ن‬P‫و‬
332
Timer .6.9
:QH‫א‬P 3‫ אوא‬KFD U $O ، Y3 Interval K lWON Q W‫ وא‬Ticker E$ k ، €.pF i‫دא‬C
.N3‫قز‬H‫'א‬O
aM.ًMQ‫א‬،i$‫دل‹وא‬3S‫ و‬1000„‘ IntervalbIaM.،‫^'א‬DKFD‫^ل‬3
:Tick E$L‫א‬U‫'دא‬P‫א‬P.‫ًو‬MQ‫א‬True„‘Enabledbœ‫א‬
C#
label1.Text = DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" +
DateTime.Now.Second;
‫ﻛﻮد‬
VB
label1.Text = DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" +
DateTime.Now.Second
‫ﻛﻮد‬
333
:‫א‬WSK^3ًJ,2N‫'نא‬P‫و‬
TreeView .6.10
.g!W‫و‬bNDC!s‫א‬: I535P>W‫ وא‬Nodes 'S9‫א‬SVND ،i`T‫א‬i‫دא‬C‫ض‬
:i‫אدא‬lWS5Fs:! I‫و‬H'b!s‫א‬n‫ˆو‬N‫א‬U
q‫א‬5P>
:‫א‬a‫אא‬53gND$Q\‫א‬nDf‫א‬NP>
‫رابط‬
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.aspx
334
Progressbar .6.11
!s‫ א‬n‫ وאد‬nD‫ א‬$L‫ א‬$Q$R Minimum - Maximum S 9‫ א‬:VjVI ، ‫م‬$7‫ א‬,p3 ‫ض‬
Style bœ‫ لא‬I53‫م‬$7‫א‬F style $Q$NP>،i3K‫م‬$7‫ א‬H‫א‬$73$Q$R Step b+
. ProgressBarStyle nF\‫ א‬enumeration ‫אل‬53 C7t‫وא‬
. Value bœ‫אمא‬$+ ً 79bœ‫א‬$Q$5P>
Trackbar .6.12
.h'V‫™א‬OI‫و‬0!‫ אœص‬Trackbar K^3،:F7PR53€‫א‬NP Progressbar K :T3
DateTimePicker .6.13
¢QH‫ א‬X'‫ א‬$Q$R Format bœ‫ א‬53 ‫ אض‬X'‫ א‬$Q$ NP> ، h.‫ وאو‬¢QH‫ א'א‬HI9 i‫دא‬C
$‫و‬¢QHnV.‫א‬$0s‫و‬5P>F Valuebœ‫א‬53‫א\وض‬¢QH‫א‬nD‫'ل‬VL‫א‬5P>.‫א\وض‬
.MinDate - MaxDateYbœ‫ˆא‬Q5Dn‫د‬C
335
0.'3„‘‫]نא‬OC‫א‬W ... gbOnDf‫א‬U€.'‫א‬Ds‫א‬53A‫و‬$%9‫אًو‬$%i
^h‫אدوא‬
: i‫دא‬CKPًVOً,${€!'‫و‬PQ3
‫رابط‬
http://msdn.microsoft.com/en-us/library/aa984065(VS.71).aspx
Dialogs
.7
‫'م‬7N ^‫ א\ א‬U ‹ ، N ‫ص‬I $‫ وא‬FV 9
ً ‫و‬C ‫'م‬7N QH‫'א‬L‫ א‬h\‫ א‬5D ND's'3 Q‫א‬$ U
.jT‫א‬QH‫'א‬L‫א‬h\‫™א‬h3‫א‬$+‫ א‬nDf
„‘ FormBorderStylebI aM . ، resizeable ‫ אل‬bI zq . ، $Q$% ‫م‬H'! zT .
h\‫א‬G—CFV ‫'ن‬PQ7Q1‫א‬lWg ... MaximizeBox‫ و‬MinimizeBox zOI.،FixedDialog
.QH‫'א‬L‫א‬
bN‫ א‬53ً‫א‬$‫وא‬2N‫'نא‬PQ Dialog ‫و‬CH‫'א‬03‫א‬U،'dFH‫'א‬L‫א‬0\‫ א‬FV.‫אšن‬
:‫א‬7‫א‬nD'dW‫ وא‬DialogResultnF\‫ א‬enumeration U!\‫א‬
Abort, Cancel, Ignore, No, None, OK, Retry, Yes
.H+\‫א‬H‫ א‬nD‫م‬H'O AcceptButton ‫אل‬bIaM OK F7‫א‬$QW‫א‬H‫א‬aM
CancelButton bœ‫א‬$< Cancel b+Na39‫ًא‬MQ‫א‬
:ً ^3‫א‬KPT ShowDialog 3‫مא‬$+ Dialog H‫'א‬03iH'V‫م‬H'!Hg&9
C#
newDialog.ShowDialog();
‫ﻛﻮد‬
VB
newDialog.ShowDialog()
‫ﻛﻮد‬
336
‫א‬KPTN‫'دאœص‬P‫א‬GPN،lHI‫”א‬H‫!אز‬3‫و‬:ND{N‫א‬7‫ א‬iz‫א‬7%rN‫و}א‬5P‫و‬
:‫א\^ل‬KnD
C#
if (newDialog.ShowDialog() == DialogResult.Cancel)
{
// do something
}
else if (newDialog.ShowDialog() == DialogResult.Ok)
{
// do something else
}
‫ﻛﻮد‬
VB
If newDialog.ShowDialog() = DialogResult.Cancel Then
' do something
ElseIf newDialog.ShowDialog() = DialogResult.Ok Then
' do something else
End If
‫ﻛﻮد‬
KQ$ ً ^3 . ‫א‬W ، public '1\‫ א‬7‫ א‬oQ ND ً 3‫'ن א‬P Dialog ‫ אل‬hQ') iz‫א‬. N‫و'و‬
:‫ א‬KPT*N‫א‬03
C#
public System.Windows.Forms.TextBox TextBox1;
‫ﻛﻮد‬
VB
Public TextBox1 As System.Windows.Forms.TextBox
‫ﻛﻮد‬
MessageBox
.7.1
:‫א‬KPTa‫א‬gH'b، MessageBox QWR‫א‬KjH'S Dialogs ‫אل‬53Kg‫ وא‬a9‫'عא‬N‫א‬
C#
MessageBox.Show("Welcome ...");
‫ﻛﻮد‬
VB
‫ﻛﻮد‬
337
MessageBox.Show("Welcome ...")
]PR‫א‬، overloads20$` Show ‫א‬$kH‫א‬5P>t‫א‬h‫א‬Z3H‫!א‬3€%'
:NSgN3 YN‹‫ضא‬N،QQWR‫א‬jHUKP,
:3 QQWHHg&‫א‬
C#
MessageBox.Show("Welcome
...","Title",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
‫ﻛﻮد‬
VB
MessageBox.Show("Welcome
...","Title",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
‫ﻛﻮد‬
:g(\‫א‬
: ًs‫א‬Z!‫א‬gN3$‫ وא‬K%03،h9i$DY¤
§QQWHHg&‫א‬
C#
DialogResult reslt = MessageBox.Show("Do you want to save", "Title",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button1);
if (reslt = DialogResult.Yes)
MessageBox.Show("you want to save.");
else if (reslt = DialogResult.No)
MessageBox.Show("you don't want to save.");
else if (reslt = DialogResult.Cancel)
MessageBox.Show("you cancel this operation.");
‫ﻛﻮد‬
338
VB
Dim reslt As DialogResult = MessageBox.Show("Do you want to save", "Title",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1)
If reslt = DialogResult.Yes Then
MessageBox.Show("you want to save.")
ElseIf reslt = DialogResult.No Then
MessageBox.Show("you don't want to save.")
ElseIf reslt = DialogResult.Cancel Then
MessageBox.Show("you cancel this operation.")
End If
‫ﻛﻮد‬
a‫אאא‬WS‫ ل‬I53ًBgs‫אא‬NP>،‡‫א‬...i$D3o3Hg&‫ א‬،AICh‫א‬HI‫א‬i$D¤NS
‫رابط‬
http://msdn.microsoft.com/en-us/libr...ebox.show.aspx
Dialogs Controls
.7.2
OnD‫אšن‬H‫و‬$‫א‬z%،SzT‫א‬ONF‫و‬QH‫'א‬L‫א‬h\‫ א‬53a‫'عא‬N‫א‬nDN!‫אن‬$
...h‫אدوא‬5Fsi‫'د‬%'\‫אא‬QH‫'א‬L‫א‬h\‫אم א‬$+‫א‬
Color Dialog .7.3
:ً ^3iH'VOœ‫
'نא‬qً1 9
ً ^3‫]אšن‬TNN‫ و‬ToolBox ‫אل‬53:!s.،‫א'אن‬HI‫א‬03
339
:‫א‬3‫א‬:! G‫وא‬3CH‫ وز‬picturebox iH'bosC
C#
if (colorDialog1.ShowDialog() == DialogResult.OK)
pictureBox1.BackColor = colorDialog1.Color;
else
MessageBox.Show("cancel operation");
‫ﻛﻮد‬
VB
If colorDialog1.ShowDialog() = DialogResult.OK Then
pictureBox1.BackColor = colorDialog1.Color
Else
MessageBox.Show("cancel operation")
End If
‫ﻛﻮد‬
t‫ وא‬AllowFullOpen K^3‫אم‬$+9‫א‬j,
—gNP‫א‬WSH‫'א‬L‫א‬03U!s9‫* א‬jVœ‫™א‬¤NS
:ً ^3‫א‬KPT7‫'אنא‬9‫—
א‬HI‫א‬53‫م‬$+\‫א‬0N301
340
:ً ^3‫א‬KPTi,3K3P Sg(t‫ א‬fullopen bœ‫وא‬
:€!'‫و‬PQ353VOa‫א‬H
‫رابط‬
http://msdn.microsoft.com/en-us/library/ms646375.aspx
341
Font Dialog .7.4
:*03aI
q‫^ل‬3 KF‫'مאšن‬7N،‫'ط‬1œ‫א‬HI9‫م‬$+Q
C#
fontDialog1.ShowColor = true;
fontDialog1.Font = textBox1.Font;
fontDialog1.Color = textBox1.ForeColor;
if (fontDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Font = fontDialog1.Font;
textBox1.ForeColor = fontDialog1.Color;
}
‫ﻛﻮد‬
VB
fontDialog1.ShowColor = True
fontDialog1.Font = textBox1.Font
fontDialog1.Color = textBox1.ForeColor
If fontDialog1.ShowDialog() = DialogResult.OK Then
textBox1.Font = fontDialog1.Font
textBox1.ForeColor = fontDialog1.Color
End If
‫ﻛﻮد‬
342
:€!'‫و‬PQ353VOa‫א‬H
‫رابط‬
http://msdn.microsoft.com/en-us/library/system.windows.forms.fontdialog(VS.80).aspx
Open And Save Dialogs .7.5
g(O‫ن‬P3 $Q$‫و‬ChO\‫!א‬FD$Q$Rg3‫א‬$+‫א‬Qi‫אد‬U،QH‫'א‬L‫א‬h\‫א‬53 YD'g,‫א‬
::(O ‹ 53‫ و‬:D KQ$‫ א‬، V o3 O : I 53 ‫'م‬7 a ‫^ل‬3 KF ‫'م‬7N ،
!s ‫'م‬75½‫
א‬IC‫و‬،OIŠ‫و‬ªORH‫ز‬os، Multiline=True bIK%‫وא‬a *03os‫א‬
.i,3‫'د‬P‫ لא‬I53gOMNK SaveFileDialog ‫و‬OpenFileDialog
:gN3$‫وא‬HI‫‹א‬53‫و‬VN‫א‬hO\‫א‬$Q$RH‫'א‬L‫א‬0\‫אمא‬$+‫ א‬SNQ$FD‫ول‬C
C#
string fileToOpen="";
OpenFileDialog openFile = new OpenFileDialog();
openFile.DefaultExt = "txt";
openFile.Filter = "Word documents (*.txt)|*.txt";
if (openFile.ShowDialog() == DialogResult.OK)
fileToOpen = openFile.FileName;
‫ﻛﻮد‬
VB
Dim fileToOpen As String = ""
Dim openFile As New OpenFileDialog()
openFile.DefaultExt = "txt"
openFile.Filter = "Word documents (*.txt)|*.txt"
If openFile.ShowDialog() = DialogResult.OK Then
fileToOpen = openFile.FileName
End If
‫ﻛﻮد‬
:ً 7SNF7Q1*03U:Q')0s‫و‬F‫'م‬7N،
q3Uo\‫ א‬H3NQ$b‫אšنא‬
C#
if (fileToOpen != "")
{
using (System.IO.StreamReader s1 =
‫ﻛﻮد‬
343
System.IO.File.OpenText(fileToOpen))
{
string input = null;
textBox1.Text = "";
while ((input = s1.ReadLine()) != null)
{
textBox1.Text += input;
}
}
}
VB
If fileToOpen <> "" Then
Using s1 As System.IO.StreamReader = System.IO.File.OpenText(fileToOpen)
Dim input As String = Nothing
textBox1.Text = ""
While (input = s1.ReadLine()) IsNot Nothing
textBox1.Text += input
End While
End Using
End If
‫ﻛﻮد‬
:o\‫א‬ªO:!‫'د‬W‫نא‬P\‫א‬$Q$RªOL‫ א‬H‫'א‬03‫م‬$+N‫אšن‬
C#
string fileToSave = "";
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
fileToSave = saveFileDialog1.FileName;
‫ﻛﻮد‬
VB
Dim fileToSave As String = ""
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
If saveFileDialog1.ShowDialog() = DialogResult.OK Then
fileToSave = saveFileDialog1.FileName
End If
‫ﻛﻮد‬
:lHI‫م‬$+\‫مא‬.W‫א‬H\‫א‬UVN‫א‬o\‫א‬ªOr‫'م‬7 ،ً7NFF‫و‬
344
C#
if (fileToSave!="")
{
using (System.IO.StreamWriter w1 =
System.IO.File.CreateText(fileToSave))
{
w1.WriteLine(textBox1.Text);
}
}
‫ﻛﻮد‬
VB
If fileToSave <> "" Then
Using w1 As System.IO.StreamWriter = System.IO.File.CreateText(fileToSave)
w1.WriteLine(textBox1.Text)
‫ﻛﻮد‬
End Using
End If
:‫א‬WSK^3ًJ,‫'ن‬P2N‫א‬
:NSFgND$Q\‫א‬nD‫ ع‬9‫ א‬NP>،YNjP‫ א‬P!s9‫*א‬jVœ‫™א‬¤NS
345
‫رابط‬
http://msdn.microsoft.com/en-us/library/aa287592(VS.71).aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.savefiledialog.aspx
...Oo353^C$Q$، a7!o\‫אوאא‬$¡‫אא‬iz‫א‬.‫אو‬hO\‫א‬53‫'ع‬$Q$NP>
.‡‫א‬
print Dialog .7.6
:€!'‫و‬PQ353‫א‬a‫אא‬¤$OQ‫אن‬5P> ،D1‫א‬FD*jVIUPR‫م‬$+Q
‫رابط‬
http://msdn.microsoft.com/en-us/library/system.windows.forms.printdialog.aspx
‫أﺣﺪاث اﻟﻤﺎوس‬
.8
346
Properties 53 MouseDown E$L‫‘„א‬GSWN ،‫א\وس‬53‫'ط‬qM\‫א‬H‫ً\!א‬9‫و‬C
:‫'دא‬P‫א‬GP‹53‫و‬
C#
if (e.Button == MouseButtons.Left)
MessageBox.Show("Left click");
if (e.Button == MouseButtons.Right)
MessageBox.Show("Right click");
if (e.Button == MouseButtons.Middle)
MessageBox.Show("Middle click");
‫ﻛﻮد‬
VB
If e.Button = MouseButtons.Left Then
MessageBox.Show("Left click")
End If
If e.Button = MouseButtons.Right Then
MessageBox.Show("Right click")
End If
If e.Button = MouseButtons.Middle Then
MessageBox.Show("Middle click")
End If
‫ﻛﻮد‬
347
: MouseMove E$Uً ^3‫א\وس‬gD >t‫א‬17N‫و\!א‬
C#
this.Text = "X: " + e.X + ", Y:" + e.Y;
‫ﻛﻮد‬
VB
Me.Text = "X: " + e.X + ", Y:" + e.Y
‫ﻛﻮد‬
‫أﺣﺪاث اﻟﻜﻴﺒﻮرد‬
.9
key_up :E$Uً ^3‫א‬3‫א‬GP‫'ط‬qM\‫א‬H‫ אœص‬E$L‫א‬iz‫א‬7
C#
this.Text="key: " + e.KeyCode.ToString();
‫ﻛﻮد‬
VB
Me.Text = "key: " + e.KeyCode.ToString()
‫ﻛﻮد‬
U ^‫ وא‬key U ‫ אول‬H‫ א‬0MN ، L‫ א‬H‫ א‬03 ً ^3 ‫'ط‬qM3 IŠ H‫ ز‬¤NS ‫ ‘ذא ن‬3 !\ 5P‫و‬
:‫א‬KPTModifier
C#
this.Text = string.Format("Key: {0} Modifier: {1}",e.KeyCode.ToString(),
e.Modifiers.ToString());
‫ﻛﻮد‬
348
VB
Me.Text = String.Format("Key: {0} Modifier: {1}", e.KeyCode.ToString(),
e.Modifiers.ToString())
‫ﻛﻮد‬
...gDzNhF‫™א‬WON‫ و‬IF ‫אم‬$+E‫א‬$‫א‬iz‫א‬. P3‫אن‬¤HI9D‫دא‬9ً
‫‪349‬‬
‫اﻟﺒﺎب‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‪GDI+‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‪15‬‬
350
351
GDI+ ‫ﻣﻘﺪﻣﺔ إﻟﻰ‬
.1
‫م‬H'O‫ א‬nDD 2 h3'H K%‫ א‬53 KM!‫ א‬9
ً ' !'‫ و‬System.Drawing JO‫ א‬3‫ אوא‬lWS 0
:‫א‬j‫א‬hJO‫ א‬nD'،:! I‫אو‬h11+\‫وא‬
hFDUg3$+t‫א‬9‫شא‬O‫ موא‬.‫ א‬nD'،j‫א‬JO‫ א‬:System.Drawing .1
.‫א‬
K^3‫א‬nD ¤$Dt‫وאلא‬$‫ א‬53AICD'F‫م‬$7: System.Drawing.Drawing2D .2
geometric transforms ‫و‬gradient brushes
WON‫ و‬I‫א‬$‫ א‬h‫ א‬iz‫א‬.‫ و‬H'V‫ א‬nD FD U ¤$D : System.Drawing.Imaging .3
.O+\‫א‬hF‫א‬
.D1‫א‬03K3‫وא‬D1H'b„‘h3'HKQ'nD¤$D :System.Drawing.Printing .4
.:! I‫'طو‬1œ‫א‬033'HiH'VK3‫ א‬:System.Drawing.Tex .5
System.Drawing ‫ﻣﺤﺘﻮﻳﺎت اﻟﻔﺌﺔ‬
.2
:SgQ')SC،ً3‫א‬$+‫ وא^א‬9‫א‬JO‫א‬S
ob'‫א‬
VN‫א‬
iH'V‫א‬h3'3z‫'א‬9
Bitmap
‫א'אع‬i$Dk‫و‬،5Q'‫א‬Fi,!
Brush
double N7 ‫אم‬$+ ‫ א‬Buffer ‫א אل‬WS ‫אم‬$+ NP>
BufferedGraphics
buffering
5Q'‫אوא‬hFDUg3‫א‬$+‫א‬5P>t‫א'אنא‬SystemColors
Color
.‫'ص‬VN‫א‬HhFDUg3‫א‬$+‫א‬5P>t‫'طא‬1œ‫ א‬FontFamily
Font
ً 79gDfN t‫وא‬،‫א‬hFDU9‫א‬5jP‫א‬
Graphics
h'7Q9‫א‬03K3‫א‬SystemIcons
Icon
H'V‫א‬hFˆQ3KP abstract class ‫אل‬
Image
R\‫א‬H'V‫ א‬03K3
ImageAnimator
352
‫'אع‬Ci$D:‫و‬،‫א‬hF.
Pen
h‹‫א‬$9‫א‬03K3
Point
K13
Rectangle
KPT\‫א‬X
Size
‫'ص‬VN‫א‬hF ˆQ3KnDJO‫א‬lWS'
StringFormat
.‫ ًא‬$%i$O3*jVIi$D:‫و‬،€C‫ل‬P,9‫א‬03K3‫ص‬I
Region
: double buffering
، flicker PT3U i$‫وא‬i3‫م‬$+FlH'g&‹K73 buffer U‫ل‬F9 FN7S
:NS53gDf‫א‬5P>‫א‬hN7UiH'gT3N7S‫'م‬F‫א‬nD
‫رابط‬
http://msdn.microsoft.com/en-us/library/b367a457.aspx
:a‫אאא‬WS‫ ل‬I53gQ')0B 5D$Q\‫!א‬3NP>F
‫رابط‬
http://msdn.microsoft.com/en-us/library/system.drawing.aspx
Graphics ‫اﻟﻔﺌﺔ‬
.3
:‫ق‬i$lzT‫א‬5P> ،‫א‬FDU‫א‬5jP‫'א‬S Graphics 5jP‫א‬
::! I‫ و‬picture box 53‫'ن‬C$\‫@א‬O‫و‬،‫م‬H'O‫א‬53−
C#
Graphics myGraphic = Form1.CreateGraphics();
‫ﻛﻮد‬
VB
Dim myGraphic As Graphics = Form1.CreateGraphics()
‫ﻛﻮد‬
:ً ^3‫א‬KPT PaintEventArgs 5jP‫ˆא‬Q5D،ً ^3 ‫م‬H'Oi‫אאدא‬E$53‫و‬C-
353
C#
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics myGraphic = e.Graphics();
}
‫ﻛﻮد‬
VB
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs)
Dim myGraphic As Graphics = e.Graphics()
End Sub
‫ﻛﻮد‬
:‫א‬3‫אوא‬nDJO‫א‬lWS'‫و‬
ob'‫א‬
VN‫א‬
ًi‫'د‬%'3iH'b53H5jKFD
FromHdc()
FromHwnd()
FromImage()
Clear()
5jP‫ א‬hQ')3
-.
$NSKP,‫ אو‬iH'bH
DrawArc()
hNRN3gNP‫و‬SN3fDC9 Beziers - H
DrawBeziers()
nNRN3H
DrawCurve()
‫و‬MKP,H
DrawEllipse()
'7Q‫א‬H
DrawIcon()
73aI H
DrawLine()
‫'ط‬1œ‫א‬53D'F H
DrawLines()
a1†H
DrawPie()
H3H
DrawPath()
K13H
DrawRectangle()
h 13H
DrawRectangles()
*H
DrawString()
‫و‬MKP,5Q'
FillEllipse()
a1†5Q'
FillPie()
354
0M35Q'
FillPolygon()
035Q'
FillRectangle()
H35Q'
FillPath()
:k‫ودوא‬JO‫א‬lWS‫'ل‬h3'\‫ א‬53$Q\
‫رابط‬
http://msdn.microsoft.com/en-us/library/system.drawing.graphics_members.aspx
g! FillXXX 5Q'‫دوאلא‬3C، Pen 7‫مא‬$+ DrawXXX ‫دوאلא‬0B‫ن‬C€(9‫وאšن‬
.9
ً ‫و‬CYNjP‫א‬5QWSnDfC$N‫א‬W، Brush i,O‫مא‬$+
Pen
.4
NC9‘،:! I‫ق و‬H‫אز‬7 Pen.BlueK^3$Q$ˆQ5Di,3‫א‬hFDU Pen ‫אم‬$+‫ א‬5P>
:ً ^3‫א‬KPTi‫د‬$\‫ א‬:VjVI53i‫د‬O9‫وא‬:N35joQnD5QH‫د‬.N‫ز‬3
C#
Pen myPen = new Pen(Color.Black, 3);
‫ﻛﻮد‬
VB
Dim myPen As New Pen(Color.Black, 3)
‫ﻛﻮد‬
ً ^3$Q$ˆQ5D7*jVœ‫ א‬53$Q\‫אمא‬$+‫א‬NNP>. 3‫'دوض‬C‫'ن‬.zTNF.
:Q‫א‬$‫א‬17KP,
C#
myPen.StartCap = LineCap.ArrowAnchor;
‫ﻛﻮد‬
VB
myPen.StartCap = LineCap.ArrowAnchor
‫ﻛﻮد‬
:7‫*א‬jVI5D$Q\‫\!א‬
355
‫رابط‬
http://msdn.microsoft.com/en-us/library/system.drawing.pen.aspx
Brush
.5
:‫א‬KPT‫^ل‬3a]Ob‫'نא‬i,!zT‫א‬5P>،7Q1‫@ א‬ON
C#
SolidBrush myBrush = new SolidBrush (Color.Yellow);
‫ﻛﻮد‬
VB
Dim myBrush As New SolidBrush(Color.Yellow)
‫ﻛﻮد‬
:ً ^3‫א‬KPT‫'ن‬53^]i,!zT‘ًMQ‫א‬5P>
‫ﻛﻮد‬
C#
HatchBrush myBrush =new HatchBrush(HatchStyle.BackwardDiagonal, Color.Green,
Color.White);
VB
Dim myBrush As New HatchBrush(HatchStyle.BackwardDiagonal, Color.Green,
Color.White)
‫ﻛﻮد‬
:i,O‫*א‬jVI5D$Q\‫\!א‬
‫رابط‬
http://msdn.microsoft.com/en-us/library/system.drawing.brush.aspx
356
‫اﻟﺮﺳﻢ‬
.6
:ً ^3‫א‬KPT73aIHUz$‫א‬NNP> ،‫אœص‬NNj]T‫אنא‬$
C#
myGraphic.DrawLine(Pens.Blue, 20, 20, 100, 100);
‫ﻛﻮد‬
VB
myGraphic.DrawLine(Pens.Blue, 20, 20, 100, 100)
‫ﻛﻮد‬
:K13‫و‬C
C#
myGraphic.DrawRectangle(Pens.Blue, New Rectangle(20, 20, 100, 100));
‫ﻛﻮد‬
VB
myGraphic.DrawRectangle(Pens.Blue, New Rectangle(20, 20, 100, 100))
‫ﻛﻮد‬
:nNRN3H‫و‬C
C#
myGraphic.DrawBezier(Pens.Blue, 10, 20, 50, 80, 10, 80, 100, 50);
‫ﻛﻮد‬
VB
myGraphic.DrawBezier(Pens.Blue, 10, 20, 50, 80, 10, 80, 100, 50)
‫ﻛﻮد‬
:ً ^3‫א‬KPTa7N3:] l$Q$‫و‬:OQˆ.5j‫אم‬$+5P‫و‬73aIHNP3
C#
Graphics myGraphic = e.Graphics;
Pen myPen = new Pen(Color.Blue, 3);
myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
myGraphic.DrawLine(myPen, 20, 20, 100, 100);
‫ﻛﻮد‬
VB
Dim myGraphic As Graphics = e.Graphics
‫ﻛﻮد‬
357
Dim myPen As New Pen(Color.Blue, 3)
myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot
myGraphic.DrawLine(myPen, 20, 20, 100, 100)
:ً ^3^3KP,nD‫'ط‬1Ii$D53H3‫و‬C
C#
GraphicsPath myGraphicPath = new GraphicsPath();
myGraphicPath.StartFigure();
myGraphicPath.AddLine(10, 10, 30, 60);
myGraphicPath.AddLine(30, 60, 60, 10);
myGraphicPath.AddLine(60, 10, 10, 10);
myGraphicPath.CloseFigure();
myGraphic.DrawPath(myPen, myGraphicPath);
‫ﻛﻮد‬
VB
Dim myGraphicPath As New GraphicsPath()
myGraphicPath.StartFigure()
myGraphicPath.AddLine(10, 10, 30, 60)
myGraphicPath.AddLine(30, 60, 60, 10)
myGraphicPath.AddLine(60, 10, 10, 10)
myGraphicPath.CloseFigure()
myGraphic.DrawPath(myPen, myGraphicPath)
‫ﻛﻮد‬
N\‫ א‬i,O‫א‬Qe03 FillPath ‫'ن‬P
I‫א‬1‫
א‬qً'3:ƒ‫و‬C
‫رﺳﻢ اﻟﻨﺼﻮص‬
.7
‫و'ن‬z‫"א‬i,O* ‫'دא‬P‫'א‬S:D‫^ل‬3aC GDI ‫_אل‬D53IŠ.'S‫'ص‬VN‫א‬H
.200‫و‬20017N‫א‬U"C
‫ﻛﻮد‬
C#
myGraphic.DrawString("Hello GDI+", new Font("Times New Roman", 30), Brushes.Red,
200, 200);
‫ﻛﻮد‬
VB
myGraphic.DrawString("Hello GDI+", new Font("Times New Roman", 30), Brushes.Red,
200, 200)
358
iH'VًVً ^3P،‫א‬h‫
א‬q3 „‘:!s‫ وא‬StringFormat 5jP‫אمא‬$+‫א‬NP3 VQً79
:Q‫'د‬FD
‫ﻛﻮد‬
C#
Graphics myGraphic = e.Graphics;
StringFormat drawFormat = new StringFormat();
drawFormat.FormatFlags = StringFormatFlags.DirectionVertical;
myGraphic.DrawString("Hello GDI+", new Font("Times New Roman", 30),
Brushes.Red, 100, 20, drawFormat);
VB
Dim myGraphic As Graphics = e.Graphics
Dim drawFormat As New StringFormat()
drawFormat.FormatFlags = StringFormatFlags.DirectionVertical
myGraphic.DrawString("Hello GDI+", New Font("Times New Roman", 30),
Brushes.Red, 100, 20, drawFormat)
‫ﻛﻮد‬
:‫א‬WSK^3ًJ,2N‫'نא‬P
'S‫و‬a‫אאא‬WSnD‫'د‬%'3‫א\^ل‬،NQ$h3'‫وسא‬H‫د‬nD ً 71‫'ن‬P$%‫س}^ل‬H$‫א‬I‫א‬
:‫ א‬KPTD
359
:‫א\^ل‬a‫א‬H
‫رابط‬
http://www.java2s.com/Tutorial/CSharp/0480__2D/Clockanimation.htm
:N3i‫אد‬9‫א‬NP>،:!ˆQ1‫ول א‬CnDs‫و‬9‘01‫_א‬c‫א‬nTIC GDI ‫_אل‬DUً‫א‬$%
^P‫א‬¤NS
.NS53
‫رابط‬
http://msdn.microsoft.com/en-us/library/ms533798(VS.85).aspx
360
361
‫اﻟﺒﺎب‬
16
Windows Presentation
Foundation
362
363
‫ﺗﻌﺮﻳﻔﺎت أﺳﺎﺳﻴﺔ‬
WPF
.1
.1.1
53 i$Q$% 3'H N7 S WPF ‫ ًא‬HVI‫ א‬fQ 3 ‫و‬C Windows Presentation Foundation
Extensible Application fQ 3 nD $F .net framework 3.0 03 hC$ €!'‫و‬PQ3
U €!'‫و‬PQ3 hN7 53 $Q$Ž‫ א‬KŽ‫ א‬4 S‫ و‬، XAML ‫ ًא‬HVI‫ وא‬Markup Language
Windows Media Player API's‫ و‬DirectX APIs ‫ و‬GDI+ ‫ و‬Windows Forms $j\‫א‬hg%‫א'א‬
.GZ‫א‬nD'Q$O‫و‹ ‹ אدوא‬jN‹h3'‫وא‬hg%‫'א‬
FV zg‫ وא‬hg%‫ א'א‬FV 53 z‫א‬$‫ط א‬7N‫ א‬lWS 0F´ PR‫ א‬P3 b‫ א‬$7! WPF 03 3C
.k I53'Q$O‫א^ ‹אدوא‬
XAML
.1.2
$، ASP.net hRObUE$d‫ن‬F^3 3iH'VFV‫'دوא‬P‫א‬YKVO‫ ‘„א‬XAML f$g
‫‘„(م‬X.C XAML ‫نאل‬C –‫ق‬HO‫א‬03 –ROb FV:3$+W‫ א‬HTML Xg, XAML
.‡‫א‬...*jVI‫و‬hJ! nD'd4‫א‬hq
Microsoft Expression
.1.3
U،'Q‫`'אل'د‬O‫א‬U37Q1gOQQ ،h3'‫א‬hFD53D'F5DiHDFV‫نא‬،ً7
Adobe FlashK^323UAIC7Q1‫ و‬photoshop K^3H'V‫ א‬QR23UH'b‫د‬K(Y
Q'1‫ א‬J U gFg! 5P> iH'V h3'‫ א‬2NQ h3'‫ א‬U *V+3 23 Q$ ‫ אšن אن‬K§ ..
‫ ؟‬bœ‫א‬
364
5P‫و‬،:! I‫و‬¤R\‫א^€وא‬FV‫א‬UVV+323‫ א‬4، Expression iP!SlWS€
.'gO+\‫א‬71U:3‫א‬$+‫א‬5P> XAML KP, nD‫'ن‬PQ‫ن‬C5P>2N‫א‬
.‫ ش‬O:T‫אوא‬X',''O:T‫ א‬3'‫א‬gN3‫و‬GQ'*V+\‫א‬gN323‫א‬4‫א‬lWS53h‫א‬H‫א‬$b‫א‬i$D¤NS
WPF ‫אل‬nDNFDiZ!¤HD‫א‬U234‫אא‬WS 0s5P‫و‬،234‫אא‬WSv,U0'NNP
.: I53:3$+ W‫ א‬XAML ‫אج‬5P>
.Q‫א‬$‫א‬53 WPF ‫_אل‬Dz$N‫'د‬N،ً‫א‬$%Q3$73lWS€
WPF ‫أﻧﻮاع ﺗﻄﺒﻴﻘﺎت‬
.2
lWS nDf‫ولא‬RN،KP,53^CnDg(Q‫אن‬5P>K،a7!$7ˆ1‫ @د‬WPF ˆ1
.‫لאšن‬P,‫א‬
: Traditional Desktop Applications -1
.:! I‫و‬hg%‫وא'א‬g(\‫ א‬YR7Q‫ د‬WPF ‫אل‬، exe $7ˆ1،ًD',^‫'عא‬N‫א‬
: Navigation-Based -2
‫ و‬Forward Q$OV\‫*א‬jVI:Q$5P‫د و‬Dˆ1‫'ن‬P71HI‫ א‬WPF ‫ ل‬I53NP>
ˆ1 g'U$Q$%9، pages U€CS‫د‬$hRObYK7N‫مא‬$+F 5P>Backward
.OV‫¨א‬$3A'‫د‬D
: XBAP Applications -3
، JAVA Applet ‫אل‬C$}ً‫א‬$%:,،OV\‫ ل א‬I53KFQˆ1zN WPF h‫Ÿא‬53i$Q$%i3
local machine ‫אل‬U XBAP application KFR‫'م‬7Q، URL ‫'אن‬ND‫ ل‬I53:‘‫'ل‬b'‫א‬Q
.gqT‫'م‬7Q‫و‬
: Silverlight Application -4
X :T‫ א‬i$Q$, ، i,3 OV\‫ ل א‬I 53 g!M‫ א‬Q h71 zN NP> ً MQ‫ א‬WPF ‫ ل‬I 53
365
g(\‫א‬UN—hP3 Silverlight ‫אل‬0FQ،O+\‫€ א‬Z–‫א‬hRObU‫'د‬%'\‫א‬embeded flash
.z‫'א‬$nDWON‫وא‬
WPF ‫ﻣﺤﺘﻮﻳﺎت اﻟﻔﺌﺔ‬
.3
. WPF K‫א‬bN‫ א‬:System.Windows
Tool ‫وאل‬j‫'א‬7‫א‬K^371 zN3‫א ز‬bN‫א‬53D'FnD' :System.Windows.Controls
.:! I‫و‬Tips
. XAML £bWON‫و‬gObœ‫ א‬hJO‫ א‬:System.Windows.Markup
.3D 3V‫وא‬R\‫א‬H'V‫'وא‬Q$O‫א‬03 K3bœ‫א‬hJO‫ א‬:System.Windows.Media
h71‫ א‬53 Navigation-Based‫'ع‬N‫ א‬03 K3 bœ‫ א‬hJO‫ א‬:System.Windows.Navigation
.ً 7lNRs‫و‬W‫א‬
.2D3V‫א‬hFh‫אدوא‬53D'F :System.Windows.Shapes
WPF ‫ﺗﻄﺒﻴﻘﻚ اﻷول ﻓﻲ ﻋﺎﻟﻢ‬
.4
zNOi,3N\‫א‬lWS‫`وز‬NNNP‫و‬، XAML nD‫د‬FD9‫ون א‬$ WPF h71zNNNP>
. XAML ‫אم‬$+ WPF h71
„‫אو‬i\‫א‬SlWS5\‫و‬،\‫א‬oV h%‫א‬$.‫'ن‬P€]! HTML 03K3‫ًא‬7€%$.€N'
:ً ^3‫א‬KPT Tags nD$F HTML ‫€אل‬$7!kN
‫ﻛﻮد‬
<a href="Ahmed.html">Ahmed</a>
'S‫م‬$+F‫*א\وض‬N‫ אن א‬YU Ahmed.html ROV‫
‘„א‬TQ Link a‫א‬HcQˆ‫'دא‬P‫א‬
.Ahmed
:ً ^3‫א‬KPT HTML ‫'אدאل‬9 AIC7Q¤NS
366
‫ﻛﻮد‬
<img src="ahmed.jpg" alt="ahmed picture" border="0" />
. Qg Tagk@!€(9'،‫ود‬$k@‫ و‬ToolTip gQ$iH'bcQ‫'د‬P‫אא‬WS
:‫א‬q NS53z$‫א‬NP> HTML 5D$Q\‫}!א‬G— €N'
‫رابط‬
http://www.html4arab.com/
‫ﻣﻼﺣﻈﺔ‬
n+0.‫א\'א‬Q'1Uً‫א‬$%ً‫א‬$O3‫'ن‬P+:FUYD 53^‫א‬WI]5+Qh3'3‫'ن‬P
− gD f‫ א‬KMO\‫ א‬5F! 71 U 'Q‫`'אل 'د‬O‫و א‬C DreamWaverK^3 h‫אم אدوא‬$+‫ א‬03
.a7!‫ و‬Notepad 030.‫א\'א‬hz$ ً V+,
‫א‬Wg!،Nbœ‫א‬h‫ אدوא‬ob'7Q1‫@א‬ON، XAML _DUz$:‘‫‰ج‬3K'S‫א‬WS،g\‫א‬
:ً ^33CH‫ز‬
‫ﻛﻮد‬
<Button Height="80" Width="100">
ClickMe
</Button>
:Iš‫'عא‬N‫אא‬WS‫و‬
‫ﻛﻮد‬
<Button Height="80" Width="100" Content="ClickMe"/>
:‫^ل‬3‫א‬WS،AICbNDnDI‫א‬$'d3CH‫ز‬NQ$‫'ن‬PQ‫אن‬5P>
‫ﻛﻮد‬
<Button Height = "80" Width = "100">
<Button.Content>
<ScrollBar Width = "75" Height = "40"/>
</Button.Content>
</Button>
367
ContentControl!JO‫א‬537T3€ Scroll ‫(אً–نאل‬±I ‫א\^لא‬5P
‫ﻛﻮد‬
<ScrollBar Height = "80" Width = "100">
<Button Width = "75" Height = "40"/>
</ScrollBar >
‫اﻟﺒﺪء ﻣﻦ ﺧﻼل ﻓﻴﺠﻮال ﺳﺘﻮدﻳﻮ‬
.5
:‫א‬KPT WPF ApplicationHI .، New Project zT‫א‬HI.، Visual Studio !‫אšنא‬
:‫א‬zŽ‫א‬nDZ.$Q$R، XAML ‫אل‬,, ª9‹،*03‫و‬3CH‫ز‬0s'.
368
‹ Window VN‫א‬KI‫دא‬gs‫موو‬H'O‫א‬bND!P XAML ‫'د‬zT‫ א‬KF‫م‬.،KO‫ذ‬F:‫א‬$`
‫د‬FD9‫ אو א‬XAML ‫'د‬P3b‫אšنא‬،FV‫א‬U!s9‫א‬bN‫ ™א‬${ ً MQ‫א‬،Grid
. - GQ‫و‬2343€N‫‘ن‬−GQ'‫א‬h7103KOFFV‫א‬nD
„‘GS‫‹אذ‬، Title bœ‫}א‬.،‫م‬H'O‫'אنא‬ND q Window *jVIUKQ$‫ولאšنא‬RN
‫א‬KPT ="WPF Example" GP‹53‫ و‬Title HI‫'م‬7‹53‫!و‬3 PC$‫א' وא‬Qg
:ً ^3
:‫ א‬KPT XAML B9‫'دא‬P‫'نא‬P
369
‫ﻛﻮد‬
<Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300" Title="WPF Example">
<Grid>
<Button Height="23" Margin="99,0,105,91" Name="button1"
VerticalAlignment="Bottom" Click="button1_Click">Button</Button>
<TextBox Height="23" Margin="77,80,81,0" Name="textBox1"
VerticalAlignment="Top" />
</Grid>
</Window>
.7Q1‫@א‬ONh‫אدوא‬KP*jVœ‫א‬0BUPR‫א‬P3‫אن‬ª9
g!G‫א‬،FVt‫'د—
א‬P73iW!$` ،Y33‫א‬H‫ز‬nDaqM3CX%‫אšن‬
:ً ^3‫א‬3‫א‬
C#
private void button1_Click(object sender, RoutedEventArgs e)
{
textBox1.Text = "Welcome WPF";
}
‫ﻛﻮد‬
VB
Private Sub button1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
textBox1.Text = "Welcome WPF"
End Sub
‫ﻛﻮد‬
:2N‫وא‬
370
:‫א‬KPTFV‫ א‬,,@OU‫'د‬P‫א‬NP>ًMQ‫א‬
‫ﻛﻮد‬
<x:Code>
<![CDATA[
void CodeExample(object sender, RoutedEventArgs e)
{
MessageBox.Show("ahmed");
}
]]>
</x:Code>
:ً ^3‫א‬KPT 3‫א‬H Click E$L‫א‬U:ZI‫א‬W‫א‬9‫א‬nD‫א‬$‫אא‬K%03
‫ﻛﻮد‬
<Button Height="23" Margin="99,0,105,91" Name="button1"
VerticalAlignment="Bottom" Click="CodeExample">Button</Button>
... VB.net ‫ل‬N‫(م‬N‫@א‬O‫و‬
...i,3$Q$%E$zT‫ א‬Visual Studio ‫ ل‬I53NP> Click E$RzN‹C ً MQC
: - ‫ ﻧﻘﺎط ﺳﺮﻳﻌﺔ‬- ‫ﺧﺎﺗﻤﺔ اﻟﺠﺰء اﻷول‬
:NS53z$‫א‬NP>0' XAML X ‫ אœص‬Syntax ‫!אل‬35DR€N'
‫رابط‬
http://msdn.microsoft.com/en-us/library/ms788723.aspx
:ً ^3‫ א‬KPT Window ‫ل‬g!s‫א‬NP>:! I‫ و‬Form_Load ‫אل‬E‫א‬$C‫د‬FD9
‫ﻛﻮد‬
Loaded="Window_Loaded" Closed="Window_Closed"
371
.h‫אدوא‬K*jVI‫و‬E‫א‬$C0B033‫@א‬O‫و‬
‫ل‬B$Q€N'5P،g(\ PR‫א‬53$Q\‫א‬ON1€]! WPF 037Q1‫א‬lWghHF‫ 'א‬Microsoft D'F 5Fs 53 Microsoft Expression Blend03 z$‫ א‬NPF! :! I‫ و‬hg%‫א'א‬
: ً ^3 j‫א‬g%‫'א‬iH'blWS،Expression
...3‫د‬.‫وس‬H‫د‬UgDfN‫ و‬i,3 Visual Studio ‫ אل‬U:s‫و‬NP> XAML ‫'ن‬PFFV2
372
WPF ‫أدوات‬
.6
K%C53g‫א‬HI‫و‬Sg(353
q ‫و‬C،i$Q$Ž‫א‬h‫אدوא‬53D'F WPF !'،Q$7‫א‬h‫! دوא‬s‫א‬
.k3‫א‬$+‫א‬
:Q$7‫א‬h‫אدوא‬D'F:ً9‫و‬C
*jVœ‫ ™ א‬0F a7! ، Q‫ אد‬h‫ אدوא‬.‫ و‬Lable, Button M t‫ א‬i‫ א\د‬h‫دوא‬9‫ א‬D'F
. g(\‫ א‬Y‫و‬KF`!s–‫א‬
:‫م‬H'O‫א‬h‫دوא‬C:ً‹
.:! I‫و‬QF‫א‬,‫وא‬j‫'א‬7‫א‬K^3
: media ‫אل‬h‫دوא‬C:ً^‹
.:! I‫'و‬Q$O‫وא‬iH'V‫ وא‬h'V‫א‬h‫دوא‬CK^3
:g(\‫א‬h‫دوא‬C:ً‫א‬H
. StackPanel ‫ و‬Canvas K^3i$Q$%AIC‫ و‬Panel ‫ وאل‬Groupbox ‫אل‬K^39‫א‬h‫دوא‬9‫™א‬M
:O+\‫ א‬WPF h‫دوא‬C53D'Fs'iH'V‫א‬
:‫א‬KPTg‫ אœص‬XAML ‫و'دאل‬
373
‫ﻛﻮد‬
<Window x:Class="WpfApplication3.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="240" Width="343">
<Grid>
<Button Name="btnPurchaseOptions" Margin="10.5,51,10.5,41">
<StackPanel>
<StackPanel Orientation = "Horizontal"></StackPanel>
</StackPanel>
</Button>
<Expander Name="helpExpander" Header="Help" Height="23"
HorizontalAlignment="Left" Margin="70,70,0,0" VerticalAlignment="Top"
Width="51.757"></Expander>
<Expander Name="fileExpander" Header="File" Height="23"
HorizontalAlignment="Left" Margin="22,70,0,0" VerticalAlignment="Top"
Width="44.95"></Expander>
<Slider Height="21" Margin="21.757,0,19,75" Name="slider1"
VerticalAlignment="Bottom">
<Slider.BitmapEffect>
<DropShadowBitmapEffect />
</Slider.BitmapEffect>
</Slider>
<ProgressBar Height="15" Margin="23,0,19,50" Name="progressBar1"
VerticalAlignment="Bottom" Value="50" />
</Grid>
</Window>
: WPF ‫ﻧﻘﺎط ﺳﺮﻳﻌﺔ ﺣﻮل أدوات‬
.:! I‫و‬j‫وא‬$‫وא‬Q‫و‬M‫لא‬P,‫א‬$Q$R Ellipse : Q‫و‬M‫لא‬P,‫א‬:ً ^3 ‫א‬KPTgN3KPO†OI‫'نو‬$Q$‫ن‬P39b‫ א‬Combobox ‫وאل‬C List bND-
374
:ً ^3‫א‬KPT*03CU Spell Check ]1œ‫א‬RVbIKO5P>
‫ﻛﻮد‬
<TextBox SpellCheck.IsEnabled="True" Height="23" Margin="20,44,16,0"
Name="textBox1" VerticalAlignment="Top" Grid.Row="10" />
:‫א‬K^3‫ˆ'د‬Q5D‫'د‬%'\‫]א‬1+Kj‫א‬$‫!א‬35P>‫و‬
C#
string alterWords = "";
SpellingError error = textBox1.GetSpellingError(0);
if (error != null)
{
foreach (string s in error.Suggestions)
{
alterWords += s + "\n";
}
MessageBox.Show("Alternative Words:\n" + alterWords);
}
‫ﻛﻮد‬
VB
Dim alterWords As String = ""
Dim [error] As SpellingError = textBox1.GetSpellingError(0)
If [error] IsNot Nothing Then
For Each s As String In [error].Suggestions
alterWords += s + "" & Chr(10) & ""
Next
MessageBox.Show("Alternative Words:" & Chr(10) & "" + alterWords)
End If
‫ﻛﻮد‬
375
:‫א‬WSK^3ًJ,‫'ن‬P2N‫وא‬
Data-Binding ‫رﺑﻂ اﻟﺒﻴﺎﻧﺎت‬
.7
!s‫'م‬7،i,3 TextBox ~ Slider .aً ^3،i,3 7Q1bND.aH01، WPF ‫אل‬U
:g1H‫א\אد‬i‫دא‬ ‫א‬zŽ‫א‬a7!
‫ﻛﻮد‬
DataContext = "{Binding ElementName=slider1}" Content = "{Binding Path=Value}"
:‫א‬KPTK3P‫ א‬XAML ‫'د‬VQ
‫ﻛﻮد‬
<Slider Height="27" Margin="20,40,16,0" Name="slider1" VerticalAlignment="Top" />
<Label Height="28" DataContext = "{Binding ElementName=slider1}" Content =
"{Binding Path=Value}" Margin="20,72,16,0" Name="label1" VerticalAlignment="Top"
BorderThickness="0">
376
:2N‫وא‬
Wpf 2d
.8
g,hN7nDfN ،i\‫א‬lWS WPF ‫אل‬U5P‫و‬$‫א‬jN‹h3'‫_ א‬AICi3‫'د‬N
. WPF ‫ ل‬I53i\‫א‬lWS5P‫ و‬GDI+ Ug3N3t‫א‬
:‫א‬hJO‫ א‬53$‫وא‬nD‫א‬h‫א‬HI'Q‫א‬$
System.Windows.Shapes
System.Windows.Media.Drawing
System.Windows.Media.Visual
Shapes ‫اﻟﺮﺳﻢ ﺑﺎﺳﺘﺨﺪام‬
.8.1
:ً ^3K13‫^ل‬3aC$، System.Windows.Shapes JO‫ل€א‬P,9‫א‬0B07
‫ﻛﻮد‬
<Rectangle Height="100" Width="200" Stroke="Red"
StrokeThickness="2" Fill="Aqua" />
377
:‫א‬KPT‫'ن‬P2N‫א‬
:ً ^3‫א‬KPT Object Browser ˆQ5Dg‘‫'ل‬b'‫ א‬NP>gƒHNP>t‫لא‬P,‫א‬
:‫^ل‬F‫א‬KPT‫א‬،gN3KP,S$<‫ אن‬5P>t‫*א‬jVœ‫א‬nDf‫א‬NNP>‫و‬
378
:ً ^3‫א‬iH'V‫א‬Ui‫'د‬%'\‫ א‬shapes K 3‫*א‬jVœ‫א‬nDf‫א‬NP>F
Pen ‫ﺧﺼﺎﺋﺺ اﻟﻘﻠﻢ‬
.8.2
:ً ^3‫א‬iH'VHFD‫א‬U‫م‬$+\‫א‬7‫ א‬oQQ
‫ﻛﻮد‬
<Pen Thickness="10" LineJoin="Round" EndLineCap="Triangle" StartLineCap="Round"
/>
. GDI+ UlNF}€(9'ً‫א‬$%:,
Brush ‫ﺧﺼﺎﺋﺺ اﻟﻔﺮﺷﺎة‬
.8.3
:gN3 ،71Ug3‫א‬$+‫א‬5P>‫ش‬O‫א‬53‫א'ع‬i$D¤NS
.‫د‬D5Q':DrawingBrush
.iH'b53z´KPT‫א‬53z%5Q' :ImageBrush
.‫א'אن‬i$1I‫ج‬H$ :LinearGradientBrush
379
.‫א'אن‬i$j‫ج دא‬H$ :RadialGradientBrush
.a7!$‫'نوא‬i,! :SolidColorBrush
:a7!$‫ 'نوא‬Solid i,O‫ א‬SgD‫^ل‬3aC
‫ﻛﻮد‬
<Ellipse Height ="50" Width ="50">
<Ellipse.Fill>
<SolidColorBrush Color ="Aqua"/>
</Ellipse.Fill>
</Ellipse>
:j‫א‬$‫جא‬H$ RadialGradientBrush ‫אم‬$+‫^ل‬3
‫ﻛﻮد‬
<Ellipse Width ="75" HorizontalAlignment="Left" Margin="28,30,0,96">
<Ellipse.Fill>
<RadialGradientBrush GradientOrigin="0.5,0.5"
Center="0.5,0.5" RadiusX="0.5" RadiusY="0.5">
<GradientStop Color="Yellow" Offset="0" />
<GradientStop Color="Red" Offset="0.25" />
<GradientStop Color="Blue" Offset="0.75" />
<GradientStop Color="LimeGreen" Offset="1" />
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
:KP,KI‫دא‬iH'b53z%D1‫^ل‬3ً‫
א‬IC‫و‬
‫ﻛﻮد‬
<Rectangle Height ="100" Width ="300">
<Rectangle.Fill>
<ImageBrush>
<ImageBrush.ImageSource>
<BitmapImage UriSource ="pic.JPG"/>
</ImageBrush.ImageSource>
</ImageBrush>
</Rectangle.Fill>
</Rectangle>
:O+\‫شא‬O‫א‬h3‫א‬$+9€!'‫و‬PQ30.'3532
380
: KbO‫א‬53$Q\a‫אאא‬WS‫و‬
‫رابط‬
http://msdn.microsoft.com/en-us/library/aa970904.aspx
Transformations ‫ال‬
.8.4
NP>،‫م‬$+\‫א‬h I$}i‹]\‫אوא‬R\‫א‬bN‫ א‬U*jVœ‫א‬lWSً‫^
א‬¤$O
.!‫א\و‬hF‫א‬53:! I‫و‬gPD‫ و‬SQ‫و‬$‫لو‬P,‫א‬Q
: ‫م‬H'O‫א‬UNQ$i‫'د‬%'\‫א‬h‫אدوא‬53D'FnDh‫™א]‹
א‬s'Q ‫א\^لא‬
‫ﻛﻮد‬
<Button Height="23" Margin="72,72,0,0" Name="button1" VerticalAlignment="Top"
HorizontalAlignment="Left" Width="75">Button
<Button.RenderTransform>
<SkewTransform AngleX ="30" AngleY ="20"/>
</Button.RenderTransform>
</Button>
<TextBox Margin="142,11,59,0" Name="textBox1" Height="23"
381
VerticalAlignment="Top">Ahmed
<TextBox.RenderTransform>
<TransformGroup>
<SkewTransform AngleX ="20" AngleY ="20"/>
<RotateTransform Angle ="45"/>
<SkewTransform AngleX ="5" AngleY ="20"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
:2NiH'blWS‫و‬
:KP,‫א‬nDO†H'V
‹] ‫ ًא‬$%KBWPFˆ1a‫אאא‬WSnD
‫رابط‬
http://www.codeproject.com/KB/WPF/TransformationsIntro.aspx
:ˆ1‫א‬iH'blWS
382
WPF ‫ ﻓﻲ‬Animation ‫ال‬
JO‫€ א‬
Animation
‫ وאل‬QR‫ א‬hF
.9
7\‫وאل א‬$‫* وא‬jVœ‫ ! א‬07
: *jVIE ‹53k$9Q$i‫אدא‬KV ‫א‬، System.Windows.Media.Animation
:DfN3'S‫و‬،QR‫א‬g! Qt‫א‬bœ‫وא‬QgN‫وא‬Q‫א‬$‫ א‬17‫د‬$By : ،To ، From
...ً 79
:S lbNDS‫א‬، timeline ً MQ‫א‬¤NS‫و‬
ob'‫א‬
VN‫א‬
L‫א‬DUPR
AccelerationRatio, DecelerationRatio
L‫א‬zg‫א‬$o+i‫'د‬
AutoReverse
c 0 F7‫ א‬، L‫ א‬l$ C$ W‫€ א‬.'‫א‬
BeginTime This
383
,\‫א‬z$‫א‬
L‫א‬FDg.qt‫א‬iZO‫א‬
Duration
z‫ 'א‬L‫ א‬zg‫ א‬$ E$R ‫ذא‬3 $Q$
FillBehavior, RepeatBehavior
:! I‫و‬Ci‫د‬D9‫א‬
: Label Uaœ‫
`א‬q،‫^ل‬3
C#
DoubleAnimation dblAnim = new DoubleAnimation();
dblAnim.From = 10;
dblAnim.To = 30;
label1.BeginAnimation(Label.FontSizeProperty, dblAnim);
‫ﻛﻮد‬
VB
Dim dblAnim As New DoubleAnimation()
dblAnim.From = 10
dblAnim.[To] = 30
label1.BeginAnimation(Label.FontSizeProperty, dblAnim)
‫ﻛﻮد‬
:L‫א‬Q‫א‬$
:L‫א‬Qg
:ً ^3 ‫א‬KPTL‫א‬i$3$Q$5P>
384
C#
dblAnim.Duration = new Duration(TimeSpan.FromSeconds(4)) ;
‫ﻛﻮد‬
VB
dblAnim.Duration = new Duration(TimeSpan.FromSeconds(4))
‫ﻛﻮد‬
:zg9‫א‬$L‫@א‬P‫و‬
C#
dblAnim.AutoReverse = true;
‫ﻛﻮد‬
VB
dblAnim.AutoReverse = true
‫ﻛﻮد‬
:lzg‫א‬$‫אض‬i‫د‬D‫א‬$Q$NNP>‫و‬
C#
dblAnim.RepeatBehavior = RepeatBehavior.Forever;
‫ﻛﻮد‬
VB
dblAnim.RepeatBehavior = RepeatBehavior.Forever
‫ﻛﻮد‬
:‫א\^ل‬KnDa7!h‫א‬30H9:‫د‬D‫אوא‬
C#
dblAnim.RepeatBehavior = new RepeatBehavior(4);
‫ﻛﻮد‬
VB
dblAnim.RepeatBehavior = new RepeatBehavior(4)
‫ﻛﻮد‬
385
XAML ‫اﻟﺤﺮﻛﺔ ﺑﺎﺳﺘﺨﺪام‬
.10
5D‫ אو‬XAML ˆQ 5D3‫وא‬9‫ א‬53 ‫ˆ א‬1 ‫ن‬P39 :‫ א‬، ‫وس‬H$‫ א‬lWS U „‫( אو‬R‫ א‬WN3 N7O‫ א‬F
K%‫^ل 'ل‬3NQ$‫אšن‬،@P‫'دوא‬P‫א‬53g‘‫'ل‬b'‫א‬5P>*jVœ‫א‬lWS0B‫'د'ن‬P‫ˆ א‬Q
: Pro CSharp 2008X53−‫\وس‬:DaqM‫א‬U:O‫אن'ل‬H‫و‬$‫'م‬7QButton
‫ﻛﻮد‬
<Button Name="myAnimatedButton" Width="120" Height = "40"
RenderTransformOrigin="0.5,0.5" Content = "OK">
<Button.RenderTransform>
<RotateTransform Angle="0"/>
</Button.RenderTransform>
<!-- The animation is triggered when the button is clicked -->
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames
Storyboard.TargetName="myAnimatedButton"
Storyboard.TargetProperty=
"(Button.RenderTransform).(RotateTransform.Angle)"
Duration="0:0:2" FillBehavior="Stop">
<DoubleAnimationUsingKeyFrames.KeyFrames>
<LinearDoubleKeyFrame Value="360" KeyTime="0:0:1" />
<DiscreteDoubleKeyFrame Value="180" KeyTime="0:0:1.5" />
</DoubleAnimationUsingKeyFrames.KeyFrames>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
styles ‫ﺗﻌﺮﻳﻒ‬
.11
D'FS‫ و‬styles fQ3NQ$‫אن‬f€NGQ'‫ א‬53‫ًא'ع‬7€%$.€N‫‘ذא‬
‫ ذ‬$ 5P> r ، darkstyle ً ^3 nF3 € :! I‫'אن و‬9‫'ل وאض وא‬1‫د א‬$ *jVœ‫ א‬53
.a7! style ‫אאل‬Pi‫ אאدא‬Ug3‫א‬$+‫א‬
386
ً ^33‫א‬H‫ ز‬KPob'‫א‬53`L‫אא‬WSKP‫'م‬75N‫ א‬WPF ‫אل‬UًMQC:‘‫ ‰ج‬3'S‫א‬WS
:ً ^3‫א‬KPT style oQ‫'م‬7N‫א‬W، style ‫@אل‬Ok3CH‫א‬H‫אز‬i$DNQ$‫ن‬CU
‫ﻛﻮد‬
<Window.Resources>
<Style x:Key ="darkstyle">
<Setter Property ="Button.FontSize" Value ="15"/>
<Setter Property ="Button.Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="Black" Offset="0" />
<GradientStop Color="Blue" Offset="0.25" />
<GradientStop Color="Brown" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
:‫א‬KPToQ‫א‬OPQ3CH‫ز‬KP‫وאšن‬
‫ﻛﻮد‬
<Button Name="b1" Width = "100"
Style ="{StaticResource darkstyle}" Content = "Button 1" HorizontalAlignment="Right"
Margin="0,61,30,61" />
<Button Name="b2" Width = "100"
Style ="{StaticResource darkstyle}" Content = "Button 2" HorizontalAlignment="Left"
Margin="25,61,0,61" />
:‫א‬KPT‫'ن‬P2N‫א‬
387
style ‫ ﺗﻐﻴﻴﺮ ﻃﺒﻴﻌﺔ ال‬.11.1
:!:'‫و‬aœ‫`א‬3‫א‬H‫ز‬$Q$Rً ^3،‫م‬$+\‫ א‬style ‫אل‬U‫'د‬%'\‫
א‬qVV†z,‫א‬oQNP>
:‫א‬KPT:OPQKK3P style ‫
אل‬q‫م‬Q 9o†
‫ﻛﻮد‬
<Button Name="b2" Width = "100"
Style ="{StaticResource darkstyle}" Content = "Button 2" HorizontalAlignment="Left"
Margin="25,61,0,61" FontSize="30" />
:2N‫وא‬
‫ ﻣﻦ آﺧﺮ‬Style ‫اﺷﺘﻘﺎق‬
.11.2
:‫א‬KPT:OQ5P> Q$. style 53lWICQ$Q$% style KF
‫ﻛﻮد‬
<Style x:Key ="darkredstyle" BasedOn = "{StaticResource darkstyle}">
Triggers ‫ ﺑﺎﺳﺘﺨﺪام‬style ‫ﺗﺼﻤﻴﻢ‬
.11.3
388
* 03 5Q' ً ^F! ، l
—‫א\وس אو‬H‫و‬3 E$r 13 i‫ دא‬h9 $Q$ 53 Triggers ‫ אل‬NP>
:‫א‬KPT styleGP$Q$R‫א‬nD:'V$NDo† ‫'ن‬
‫ﻛﻮد‬
<Window.Resources>
<Style x:Key ="txtstyle" TargetType = "{x:Type TextBox}">
<Setter Property = "Background" Value = "White"/>
<Style.Triggers>
<Trigger Property = "IsFocused" Value = "True">
<Setter Property = "Background" Value = "Yellow"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
:$Q$R‫א‬:DW‫*א‬N‫א‬0\2N‫وא‬
: ‫ﺑﺮﻣﺠﻴ ًﺎ‬
style $Q$‹53‫ و‬styles ‫אل‬53D'FgFj7 bND!s‫א‬، Pro CSharp 2008 53‫'ل‬7N3‫^ل‬3
:ً ^3‫א‬KPT S$CnD'R39‫א‬H‫ز‬
C#
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
‫ﻛﻮد‬
389
// Add items to our list box.
lstStyles.Items.Add("TiltStyle");
lstStyles.Items.Add("GreenStyle");
lstStyles.Items.Add("MouseOverStyle");
}
protected void comboStyles_Changed(object sender, RoutedEventArgs args)
{
// Get the selected style name from the list box.
System.Windows.Style currStyle = (System.Windows.Style)
FindResource(lstStyles.SelectedValue);
// Set the style of the button type.
this.btnMouseOverStyle.Style = currStyle;
}
}
VB
Public Partial Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
' Add items to our list box.
lstStyles.Items.Add("TiltStyle")
lstStyles.Items.Add("GreenStyle")
lstStyles.Items.Add("MouseOverStyle")
End Sub
Protected Sub comboStyles_Changed(ByVal sender As Object, ByVal args As
RoutedEventArgs)
' Get the selected style name from the list box.
Dim currStyle As System.Windows.Style =
DirectCast(FindResource(lstStyles.SelectedValue), System.Windows.Style)
' Set the style of the button type.
Me.btnMouseOverStyle.Style = currStyle
End Sub
End Class
‫ﻛﻮد‬
:2N‫وא‬
390
Templates ‫ال‬
.12
1‫ א‬K3P q ‫ אن‬01 g‫ א‬styles Y‫ و‬gN ‫ق‬HO‫ א‬5P‫ و‬، h‫* אدوא‬jVI q ً MQ‫م א‬$+
: Templates‫אل‬lWSً ^3،i‫دא‬ 9‫א‬
‫ﻛﻮد‬
<Grid.Resources>
<!-- A simple template for a round button for items in this grid -->
<ControlTemplate x:Key ="roundButtonTemplate" TargetType ="{x:Type Button}">
<Grid>
<Ellipse Name ="OuterRing" Width ="75" Height ="75" Fill ="DarkGreen"/>
<Ellipse Name ="InnerRing" Width ="60" Height ="60" Fill ="MintCream"/>
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Grid.Resources>
:ً ^33CHS$Q$NP>‫وאšن‬
‫ﻛﻮد‬
<Button Name ="myButton" Foreground ="Black" FontSize ="20" FontWeight ="Bold"
Template ="{StaticResource roundButtonTemplate}"
Click ="myButton_Click"> Click!
</Button>
391
:2N‫وא‬
3D WPF
.13
‫א‬WS U ‫ول‬RN ، ‫د‬9‫ א‬jN‹ ( g%‫ و‬53 WPF _D U ‫'ص‬q z$ :‘ ‫ ‰ج‬3 K NF ‫ אن‬$
. Avalon ~nFQ3‫אو‬WPF U‫א_א^ ‹אد‬h‫ א‬nDf‫سא‬H$‫א‬
™!3‹53‫ و‬9
ً ‫و‬C—‫א‬O‫א‬$Nk‫א‬SO3™‫ج‬، 2D‫_אل‬D5Dً‫ ^
א‬3D‫_אل‬D o•
3!}z$‫א‬NP> Graphics ‫ل אل‬UNS*V+5N‫و}א‬،:! I‫ و‬Projection K^3SO\‫א‬
:Q‫א‬3$7\‫א‬lWS‫ ل‬I53$Q
‫رابط‬
http://developer.nvidia.com/docs/IO/11278/Intro-to-Graphics.pdf
... WPF 03C$N‫אšن‬
3D _DUً3‫دو‬9‫א‬KPT‫ א‬−‫م‬k‫אنא‬¤H$€]! Graphics ‫אل‬D03i4œ‫ ™א‬Q$€'
O†‫ط‬7Y‫'ط‬1œ‫ א‬53D'F9‘'S3 Graphics - ‫_אل‬DU Hello World :TQW‫ˆא‬1‫وא‬
‫אل‬hQ(gO‫ج‬NP‫و‬−:%‫ אو‬3−‫م‬k‫ א‬:%‫و‬C‫د‬$DK^eh^^\‫א‬53D'Fg‫'لא‬7‫א‬01‫אو‬،
iH'Vg(r 3D‫אل‬Uh^^\‫א‬lWSN\‫ א‬h7‫دوא‬9‫א‬$Q$Rprojection
._‫אא‬WS03K3V+\‫א‬S‫و‬System.Windows.Media.Media3DJO‫'م
אدא‬7NQ‫א‬$
C#
using System.Windows.Media.Media3D;
‫ﻛﻮد‬
392
VB
Imports System.Windows.Media.Media3D;
‫ﻛﻮد‬
‫א‬KPT،:! I‫
אو‬3P‫و'عא‬Q¯‫لא‬$Q$ 53NNP>W‫ وא‬Viewport3D oQً9‫جאو‬RN
:ً ^3
‫ﻛﻮد‬
<Viewport3D Name="mainViewport" ClipToBounds="True">
<Viewport3D.Camera>
<PerspectiveCamera
FarPlaneDistance="100"
LookDirection="-11,-10,-9"
UpDirection="0,1,0"
NearPlaneDistance="1"
Position="11,10,9"
FieldOfView="70" />
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight
Color="White"
Direction="-2,-3,-1" />
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
:3‫א‬H‫ز‬U‫و‬
C#
MeshGeometry3D triangleMesh = new MeshGeometry3D();
Point3D point0 = new Point3D(0, 0, 0);
Point3D point1 = new Point3D(5, 0, 0);
Point3D point2 = new Point3D(0, 0, 5);
triangleMesh.Positions.Add(point0);
triangleMesh.Positions.Add(point1);
triangleMesh.Positions.Add(point2);
triangleMesh.TriangleIndices.Add(0);
triangleMesh.TriangleIndices.Add(2);
triangleMesh.TriangleIndices.Add(1);
Vector3D normal = new Vector3D(0, 1, 0);
triangleMesh.Normals.Add(normal);
‫ﻛﻮد‬
393
triangleMesh.Normals.Add(normal);
triangleMesh.Normals.Add(normal);
Material material = new DiffuseMaterial(
new SolidColorBrush(Colors.DarkKhaki));
GeometryModel3D triangleModel = new GeometryModel3D(
triangleMesh, material);
ModelVisual3D model = new ModelVisual3D();
model.Content = triangleModel;
this.mainViewport.Children.Add(model);
VB
Dim triangleMesh As New MeshGeometry3D()
Dim point0 As New Point3D(0, 0, 0)
Dim point1 As New Point3D(5, 0, 0)
Dim point2 As New Point3D(0, 0, 5)
triangleMesh.Positions.Add(point0)
triangleMesh.Positions.Add(point1)
triangleMesh.Positions.Add(point2)
triangleMesh.TriangleIndices.Add(0)
triangleMesh.TriangleIndices.Add(2)
triangleMesh.TriangleIndices.Add(1)
Dim normal As New Vector3D(0, 1, 0)
triangleMesh.Normals.Add(normal)
triangleMesh.Normals.Add(normal)
triangleMesh.Normals.Add(normal)
Dim material As Material = New DiffuseMaterial(New
SolidColorBrush(Colors.DarkKhaki))
Dim triangleModel As New GeometryModel3D(triangleMesh, material)
Dim model As New ModelVisual3D()
model.Content = triangleModel
Me.mainViewport.Children.Add(model)
‫ﻛﻮد‬
:‫'ن‬P2N‫وא‬
394
:GP\‫א‬3‫א‬
C#
private Model3DGroup CreateTriangleModel(Point3D p0, Point3D p1, Point3D p2)
{
MeshGeometry3D mesh = new MeshGeometry3D();
mesh.Positions.Add(p0);
mesh.Positions.Add(p1);
mesh.Positions.Add(p2);
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(2);
Vector3D normal = CalculateNormal(p0, p1, p2);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
Material material = new DiffuseMaterial(
new SolidColorBrush(Colors.DarkKhaki));
GeometryModel3D model = new GeometryModel3D(
mesh, material);
Model3DGroup group = new Model3DGroup();
group.Children.Add(model);
return group;
}
private Vector3D CalculateNormal(Point3D p0, Point3D p1, Point3D p2)
{
Vector3D v0 = new Vector3D(
p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
Vector3D v1 = new Vector3D(
p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z);
return Vector3D.CrossProduct(v0, v1);
‫ﻛﻮد‬
395
}
‫ﻛﻮد‬
VB
Private Function CreateTriangleModel(ByVal p0 As Point3D, ByVal p1 As Point3D, ByVal
p2 As Point3D) As Model3DGroup
Dim mesh As New MeshGeometry3D()
mesh.Positions.Add(p0)
mesh.Positions.Add(p1)
mesh.Positions.Add(p2)
mesh.TriangleIndices.Add(0)
mesh.TriangleIndices.Add(1)
mesh.TriangleIndices.Add(2)
Dim normal As Vector3D = CalculateNormal(p0, p1, p2)
mesh.Normals.Add(normal)
mesh.Normals.Add(normal)
mesh.Normals.Add(normal)
Dim material As Material = New DiffuseMaterial(New
SolidColorBrush(Colors.DarkKhaki))
Dim model As New GeometryModel3D(mesh, material)
Dim group As New Model3DGroup()
group.Children.Add(model)
Return group
End Function
Private Function CalculateNormal(ByVal p0 As Point3D, ByVal p1 As Point3D, ByVal p2
As Point3D) As Vector3D
Dim v0 As New Vector3D(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z)
Dim v1 As New Vector3D(p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z)
Return Vector3D.CrossProduct(v0, v1)
End Function
:3‫א‬H‫ز‬U‫و‬
C#
Model3DGroup cube = new Model3DGroup();
Point3D p0 = new Point3D(0, 0, 0);
Point3D p1 = new Point3D(5, 0, 0);
Point3D p2 = new Point3D(5, 0, 5);
Point3D p3 = new Point3D(0, 0, 5);
Point3D p4 = new Point3D(0, 5, 0);
Point3D p5 = new Point3D(5, 5, 0);
Point3D p6 = new Point3D(5, 5, 5);
Point3D p7 = new Point3D(0, 5, 5);
//front side triangles
cube.Children.Add(CreateTriangleModel(p3, p2, p6));
‫ﻛﻮد‬
396
cube.Children.Add(CreateTriangleModel(p3, p6,
//right side triangles
cube.Children.Add(CreateTriangleModel(p2, p1,
cube.Children.Add(CreateTriangleModel(p2, p5,
//back side triangles
cube.Children.Add(CreateTriangleModel(p1, p0,
cube.Children.Add(CreateTriangleModel(p1, p4,
//left side triangles
cube.Children.Add(CreateTriangleModel(p0, p3,
cube.Children.Add(CreateTriangleModel(p0, p7,
//top side triangles
cube.Children.Add(CreateTriangleModel(p7, p6,
cube.Children.Add(CreateTriangleModel(p7, p5,
//bottom side triangles
cube.Children.Add(CreateTriangleModel(p2, p3,
cube.Children.Add(CreateTriangleModel(p2, p0,
ModelVisual3D model = new ModelVisual3D();
model.Content = cube;
this.mainViewport.Children.Add(model);
p7));
p5));
p6));
p4));
p5));
p7));
p4));
p5));
p4));
p0));
p1));
VB
Dim cube As New Model3DGroup()
Dim p0 As New Point3D(0, 0, 0)
Dim p1 As New Point3D(5, 0, 0)
Dim p2 As New Point3D(5, 0, 5)
Dim p3 As New Point3D(0, 0, 5)
Dim p4 As New Point3D(0, 5, 0)
Dim p5 As New Point3D(5, 5, 0)
Dim p6 As New Point3D(5, 5, 5)
Dim p7 As New Point3D(0, 5, 5)
'front side triangles
cube.Children.Add(CreateTriangleModel(p3,
cube.Children.Add(CreateTriangleModel(p3,
'right side triangles
cube.Children.Add(CreateTriangleModel(p2,
cube.Children.Add(CreateTriangleModel(p2,
'back side triangles
cube.Children.Add(CreateTriangleModel(p1,
cube.Children.Add(CreateTriangleModel(p1,
'left side triangles
cube.Children.Add(CreateTriangleModel(p0,
cube.Children.Add(CreateTriangleModel(p0,
'top side triangles
cube.Children.Add(CreateTriangleModel(p7,
cube.Children.Add(CreateTriangleModel(p7,
‫ﻛﻮد‬
p2, p6))
p6, p7))
p1, p5))
p5, p6))
p0, p4))
p4, p5))
p3, p7))
p7, p4))
p6, p5))
p5, p4))
397
'bottom side triangles
cube.Children.Add(CreateTriangleModel(p2, p3, p0))
cube.Children.Add(CreateTriangleModel(p2, p0, p1))
Dim model As New ModelVisual3D()
model.Content = cube
Me.mainViewport.Children.Add(model) :2N‫وא‬
:‫א‬a‫אא‬nD‫س‬H$‫אא‬WShQ'):N3€7‫א‬W‫א‬H$V\‫ א‬53h71‫א‬lWSUb‫א\'א‬NP>
‫رابط‬
http://www.kindohm.com/technical/wpf3dtutorial.htm
:‫א‬KPT2N‫'نא‬P‫
א‬3P‫ א‬UPR‫א‬53NP>23KFDOnD‫א\  ع‬NP>‫و‬
398
:‫א‬KPT‫'ن‬PhsHCH‫אو‬
XNA ‫ﻋﺎﻟﻢ‬
.14
€% $. €]! ، ‫ _ א^ ‹ אد‬. D : z, C ‫و‬C X‫ א‬03 K3‫€ א‬% $. €N ‫‘ذא‬
‫א‬W،‫א_א^ ‹אد‬03K3bœ‫א‬hP\‫ א‬53S
—‫و‬C OpenGL 03‫و‬C Direct3D 03K3‫א‬
DirectX nDN3 API's ‫אل‬53i$Q$%D'FS XNA ‫نאل‬C€.' ً boQ‫'نא‬PQ5
399
™ WON ‫م‬g\‫وאل وא‬$‫ א‬53
‫د‬$Dg{ ” DirectX ‫ אل‬hP3 03 K3‫ א‬Kg „‘ f$g
.$gŽ‫א‬53
^P‫א‬WI]QSWON‫ن‬t‫א‬hF‫א‬
‫ط‬ZT gNP‫ و‬S‫ و‬، DirectX Next Generation Architecture : F` HVI‫ א‬S XNA ‫אل‬
KFR.،'g XNA ‫وع‬T3zT‫ א‬P3‫'ن‬Pً79،KF'Q‫`'אل'د‬O‫א‬53 Express +
:‫א‬a‫אא‬53XNA
:a‫אאא‬WS53i‫د‬O9‫א‬NP>1‫€ول‬N'
‫رابط‬
http://www.csharpcorner.com/UploadFile/mgold/XNAIntro04192007233237PM/XNAIntro.aspx
:‫א‬KPT{2‫'ن‬P‫و‬
4‫ول א‬R! W 5P _ ' 3C ... ‫ق‬HO‫€ א‬H‫ אد‬01 €]! ˆ DirectX 2343 €N ‫אšن ‘ذא‬
...‫ق‬HO‫א‬X%‹ iZO DirectX ‫אم‬$+
Microsoft Expression Studio
.15
Microsoft Expression Web .15.1
400
K^3 i‫'د‬%'3 qb ] ROb KFD nD ¤$DQ‫ و‬iŸ 7Q1 ROb FV 234‫א א‬WS Q
:‫א‬KPT:j‫א‬g%‫א'א‬XHTML, CSS, XML, XSLT
ًMQ‫ א‬¤NS ، *jVœ‫ א‬nD KQ$‫ وא‬ROb FV Q$ S${ t‫ א‬h‫دوא‬9‫ א‬53 ‫אم א‬$+‫ א‬NP>
QKa7!‫א‬WS@،ً ^3 styles ‫אل‬03K3‫א‬Kg*jVI¤NS،z1I‫ א‬.‫ \א‬HTML ˆ.$3
. php ‫ ل‬I53‫و‬C Asp.net ‫ ل‬I53z‫'א‬: I534‫א‬234‫א‬
:NS53z$‫א‬NP>$QF
‫رابط‬
http://www.microsoft.com/expression/features/default.aspx?key=web
Microsoft Expression Design .15.2
‫ א‬KPT:j‫א‬g%‫א'א‬،:! I‫و‬h3'‫وא‬H'V‫א‬GKgiŸً9' 234‫אא‬WS‫م‬$7Q
:
401
:NS53:!3NP>$Q\‫א‬
‫رابط‬
http://www.microsoft.com/expression/features/default.aspx?key=design
Microsoft Expression Media .15.3
:g%‫'א‬iH'blWS،O+\‫א‬3 !C5Q'P‫و‬G‫و‬KQ$ 234‫אא‬WSQ
402
:NS53:!3NP>$Q\‫وא‬
‫رابط‬
http://www.microsoft.com/expression/features/default.aspx?key=media
Microsoft Expression Encoder .15.4
53i$Q$Ž‫א‬N7‫ א‬Silver Light iH‫دא‬9‫א‬234‫ א‬KPTQ،s‫و‬D03KDOj‫א‬vF‫א‬Q
.ً Adobe 53‫ًو‬7 Micromeida 53 Flash N7 gT\‫و'!€وא‬PQ3
:234 j‫א‬g%‫א'א‬
403
:NSKVO‫א‬53$Q}z$‫א‬NP>
‫رابط‬
http://www.microsoft.com/expression/features/default.aspx?key=encoder
Expression Blend .15.5
KVO:ND$Q\‫!א‬3‫ول‬RN،FVi‫د‬$3Kj‫'!و‬Q ،O+\‫א‬hg%‫وא‬FV
...‫س‬H$‫אא‬WSU
:qT.،7‫א‬a‫אوא‬53ً9‫و‬C:FR. Expression Blend ‫ ل‬I53aˆ1KFD‫ولאšن‬RN
:‫א‬KPT WPF Application (*.exe)‹53‫ و‬New Project HI‫‹א‬53‫و‬
404
.015Q+‫نא‬P3‫! و‬s‫ א‬framework ‫وאل‬gD KF‫א‬$Qt‫א‬q‫א‬HI‫א‬NP>
‫ وאض‬XAML ‫ض‬D 535PF Split 0s'‫א‬ZI‫‹א‬53‫ و‬Active Document View ZI‫ א‬View 53
:‫א‬KPT€.'‫@א‬OU‫אد‬
3‫אوא‬H‫א‬H‫ز‬C‫و‬C،:! I‫و‬i,O‫وא‬7‫א‬z‫'א‬FVg‘‫ ج‬t‫ א‬h‫אدوא‬K$`،,T‫א‬G%nD
405
bND IŠ nD aqM‫ א‬NP> ً MQ‫ א‬، U g3$+ t‫ א‬h‫ אدوא‬53 :! I‫'ص و‬VN‫ א‬h3‫و‬
:ً ^3‫א‬KPTh‫אدوא‬0B‫ض‬Fj7‫א‬
g(\PR‫א‬gN301،GŽ‫א‬nD*jVœ‫א‬53D'Fi‫ אدא‬$`،‫א‬UFD‫ ل‬I
::! I‫و‬
bIiH'b:!0MNW‫ א‬Canvas‫'אل‬S‫א‬WS،l‫אد‬$Q$R.‫ و‬Canvas !s.،0Qˆ1‫אšن‬
:h‫™ א]‹
א‬gDˆ1‫و‬N
406
‫ﻛﻮد‬
<Canvas>
<Canvas x:Name="MainImageCanvas" Canvas.Left="40" Canvas.Top="120">
XAML 2‫'ن‬P، −i,3iH'b0s'.‫و‬C –ً ^3iH'b:!0MN‫ و‬MediaElement !s.‫אšن‬
:‫א‬KPT
‫ﻛﻮد‬
<MediaElement x:Name="MainImage" Source="c:/example/futex.jpg" Width="300"
Height="300" >
</MediaElement>
‫'ن‬P،*jVœ‫ لא‬I53K\‫א‬FDˆ1 Canvas ‫אل‬nDh‫ˆ™ א]‹
א‬1‫'م‬7N‫وאšن‬
:‫א‬KPT XAML 2
‫ﻛﻮد‬
<Canvas.RenderTransform>
<TransformGroup>
<SkewTransform x:Name="MainSkewTransform" AngleY="-19" AngleX="0"
CenterX="0" CenterY="0"/>
<ScaleTransform x:Name="MainScaleTransform" ScaleY="1" ScaleX = "1"
CenterX="0" CenterY="0"/>
</TransformGroup>
</Canvas.RenderTransform>
</Canvas>
:‫א‬KPT‫'ن‬PW‫ ` אضوא‬F5 nDaqM.‫אšن‬
407
0MNNSN{U‫و‬C،i,O‫*א‬jVI53i,3g71NP>، ًMQCiH'VK(‫א‬Q(ˆ1‫ول‬RN
i\‫א‬lWSO†K3Q‫زوא‬035P‫ًو‬MQCiH'V‫א‬:!0M‫ و‬Canvas KF‫'م‬7N‫א‬W ،FgMnDYH'b
:‫א‬KPT XAML 2‫'ن‬P،iH'V‫א‬f‫ذאא‬r
‫ﻛﻮد‬
<Canvas x:Name="ReflectionImageCanvas" Canvas.Left="260" Canvas.Top="640">
<MediaElement x:Name="ReflImage" Source="c:/example/futex.jpg"
Width="300" Height="300" Volume="0">
</MediaElement>
<Canvas.RenderTransform>
<TransformGroup>
<SkewTransform x:Name="ReflectionSkewTransform" AngleY="19"
AngleX="-41" CenterX="0" CenterY="0" />
<ScaleTransform x:Name="ReflectionScaleTransform" ScaleY="-1"
ScaleX="1" CenterX="0" CenterY="0" />
</TransformGroup>
</Canvas.RenderTransform>
</Canvas>
:‫ א‬KPTiH'V2N‫'نא‬P‫و‬
408
XAML ‫אل‬2$`‫א‬W،ًMQC*jVœ‫א‬5Fs53،K(‫א‬iH'V!OT‫! א‬s‫א‬Sg3K3N17IŠ
:‫א‬KPT QgN‫א‬U
‫ﻛﻮد‬
<Canvas x:Name="ReflectionImageCanvas" Canvas.Left="260" Canvas.Top="640">
<MediaElement x:Name="ReflImage" Source="c:/example/futex.jpg"
Width="300" Height="300" Volume="0">
</MediaElement>
<Canvas.RenderTransform>
<TransformGroup>
<SkewTransform x:Name="ReflectionSkewTransform" AngleY="19"
AngleX="-41" CenterX="0" CenterY="0" />
<ScaleTransform x:Name="ReflectionScaleTransform" ScaleY="-1"
ScaleX="1" CenterX="0" CenterY="0" />
</TransformGroup>
</Canvas.RenderTransform>
<Canvas.OpacityMask>
<LinearGradientBrush StartPoint="0.5,0.0" EndPoint="0.5,1.0">
<GradientStop Offset="0.345" Color="#00000000"
x:Name="ReflGradientStop1" />
<GradientStop Offset="1.0" Color="#CC000000"
x:Name="ReflGradientStop2" />
</LinearGradientBrush>
409
</Canvas.OpacityMask>
</Canvas>
،b9‫א‬iH'V‫א‬nD71N3K(‫א‬iH'bKŽ‫'د‬P‫א‬53 ‫ًאو‬Q‫و‬$Q Top ‫ وאل‬Left ‫אل‬h‫אدא‬$D‫™א‬aM.
:iH'V‫א‬2 ‫'ن‬P
: XAML K3P‫'دא‬P‫א‬
‫ﻛﻮد‬
<Canvas>
<Canvas x:Name="MainImageCanvas" Canvas.Left="40" Canvas.Top="120">
<MediaElement x:Name="MainImage" Source="c:/example/FUTEX.JPG"
Width="300" Height="300" >
</MediaElement>
<Canvas.RenderTransform>
<TransformGroup>
<SkewTransform x:Name="MainSkewTransform" AngleY="-19"
AngleX="0" CenterX="0" CenterY="0"/>
<ScaleTransform x:Name="MainScaleTransform" ScaleY="1" ScaleX
= "1" CenterX="0" CenterY="0"/>
</TransformGroup>
410
</Canvas.RenderTransform>
</Canvas>
<Canvas x:Name="ReflectionImageCanvas" Canvas.Left="267"
Canvas.Top="645">
<MediaElement x:Name="ReflImage" Source="c:/example/futex.jpg"
Width="300" Height="300" Volume="0">
</MediaElement>
<Canvas.RenderTransform>
<TransformGroup>
<SkewTransform x:Name="ReflectionSkewTransform" AngleY="19"
AngleX="-41" CenterX="0" CenterY="0" />
<ScaleTransform x:Name="ReflectionScaleTransform" ScaleY="-1"
ScaleX="1" CenterX="0" CenterY="0" />
</TransformGroup>
</Canvas.RenderTransform>
<Canvas.OpacityMask>
<LinearGradientBrush StartPoint="0.5,0.0" EndPoint="0.5,1.0">
<GradientStop Offset="0.345" Color="#00000000"
x:Name="ReflGradientStop1" />
<GradientStop Offset="1.0" Color="#CC000000"
x:Name="ReflGradientStop2" />
</LinearGradientBrush>
</Canvas.OpacityMask>
</Canvas>
</Canvas>
ˆ1NQ
‹]‫@א‬O‫אن‬$`‫'و‬Q$!0s‫^ ًو‬3X% ‫א‬W،z,‫'نא‬P‫אن‬5P> MediaElement ‫@אن‬N9
...ً 3e:D
.iH'V‫@א‬ONKF‫'و‬Q‫`'אل 'د‬O‫'‘„א‬SF‫'د‬P‫א‬K7NP>ً
Microsoft _D _‫א א‬WS 5D ^P‫ ً }! א‬13 € 234F ] ¤‫ אن אذ‬G‫ א‬، QgN‫ א‬K.
.a7!{N‫ א‬XAML ‫אل‬03K3‫'א‬SFgQ 3K،YFFVFً b‫א‬:%'3'g!Expression
:NS53z$‫א‬NP>D'F¡‫א‬lWS5D$Q3K ‫رابط‬
http://expression.microsoft.com/en-us/cc136522.aspx
‫‪411‬‬
‫اﻟﺒﺎب‬
‫‬
‫‬
‫‬
‫‪17‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫ﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت ‪ADO.net‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
412
413
:‫ﻣﻘﺪﻣﺔ‬
t‫ א‬ADO >$7‫א‬+N ‫אد‬$3‫א‬S Active Data Object.net ً‫א‬HVI‫א‬f3‫ אو‬ADO.net ‫אل‬
‫אو‬h‫א‬h‫ودא‬3_ًMQ‫אدא‬$3‫ א‬S‫و‬،€!'‫و‬PQ353 6‫!`'אل‬h‫א‬H‫א‬$b‫א‬Ui‫'د‬%'3€
. DAO, RDO K^3 hN7‫ א‬53 $Q$‫ א‬h$g,‫ و‬i$Q$D H'1 K‫ }א‬h3 t‫א‬Data Providers
‫אœدم‬Y ‫אو‬234‫وא‬h‫א‬i$D.Y‫ل‬V‫א‬OVV†€t‫ א‬ADO >$7‫א‬+N‫@ א‬PDnD‫و‬
ً‫א‬1M3 V 5 r disconnected 3$x i‫ود‬3 €Rb‫ א‬ADO.net ‫ !¦ن‬Client/Server KF‫وא‬
.h‫א‬i$D7ًFj‫ل دא‬V :S%'3‫א‬WSYN7‫א‬YAICh.‫!و‬¤NS
. XML ‫ل‬K3P‫א‬D$‫א‬ .3$+\‫وאل א‬$‫وא‬i$F\‫א‬h‫'אعא‬Ci‫د‬Q‫ز‬ .D‫ א‬i‫د‬Q‫ز‬ .K3P managed code €Rb‫א‬g‫א‬ :NSh.‫و‬O‫'لא‬KbO‫א‬53$Q3 nD‫ ع‬9‫א‬NP>
‫رابط‬
http://msdn.microsoft.com/en-us/library/904fck4k(VS.71).aspx
ADO.net ‫اﻟﺒﺪء ﺑﺎﺳﺘﺨﺪام‬
.1
‫'ن‬P S$ ، System.Data ‫ ً € א‬B S${، g bœ‫ א‬hP\‫'א
אد א‬S D 3 K a7!
L‫ א‬U ، Disconnected ‫و‬C Connected 0s'‫ ل א‬I 53 KF‫ א‬U G— €N ‫ ‘ذא‬F! Q7 D
‫'م‬7‫אو‬h‫א‬G` K‫א‬3nDKV!^‫א‬L‫א‬3‫א‬h‫א‬i$D7j‫لدא‬V‫א‬nD‫'ن‬P„‫אو‬
.Iš‫א‬0s'ً79‫'د‬NF! Connected 03 A'K35ًN‫و‬H‫د‬Q‫א‬$U،DFŽ‫א‬h Q$‫™א‬
414
ADO.net Data Provider ‫ﻣﻜﻮﻧﺎت‬
.2
.h‫ א‬i$D7V‫א‬zT‫א‬53NP> :Connection−1
.h‫א‬i$D.nD SQL ‫א م‬BWON53NPe:Command−2
‫ א م‬FD 5D {N‫ א‬h‫ א‬iz‫א‬. 53 NPe : DataReader DbDataReader IdataReader −3
.a7!$‫وא‬l{‫א‬U‫و‬a7!iz‫א‬7‫'ن‬P2N‫א‬5P ،‫א\^ل‬KnD
h‫ א‬53 iH'b nD ‫'ل‬VL‫ א‬nD NPe : DataAdapter DbDataAdapter IdataAdapter −4
.:! I‫و‬fW‫و‬KQ$‫! و‬s‫א‬KFD‫و‬gNK7N‫א‬53NPe‫א مو‬B‫ولאو‬$%z‫''א‬1\‫א‬
.‫ م‬9‫א‬KB„‘h‫
א‬q3QFbI:Parameter DbParameter IdataParameter−5
‫ اﻟﻤﺪﻋﻮﻣﺔ ﻣﻦ ﻗﺒﻞ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ‬Data Providers ‫اﻟـ‬
.2.1
:System.Data.OleDb
U ‫'د‬%'3 IŠ ‫ود‬3 h‫ א‬i$D7 ‫ ' ن‬5P ، h‫ א‬$D‫'א‬. 53 ‫ א 'ع‬03 K3 g3‫א‬$+‫ א‬5P>
.]1‫' א‬S‫'ع‬N‫אא‬WS‫(אًن‬:3‫א‬$+‫א‬KMOQFj7‫א‬
:System.Data.SqlClient
‫م‬g\‫ א‬53 D'F nD ' g‫ א‬SQL Server h‫ א‬$D‫'א‬. 03 K3 g3‫א‬$+‫ً א‬3‫ دو‬KMOQ
.h‫א‬$D‫'א‬.53‫'ع‬N‫א א‬WS03K3bœ‫א‬
:System.Data.SqlServerCe
. Pocket PC ‫אل‬03K3bœ‫ א‬SQL Server CE hi$D.03K3‫א‬Ug3‫א‬$+‫ א‬KMOQ
:System.Data.Odbc
.k I53:3K3‫א‬5P> Odbc o3‫א‬
System.Data.OracleClient
.k I53K‫א‬H‫و‬Ch‫א‬$D‫'א‬.03K3‫ א‬KMOQ
415
.2.2
Third-Party ‫اﻟﺘﻌﺎﻣﻞ ﻣﻊ ﻣﺰودات ﺧﺪﻣﺔ أﺧﺮى‬
ADO.NET Data Providers
‫و‬C FoxPro ‫و‬C MYSQL h‫א‬$D‫'א‬.5D‫ذא‬35P‫و‬،j‫א‬h‫א‬$D‫'א‬7 h‫ودא‬3‫ذ‬7‫א‬i7O‫א‬U
‫^ ً؟‬3DB2
‫ً؟‬i‫ود‬$[‫א‬hP39‫]وא‬1‫א‬D‫ א‬h‫ ذא‬OleDb ‫אم‬$+9QgN‫א‬U1MNKS
‫م‬$7h, n‫و‬C ADO.netXbIg`N\Data Providers Q'1hT‫א‬G—‫€א‬3. ،ً 9
:gD‫^ل‬3a‫אאא‬WS،!s‫ א‬h3$I‫و‬h‫وŸא‬4‫א‬D0Fb‫א‬hT‫א‬53i$F3h‫ودא‬3
‫رابط‬
http://www.sqlsummit.com/dataprov.htm
System.Data ‫ﻣﻜﻮﻧﺎت اﻟﻔﺌﺔ‬
.3
z1I‫א‬KjHn‫*و‬jVI‫دوאلو‬53g3K3‫وא‬h‫ א‬$D‫'א‬.*•3KnDJO‫א‬lWS'
:gVjVInDf‫א‬U$OJO‫א‬lWShQ')SCًQNS ‫ض‬N،exceptions
: IDbConnection Interface
:‫وאلא‬$‫א‬nD'd،h‫ א‬i$D7‫ل‬V9bœ‫א‬JO‫قא‬7,‫א‬Q:N3
C#
public interface IDbConnection : IDisposable
{
string ConnectionString { get; set; }
int ConnectionTimeout { get; }
string Database { get; }
ConnectionState State { get; }
IDbTransaction BeginTransaction();
IDbTransaction BeginTransaction(IsolationLevel il);
void ChangeDatabase(string databaseName);
void Close();
IDbCommand CreateCommand();
void Open();
}
‫ﻛﻮد‬
416
VB
Public Interface IDbConnection
Inherits IDisposable
Property ConnectionString() As String
ReadOnly Property ConnectionTimeout() As Integer
ReadOnly Property Database() As String
ReadOnly Property State() As ConnectionState
Function BeginTransaction() As IDbTransaction
Function BeginTransaction(ByVal il As IsolationLevel) As IDbTransaction
Sub ChangeDatabase(ByVal databaseName As String)
Sub Close()
Function CreateCommand() As IDbCommand
Sub Open()
End Interface
‫ﻛﻮد‬
: IDbCommand Interface
:‫وאل א‬$‫א‬nD'd،‫ م‬9‫א‬KBWON03ً79K3bœ‫א‬hJO‫قא‬7,‫ א‬:N3Q
C#
public interface IDbCommand : IDisposable
{
string CommandText { get; set; }
int CommandTimeout { get; set; }
CommandType CommandType { get; set; }
IDbConnection Connection { get; set; }
IDataParameterCollection Parameters { get; }
IDbTransaction Transaction { get; set; }
UpdateRowSource UpdatedRowSource { get; set; }
void Cancel();
IDbDataParameter CreateParameter();
int ExecuteNonQuery();
IDataReader ExecuteReader();
IDataReader ExecuteReader(CommandBehavior behavior);
object ExecuteScalar();
void Prepare();
}
‫ﻛﻮد‬
VB
Public Interface IDbCommand
Inherits IDisposable
‫ﻛﻮد‬
417
Property CommandText() As String
Property CommandTimeout() As Integer
Property CommandType() As CommandType
Property Connection() As IDbConnection
ReadOnly Property Parameters() As IDataParameterCollection
Property Transaction() As IDbTransaction
Property UpdatedRowSource() As UpdateRowSource
Sub Cancel()
Function CreateParameter() As IDbDataParameter
Function ExecuteNonQuery() As Integer
Function ExecuteReader() As IDataReader
Function ExecuteReader(ByVal behavior As CommandBehavior) As IDataReader
Function ExecuteScalar() As Object
Sub Prepare()
End Interface
: IdbDataParameter
:nD'
C#
public interface IDbDataParameter : IDataParameter
{
byte Precision { get; set; }
byte Scale { get; set; }
int Size { get; set; }
}
‫ﻛﻮد‬
VB
Public Interface IDbDataParameter
Inherits IDataParameter
Property Precision() As Byte
Property Scale() As Byte
Property Size() As Integer
End Interface
‫ﻛﻮد‬
418
: IdataParameter
C#
public interface IDataParameter{
DbType DbType { get; set; }
ParameterDirection Direction { get; set; }
bool IsNullable { get; }
string ParameterName { get; set; }
string SourceColumn { get; set; }
DataRowVersion SourceVersion { get; set; }
object Value { get; set; }
}
‫ﻛﻮد‬
VB
Public Interface IDataParameter
Property DbType() As DbType
Property Direction() As ParameterDirection
ReadOnly Property IsNullable() As Boolean
Property ParameterName() As String
Property SourceColumn() As String
Property SourceVersion() As DataRowVersion
Property Value() As Object
End Interface
‫ﻛﻮد‬
: IdbDataAdapter
C#
public interface IDbDataAdapter : IDataAdapter
{
IDbCommand DeleteCommand { get; set; }
IDbCommand InsertCommand { get; set; }
IDbCommand SelectCommand { get; set; }
IDbCommand UpdateCommand { get; set; }
}
‫ﻛﻮد‬
VB
Public Interface IDbDataAdapter
Inherits IDataAdapter
Property DeleteCommand() As IDbCommand
Property InsertCommand() As IDbCommand
Property SelectCommand() As IDbCommand
Property UpdateCommand() As IDbCommand
End Interface
‫ﻛﻮد‬
419
: IdataAdapter
C#
public interface IDataAdapter
{
MissingMappingAction MissingMappingAction { get; set; }
MissingSchemaAction MissingSchemaAction { get; set; }
ITableMappingCollection TableMappings { get; }
int Fill(System.Data.DataSet dataSet);
DataTable[] FillSchema(DataSet dataSet, SchemaType schemaType);
IDataParameter[] GetFillParameters();
int Update(DataSet dataSet);
}
‫ﻛﻮد‬
‫ﻛﻮد‬
VB
Public Interface IDataAdapter
Property MissingMappingAction() As MissingMappingAction
Property MissingSchemaAction() As MissingSchemaAction
ReadOnly Property TableMappings() As ITableMappingCollection
Function Fill(ByVal dataSet As System.Data.DataSet) As Integer
Function FillSchema(ByVal dataSet As DataSet, ByVal schemaType As SchemaType)
As DataTable()
Function GetFillParameters() As IDataParameter()
Function Update(ByVal dataSet As DataSet) As Integer
End Interface
: IdataReader
C#
public interface IDataReader : IDisposable, IDataRecord
{
int Depth { get; }
bool IsClosed { get; }
int RecordsAffected { get; }
void Close();
DataTable GetSchemaTable();
bool NextResult();
bool Read();
}
‫ﻛﻮد‬
420
VB
Public Interface IDataReader
Inherits IDisposable
Inherits IDataRecord
ReadOnly Property Depth() As Integer
ReadOnly Property IsClosed() As Boolean
ReadOnly Property RecordsAffected() As Integer
Sub Close()
Function GetSchemaTable() As DataTable
Function NextResult() As Boolean
Function Read() As Boolean
End Interface
‫ﻛﻮد‬
C#
public interface IDataRecord
{
int FieldCount { get; }
object this[ string name ] { get; }
object this[ int i ] { get; }
bool GetBoolean(int i);
byte GetByte(int i);
char GetChar(int i);
DateTime GetDateTime(int i);
Decimal GetDecimal(int i);
float GetFloat(int i);
short GetInt16(int i);
int GetInt32(int i);
long GetInt64(int i);
//...
bool IsDBNull(int i);
}
: IdataRecord
‫ﻛﻮد‬
VB
Public Interface IDataRecord
ReadOnly Property FieldCount() As Integer
Default ReadOnly Property Item(ByVal name As String) As Object
Get
End Get
End Property
Default ReadOnly Property Item(ByVal i As Integer) As Object
Get
End Get
‫ﻛﻮد‬
421
End Property
Function GetBoolean(ByVal i As Integer) As Boolean
Function GetByte(ByVal i As Integer) As Byte
Function GetChar(ByVal i As Integer) As Char
Function GetDateTime(ByVal i As Integer) As DateTime
Function GetDecimal(ByVal i As Integer) As Decimal
Function GetFloat(ByVal i As Integer) As Single
Function GetInt16(ByVal i As Integer) As Short
Function GetInt32(ByVal i As Integer) As Integer
Function GetInt64(ByVal i As Integer) As Long
'...
Function IsDBNull(ByVal i As Integer) As Boolean
End Interface SQL Server ‫اﻟﺒﺪاﻳﺔ ﻣﻊ‬
.4
. ‫إﻧﺸﺎء ﻗﺎﻋﺪة اﻟﺒﻴﺎﻧﺎت‬
.4.1
. ‫ˆאšن‬1‫€א‬.‫و‬z%‫و‬، ADO.net _DU9‫א‬hJO‫א‬53Ng‫א‬
‫ !`'אل‬+ KqT . ‫ אšن‬، Employee YO&'F ً ^3 h i$D. zT‫ˆ א‬1 ‫ول אšن‬RN
.3‫א ز‬h‫وא‬H\‫א‬HI. ‹53‫و‬، Windows Forms i$Q$%'Q‫'د‬
03 i‫'د‬%'\‫א‬+N‫א‬K.9‫א‬nD‫אو‬E$‫وא‬C0‫א‬H‫א‬$b9‫א‬53 Sql Server +Q$‫'ن‬PQ ‫ن‬C$9Q‫א‬$
:‫א‬a‫אא‬nD Express 'Q‫`'אل'د‬O‫א‬
‫رابط‬
http://msdn.microsoft.com/vstudio/express/sql
.€!'‫و‬PQ353¡‫א‬D'F¡‫א‬5Fs07t‫وא‬
HI‫وא‬5>‫א‬HaqM .،GŽ‫א‬nDl$` Server Explorer HI. View Fj.53‫אšن‬
:‫א‬KPTCreate New Sql Server Database
422
:‫א‬KPT Create aqs‫‹א‬9‫א‬$Q$Ra7!. ،h‫א‬i$D.zT‫א‬P3b‫אšنא‬
‫م‬$ ‫'ن‬PQ PT\‫ א‬lWS K Gq‫ א‬U ، : KV Kb9‫ א‬U !
‫'د‬%‫م و‬$D PT3 g( $. ***
.a7! . X%‫و‬−€Z9‫ل‬V‫'دא‬%‫مو‬$DUn−PT‫א‬Kb'.a7!،PT V‫א‬
423
: ‫]א‬1œ‫א‬Hg(5P‫א
! و‬g(Q$.***
An error has occurred while establishing a connection to the server. When connecting
to SQL Server 2005, this failure may be caused by the fact that under the default
settings SQL Server does not allow remote connections. (provider: Named Pipes
Provider, error: 40 - Could not open a connection to SQL Server)
53‫ و‬Configuration Tools‹53‫ و‬Microsoft SQL Server 2005 HI.23‫א‬4‫א‬53L‫א‬lWSU
Surface Area *jVœ‫ א‬5Fs 53 $` ، SQL Server 2005 Surface Area Configuration‹
Local and *jVI ‫ אن‬53 $]‫ وא‬gRO . ، Configuration for Services and connections
.KFQ!
‫نא‬C53$]ًMQ‫א‬. ،O3remote connections
: NS‫'ل‬L‫א‬53D'F3 NP>ًMQ‫א‬
‫رابط‬
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=192622&SiteID=1
:‫א‬KPTYO&'\‫ א‬h‫ول‬$%!sC$N،KFiS%‫و‬hi$D.Q$b‫אšنא‬
424
‫אšن‬،l
—‫ و‬Stored Procedureh‫א‬z‫א‬%9‫وאلوא‬$‫א‬K^3KPT‫א א‬WghQ')‫!א‬s‫א‬P3:‫א‬ª9
:‫א‬KPT‫ول‬$% !s‫א‬HINF.
Identity KQ$ ‫'م‬7 autonumber :Ž‫ و‬set primary key HI ‫'م‬7 jH vO3 Y
:‫א‬KPT‫א‬UF1„‘i‫د‬Q‫لא‬$3'S‫ و‬Increment $Q$R‫'م‬7 ‹53‫ و‬yes „‘Specfications
425
.7Q1‫@א‬ON:!G—K7 ‫*א‬jVI‫و‬.KQ$NP>7Q1‫@א‬ON‫و‬
.i,3ˆ ‫א‬zŽ‫א‬Uh‫'אعא‬CnDfN
.ً ^3 Employee_Info ‫ول‬$Ž‫א‬ªOr.zg9‫א‬$ً‫
א‬I‫א‬
KPTh‫لא‬I‫אد‬Uz$gR!‫و‬Q$t‫אولא‬$Ž‫ אאضא‬NP>،7‫א‬h‫'א‬1œ€F.‫אن‬$
:‫א‬
426
:ً ^3‫א‬KPTh‫ل™א‬I‫€د‬F.،:! I‫ول و‬$Ž‫א‬FVi‫د‬D‫א‬NP>7Q1‫@א‬ON‫و‬
:SQL ServerUh‫'אعא‬C
Exact numerics
„‘‫א¡ل‬
9,223,372,036,854,775,807
2,147,483,647
32,767
255
1
10^38 –1
53‫א¡ل‬
‫'ع‬N‫א‬
-9,223,372,036,854,775,808
-2,147,483,648
-32,768
0
0
-10^38 +1
bigint
int
smallint
tinyint
bit
decimal
427
10^38 –1
+922,337,203,685,477.5807
+214,748.3647
1.79E + 308
3.40E + 38
-10^38 +1
-922,337,203,685,477.5808
-214,748.3648
-1.79E + 308
-3.40E + 38
Dec 31, 9999
Jan 1, 1753
Jun 6, 2079
Jan 1, 1900
numeric
money
smallmoney
float
real
datetime (3.33
milliseconds
accuracy)
smalldatetime (1
minute accuracy)
f8000nK7Q–`L‫‹€א‬f
char
f8000nK7Q–non-Unicodef
varchar
nKFnon-Unicodef‫و‬
f231
varchar(max)
f 2,147,483,647 nKFnon-Unicodef‫و‬
text
f 4,000 nKF Unicode ‹f‫و‬
nchar
f 4,000 nKFUnicode f‫و‬
nvarchar
nKFnon-Unicodef‫و‬
f 230
nvarchar(max)
.f 1,073,741,823 nKFUnicode f‫و‬
ntext
.€Q of 8,000 nKF‹jN‹h
binary
nKFi
q3jN‹h of 8,000 €Q.
varbinary
€Q 231 nKFi
q3jN‹h
varbinary(max)
.€Q 2,147,483,647 nKFi
q3jN‹h
image
(s'Q€!'‫و‬PQ353‫ول‬$Ž‫אא‬Wg!، .netUh‫'אعא‬CF‫(م‬nDh‫'د‬$.€N‫و‘ذא‬
:.netUh‫'ع‬K
CLR.netUh‫'عא‬
SQL SERVER
SqlInt64
Int64, Nullable<Int64>
Bigint
SqlBytes, SqlBinary
Byte[]
Binary
SqlBoolean
Boolean, Nullable<Boolean>
bit
CLR h‫( 'عא‬SQL
Server)
428
$%'Q9
$%'Q9
char
$%'Q9
$%'Q9
cursor
SqlDateTime
DateTime, Nullable<DateTime>
date
SqlDateTime
DateTime, Nullable<DateTime>
datetime
SqlDateTime
DateTime, Nullable<DateTime>
datetime2
$%'Q9
DateTimeOffset,
Nullable<DateTimeOffset>
DATETIMEOFFSET
SqlDecimal
Decimal, Nullable<Decimal>
decimal
SqlDouble
Double, Nullable<Double>
float
$%'Q9
$%'Q9
image
SqlInt32
Int32, Nullable<Int32>
int
SqlMoney
Decimal, Nullable<Decimal>
money
SqlChars, SqlString
String, Char[]
nchar
$%'Q9
$%'Q9
ntext
SqlDecimal
Decimal, Nullable<Decimal>
numeric
SqlChars, SqlString
String, Char[]
nvarchar
SqlChars, SqlString
Char, String, Char[], Nullable<char>
nvarchar(1), nchar(1)
SqlSingle
Single, Nullable<Single>
real
$%'Q9
Byte[]
rowversion
SqlInt16
Int16, Nullable<Int16>
smallint
SqlMoney
Decimal, Nullable<Decimal>
smallmoney
$%'Q9
Object
sql_variant
$%'Q9
$%'Q9
table
$%'Q9
$%'Q9
text
TimeSpan
TimeSpan, Nullable<TimeSpan>
time
$%'Q9
$%'Q9
timestamp
SqlByte
Byte, Nullable<Byte>
tinyint
429
SqlGuid
Guid, Nullable<Guid>
uniqueidentifier
$%'Q9
i‫د‬$[‫א‬JO‫@א‬O
User-defined
type(UDT)
SqlBytes, SqlBinary
Byte[]
varbinary
SqlBytes, SqlBinary
byte, Byte[], Nullable<byte>
varbinary(1),
binary(1)
$%'Q9
$%'Q9
varchar
SqlXml
$%'Q9
xml
SQL Statements
.4.2
5Q'P‫وא‬zT–‫א‬hF!s‫א‬:! I‫و‬KQ$‫!وא‬s9‫א‬hFDWON‫و‬h‫א‬i$D.Uh‫\Žא‬
. Structured Query Language~HVI‫א‬S‫و‬SQLSq‫א‬lWS،h‫א‬$D‫'א‬.gFgOq„‘‫‰ج‬
.S
—‫ و‬Access - MS sql Server− Oracle : h‫א‬$D‫'א‬.‫'אع‬C0B03KF‫ م‬9‫א‬N7V‫و‬
‫אول‬$Ž‫א‬zT‫وא‬KQ$‫وא‬fWL‫!وא‬s9‫א‬UًMQC‫م‬$+ gC9‘−0j,'SF−RFŽ‫א‬lWS‫'م‬7
.‫و—
ذ‬iH‫دא‬9‫وא‬gPR‫ وא‬. h‫א‬$D‫'א‬.n‫و‬
:lWS‫א– م‬qUj‫وאلא‬$‫א‬SlWS
430
:SRg,‫א– مא‬FŽ3‫א‬qV‫א‬
SQL Server
Select Colums_Name From Table_Name;
‫ﻛﻮد‬
:z‫א‬%C HC53‫א– م‬B‫'ن‬Pª .SQL KB 53S
—5DR‫א‬Bet‫א‬S‫ و‬:Select
.g(Q‫ن‬C:$QW‫'د א‬F‫وא‬CK7L‫ אא‬:Colum_Name
.R‫א‬F´bIqbًMQCS‫ و‬:From
.‫ول‬$Ž‫א א‬GPNS :Table_Name
:‫א– م‬KFŽ Syntex ( Q'RN‫ א‬$D‫'א‬7‫)א‬:F5P>3nDz$‫א‬K.i(ˆN‫و‬
.i
qV‫وא‬i
P‫ א‬f‫א‬Y‫!ق‬C$%'Q9*
.!3 53^]fZQ9:1CiTD=‫!ن‬3=!3*
.ً—4‫א‬h71Ug‘‫‰ج‬9$.NC9‘‫'؛‬7N3bO‫א– م‬KB0BgN*
:7‫א‬FŽ‫א‬nD‫^ل‬3‫א‬WS‫و‬
SQL Server
SELECT FName FROM Tb_Main;
‫ﻛﻮد‬
‫אجא–אول‬+9ً ^F!،bO‫א‬gN KVO‫'אو‬gs‫و‬NNPF!‫'د‬FD53^C‫אج‬+‫א‬$QN‫و‘ذא‬
: I‫وא–א‬
SQL Server
SELECT FName,LName FROM Tb_Main;
‫ﻛﻮد‬
: ‫א‬KPT‫'لوذ‬7L‫ א‬zƒ‫א‬K)*0MN¦!h‫א‬0B‫אج‬+9‫و‬
SQL Server
SELECT* FROM Tb_Main;
‫ﻛﻮد‬
431
H‫א‬P‫א‬fW03‫אجא–אول‬+9 ً ^F! DISTINCT ... ‫م‬$+ H‫א‬P ‫ون‬$ 5P‫و‬h‫אجא‬+9‫و‬
SQL Server
SELECT DISTINCT FNAme FROM Tb_Main;
‫ﻛﻮد‬
:3‫مא‬$+ ً ‫ز‬N‫و‬CًQ$DV%+\‫א‬h‫א‬GZًMQC
ORDER BY colum
$DV ‫و‬C
ORDER BY colum DESC
: ‫א–אول‬G $DV‫א‬GZ‫א‬03 h‫א‬0B‫אج‬+9ً ^F!
SQL Server
SELECT * FROM Tb_Main ORDER BY FName DESC;
‫ﻛﻮد‬
53‫א–אولو‬GGZً ^F!،bO‫אمא‬$+ ‫وذ‬−0j,'SF−GZYQ'3KFDNNP>‫و‬
:
I‫‹א–א‬
SQL Server
SELECT * FROM Tb_Main ORDER BY FName,Lname ;
‫ﻛﻮد‬
:‫א‬qV‫א– م א‬FDU‫ط‬Ti‫אمא\وא‬$+‫א‬qbWI]
SQL Server
Select * From Tb_Main Where Field = Value;
‫ﻛﻮد‬
. = ً ‫و >< و‬C =< ‫و‬C => ‫و‬C < ‫و‬C > ‫אم‬$+‫א‬NNP>‫و‬
. Between ‫ و‬Like FS‫ ً و‬79‫¦ذنא‬gTN‫د‬$%Y33ً‫
א‬IC‫و‬
: N 18SHFDC‫و‬5QW‫א‬z.$b‫א‬5D‫^ ً م‬F!
432
SQL Server
SELECT * FROM tb_Main WHERE age = 18;
‫ﻛﻮد‬
:N5053qbCS53zƒC‫وض‬
SQL Server
SELECT FName,LName FROM tb_Main where age < 50;
‫ﻛﻮد‬
‫ص‬+,‫ א‬5DR−‫א‬KPT‫ًوذ‬b'V€Ui‫د‬O3*VNt3 DY Value 0MN‫و‬
:( $"C)–‫א‬k5QW‫وא‬
SQL Server
SELECT * FROM tb_Main WHERE Fname = 'ahmed';
‫ﻛﻮد‬
g,qbWI]gNP،h‫א‬i$D.U¢QH^3C $%'9‫و‬،¢QH‫'א‬5DR‫א‬$ND#t3 D0MNF
: SQL Server
Select * Form Table1 Where Date > #12/03/04#;
‫ﻛﻮد‬
‫؟‬IŠzO‫א‬03‫ط‬,ˆ7‫و‬CS$C‫و‬C‫وط‬,D'Fˆ7R R‫دא‬HC'‫ذא‬3:‫وאšن‬
.4‫א‬hqUNFFOr‫و‬And1‫א‬71N\‫א‬h 3\‫مא‬$+‫ض‬q‫אא‬WSK%C53
: Y%‫و‬3‫''א‬PQ9C‫ط‬T175DSFD 4PQ5QW‫صא‬+,‫א‬5DRN،0Q‫^ل‬3„‘‫وאšن‬
SQL Server
Select Fname from tb_main where age > 17 and marry = false;
‫ﻛﻮد‬
: Like K3\‫אمא‬$+‫א‬
... Y3
gT\‫א‬hFP‫א‬5DR Like K3\‫مא‬$+
: ‫א‬qV‫ א‬Like K3F‫م‬$+‫و‬
433
SQL Server
‫ﻛﻮد‬
Select * From Table Where Field Like '%Name٪';
U3‫א‬M‫و‬.Fg‫و‬C،QgN‫وא‬C،Q‫א‬$‫א‬U g3$+$.‫و‬...3fC‫'د‬%‫و‬nD9$٪‫م‬$+
:^3‫א‬
:KPT‫אא‬Wg‫א م‬B‫م‬$+N ... hm nD„‫אو‬SzƒC'$.5QW‫صא‬+,‫ض א‬
SQL Server
SELECT * FROM Tb_Main WHERE FName like '%hm%';
‫ﻛﻮد‬
: R‫א‬FK.٪0M5‫א‬W A fr SzƒCC$5QW‫صא‬+,‫א‬5DR‫دא‬HC'3C
SQL Server
SELECT * FROM Tb_Main WHERE FName like 'A%';
‫ﻛﻮد‬
.QgN‫دونא‬Q‫א‬$‫א‬U٪0MNY3 frgƒ‫א‬gNQ5QW‫صא‬+,‫א‬5DR‫دא‬HC'‫و‬
‫ﻣﻼﺣﻈﺔ‬
% ‫ نستخدم * بدال ً من‬MS Access ‫في‬
‫ ؟‬f‫و‬L‫دא‬$D$Q$‫د‬HC'‫ذא‬35P ،f‫و‬L‫א‬53‫د‬$DCc٪‫ن‬C2NˆŸ
."‫"؟‬SO–‫א‬3 D'SAccessUS&N3،"_"‫م‬$+'L‫א‬lWSU
3‫א‬
%
_ (underscore)
[]
‫אم‬$+–‫א‬
‫ ًא‬$DV!Ob53z‫א‬$‫א‬f‫א‬53‫د‬$DC
.a7!$‫وא‬f
N‫وאل‬A‫אل‬Yfً ^3،Y3A$353a7!$‫وא‬f
Like '[A-N]ack'
[^]
Like '[^B]ack'
‫'ن‬PQ9fً ^3،‫د‬$[‫'א‬S‫'ن‬PQ9C1Q,a7!$‫وא‬f
B
434
.a7! 3g!‫دو‬$D‫'ن‬PQ‫ن‬C‫ط‬T A frSzƒC C$5QW‫صא‬+,‫א‬5DR‫ن‬C‫د‬HC'‫ذא‬3:‫‘ذن‬
SQL Server
SELECT * FROM Tb_Main WHERE FName like 'A__';
‫ﻛﻮد‬
. Between ‫اﺳﺘﺨﺪام اﻟﻤﻌﺎﻣﻞ‬
5FsR‫א‬U:3‫א‬$+‫'א‬SK3\‫אא‬Wk‫ل‬F‫ א‬g,C‫و‬،Y3‫ق‬15FsRK3\‫אא‬WS‫م‬$+
.¢QH‫א'א‬
:‫א‬qV‫ א‬between ‫אم‬$+R‫א‬WI]Q
SQL Server
SELECT colum FROM table WHERE field BETWEEN v1 AND v2;
‫ﻛﻮد‬
:60‫ و‬20 YSHFDCv‫وא‬Z5QW‫صא‬+,‫אجא‬+9ً ^F!
SQL Server
SELECT *
FROM tb_main
WHERE age between 20 and 60;
‫ﻛﻮد‬
.‫ل‬L‫א‬1 ¢QH‫وא'א‬،zƒ‫א‬037Q1‫@א‬O‫אم‬$+‫א‬5P>‫و‬
.‫اﻟﺪوال ﻓﻲ اﻻﺳﺘﻌﻼﻣﺎت‬
−i$‫و‬F.$‫و‬،d3‫و‬،‫אم‬$+9‫א‬j,S‫و‬،‫ م‬9‫ א‬KBh5Fs‫وאل‬$‫א‬53$Q$‫مא‬$+
.‫س‬H$‫אא‬WS‫ ل‬I^3‫™א‬03‫وאل‬$‫™א‬nDfN - ‫ول‬$%$9
:‫ א‬KPT‫א‬WI]t‫وאلوא‬$‫אمא‬$+93‫א‬qV‫‘„א‬Qi((NN‫و‬
SQL Server
SELECT func(colum) FROM table WHERE condition;
‫ﻛﻮد‬
: AVG ‫א‬$‫א‬
435
:ً‫א‬3CGPً ^3h‫א‬i$D.UHFD‫ א‬a'3XL‫و‬،3K7a'3‫א‬$‫א‬lWSN1
SQL Server
Select AVG(Age) from tb_main;
‫ﻛﻮد‬
K‫م‬.H‫א‬0F<h `‫א‬0BnDH‫و‬$NN،‫א‬$‫א‬lWS‫م‬$+_ 'KON‫ذא‬3K+‫وאن‬
- .ً −‫א‬WPS‫ ‘„אو‬K7N‹K`
:255DSHFDC$Q95QW‫صא‬+,‫א‬HFDCa'3XL ً ^F!...‫ط‬T‫א‬$‫אمא‬$+‫א‬NNP>ًMQC
SQL Server
SELECT AVG(Age) FROM tb_main where age < 25;
‫ﻛﻮد‬
−$Q€N‫‘ذא‬−.‫א‬W...:, 3‫و‬C Expr100 ‫€א‬K7Ug(Q‫א‬$‫א‬2‫ن‬Ch$%' €(9'
:‫א‬KPT‫ًو‬7NFF As ˆQ5D2N‫א‬K7Fi‫د‬D
SQL Server
SELECT AVG(Age) as AVGAGE FROM tb_main WHERE age < 25;
‫ﻛﻮد‬
‫ﻣﻼﺣﻈﺔ‬
..‫الحظ أن الدالة سوف تتجاھل السجالت الفارغة‬
: Sum,Max,Min ‫اﻟﺪوال‬
:h‫א‬i$D.UFD4CnD‫^ل‬3‫א‬WS‫و‬،‫ א'א‬nDqb‫א‬−4‫א‬−‫'ع‬F¡‫وאلא‬$‫א‬lWS1
SQL Server
SELECT max(Age) AS mxAGE FROM tb_main;
‫ﻛﻮد‬
‫ﻣﻼﺣﻈﺔ‬
.‫ال تنس أن بإمكاننا وضع شرط لعملية اإلستعالم‬
436
: Count ‫اﻟﺪاﻟﺔ‬
:h `‫دא‬$Dً ^3$N،h `‫دא‬$D‫א‬$‫א‬lWS$‫و‬
SQL Server
‫ﻛﻮد‬
SELECT COUNT(*)
FROM Table1;
:h‫א‬H‫א‬P‫א‬KS`‫و‬
SQL Server
SELECT COUNT(DISTINCT Title)
FROM Table1;
‫ﻛﻮد‬
: ‫اﻟﻌﻼﻗﺎت‬
KF‫א‬UG—‫و‬h. D NQ$ €'‫ذא‬3،‫ وאšن‬TSql Uig,^9‫وא‬1‫وאلא‬$‫™א‬lWS€
:‫א‬KPTFŽ‫مא‬$+f'L‫א‬lWSU .gD
‫ﻛﻮد‬
SQL Server
SELECT tb_main.Fname, tb_main.lname, Tb_R1.passport, tb_r1.bclass, tb_r1.from
FROM tb_main, tb_r1
WHERE tb_main.Number = tb_r1.Number;
:7‫ א‬7Q1‫وא‬7Q1‫א‬lWSY‫وق‬O‫א‬ª ‫אšن‬ND‫د‬
.‫ول‬$%53^C03K3N g3‫وذ‬K7L‫אא‬.‫ول‬$Ž‫אא‬P‫'م‬7:ً9‫و‬C
.‫ول‬$%53^C532‫'א‬N‫א‬$Q N FromiHD$‫ول‬$%53 ^‫א‬P‫'م‬7:ً‹
.Q'Y‫و‬$Ž‫א‬Ug3.HC:Tt‫א‬h3'\‫ضא‬QP'S‫ م‬9‫א‬B 53
I‫א‬1‫א‬:ً^‹
: DDL
:‫א‬KPT‫ول وذ‬$% zT‫ א‬qVً9‫و‬CC$N،h‫א‬$D‫'א‬.KS03K3*§DDL‫ن‬C‫ذ‬
SQL Server
CREATE TABLE tb1 ( colum type, colum type,........);
‫ﻛﻮد‬
437
− *)‫'ع‬53 Name –‫א‬،Y7nD'd Tb2 ‫ً€א‬9‫و‬$%±TNN...‫ذ‬nD‫^ل‬F‫و‬
: Number ‫'ع‬53 Age Iš‫( وא‬String
SQL Server
CREATE TABLE tb1 (name text,age number );
‫ﻛﻮد‬
Y'.Yhœ‫دא‬$D0s‫‘ذن‬...a7!hI@Fx Name F‫א‬K7`‫د‬$‰‫ن‬C‫د‬HC'‫ذא‬3‫‘ذن‬
:‫א‬KPT‫ وذ‬Text ¤9‫א‬h‫'ع‬Y 03
SQL Server
CREATE TABLE tb1 (name text(6),age number );
‫ﻛﻮد‬
03‫אא\^ل‬WSX`N‫و‬... - Null ‫!אغ‬K7Q9K7L‫א‬K< oS‫אول‬$Ž‫א‬zT‫א‬Ug,]17IŠ
:ً MQC–‫א‬
SQL Server
CREATE TABLE tb1 (name text(6) Not Null,age number );
‫ﻛﻮد‬
:‫' ًא‬lzT¦NF.W‫ولא‬$Ž‫א‬fWr ‫'م‬7Q‫'د‬P‫אא‬WS0.‫א'א‬U ... fWL‫ א‬5D‫ذא‬35P‫و‬
SQL Server
DROP Table tb1;
‫ﻛﻮد‬
‫ א‬KPT‫'دوذ‬P‫א‬IŠ„‘ CASCADE !sg^Q$53 $ !h. ً13‫ول‬$Ž‫אא‬WS‫و'ن‬
SQL Server
DROP Table tb1 CASCADE;
‫ﻛﻮد‬
h‫א‬i$D.‫ولو‬$Ž‫א‬Y ‫ق‬O‫نא‬C$7DC−zT9‫א‬FD$‫وذ‬:‘ ‫'ل‬7 !s‫ א‬UC$N‫وאšن‬
- .ًRs‫وא‬bC‫'ل‬7L‫وא‬
:‫א‬7Q13DqV‫'ل‬7L‫!א‬s‫א‬01
SQL Server
ALTER TABLE tb1 ADD colum type;
‫ﻛﻮد‬
438
:( n^C−‫'ع)ذ‬N‫ א\ دوא^א‬¢QH'S‫אول‬:5Q$Q$%Y7oMN!
SQL Server
ALTER TABLE tb1 ADD birth_Date date,Gender Text;
‫ﻛﻮد‬
Q$R CASCADE FoMًFj‫دא‬NCª9 Gender ... K75P‫'ل و‬7L‫ א‬lWS$CfWRN ‫وאšن‬
:‫א‬KPT‫وذ‬،−S‫'د‬%‫لو‬U - h. ‫א‬
SQL Server
ALTER TABLE tb1 DROP gender CASCADE;
‫ﻛﻮد‬
.AICi3DML
Tb_Main ‫م‬$+f'‫و‬، h `‫!א‬s‫ אšنא‬f'DMLU‫ م‬9‫وא‬R‫א‬z%NF‫אن‬$
:!s–‫א‬3 3‫א‬qV‫وאšن‘„א‬،:D3‫وא‬CX`N‫ول‬$`
SQL Server
INSERT INTO table VALUES (v1, v2,......);
‫ﻛﻮد‬
""*VNt3 DY‫'ص‬VN‫א‬0s‫و‬iD‫א‬303،b!gNKVO‫א^ و‬z‫א‬H‫אًو‬$‫وא‬7‫א‬HFNNCª9
. ## t3 D Y¢QH‫وא'א‬
−‫و‬ZP–‫א‬$Q4‫א‬−‫'אن‬N‫א‬−F‫א‬−ok‫א‬.H−
I‫ א–א‬- ‫א–אول‬−.‫א‬:‫א‬7‫א‬HFN
:‫א‬KPT‫وذ‬، h( 3−9/‫وج‬3−0.'\‫ א‬- q‫א‬−N‫א‬
‫ﻛﻮد‬
SQL Server
Insert into tb_main values(11,'ahmed','gamal',6666666,18,'Cairo','Hammada2091','First
Year','','',false,'');
:KQ$‫א‬
:‫א‬KPTK`hKQ$3‫א‬qV‫א‬
439
SQL Server
UPDATE table_name SET colum1 = v1 , colum2 = v2 WHERE colum = v;
‫ﻛﻮد‬
( Ahmed ‫אول‬:ƒ‫א‬W‫*א‬+T = www.vb4arab.com 0.'\‫وא‬25=F‫א‬KŽً9^3‫אšن‬X`N
: ( Gamal ) I9‫)وא‬
‫ﻛﻮد‬
SQL Server
Update tb_main set age=25 , site='www.vb4arab.com' where fname='ahmed' and
lname='Gamal';
:3DqbR‫א‬B W+0.‫א'א‬U ... fWL‫ א‬5D‫ذא‬35P‫و‬
SQL Server
DELETE FROM table WHERE colum = value;
‫ﻛﻮد‬
‫ص‬+,‫א‬0BfW‰f'‫א\^لא‬U..‫ط‬, 53^Cˆ7
‹]€fWL‫'نא‬PQ‫ن‬C5P>‫و‬
:YH‫א‬5DSHFDC$Q5QW‫א‬
SQL Server
Delete from tb_main where age>40;
‫ﻛﻮد‬
:7Q1‫א‬SlWS ... 3‫ول‬$%hQ')K3 fW 5D‫ذא‬35P‫و‬
SQL Server
DELETE * FROM table;
‫ﻛﻮد‬
Stored Procedure
.4.3
‫ض‬N ‫א‬W‫ و‬، ‫ ًא‬$% a ‫'ع‬s'\‫ א‬، h‫ א‬i$D. U † ‫ א م‬B 'S Stored Procedure ‫אل‬
:‫א– م‬BQ'
SQL Server
select [First Name] from employee_info where age>21;
‫ﻛﻮد‬
440
:‫א‬KPT Procedure ‫ل‬:Q'Q3'S‫و‬
SQL Server
Create PROCEDURE dbo.GetAge
@firstname char(10) output
AS
SELECT @firstname =[First Name]
from Employee_info
where age > 21
‫ﻛﻮد‬
.Stored Procedure‫‹אאل‬Alter‫و‬CCreate‫אول‬1‫א‬−
.Output‫و‬CInput:7Q‫و‬:D'$Q$Qreturn value‫وאل‬Ch‫א‬Z3H‫א‬nD'd^‫א‬1‫א‬−
.‫א– م‬B^‫א‬1‫א‬−
:‫ م‬9‫א‬lWS :!GP‫و‬$Q$%$‫وא‬zT‫א‬H+N‫ و‬Stored Procedure .„‘GSWN‫وאšن‬
‫א‬WSK^3ًJ,2N‫'نא‬P‫ و‬، Excute HI‫ˆא‬Q5D2N‫{א‬NP>
441
:‫^ل‬F‫א‬KPT‫א‬،X'1\‫طא‬T‫^ ًא‬3$Q$RZ3HK7 ‫ م‬9‫א‬BK%NP>
SQL Server
ALTER PROCEDURE dbo.GetAge
@condition int,
@firstname char(10) output
AS
SELECT @firstname =[First Name]
from Employee_info
where age > @condition
‫ﻛﻮد‬
‫ م‬9‫א‬BWON‫'م‬7 SQL Server‫אل‬Un‫אو‬234‫א‬53z‫'א‬Z3HQeNP>L‫א‬lWSU
.:‫א‬nD
G‫و‬، Select 53ً9$ Insert ‫و‬C Delete ‫ אو‬Update ‫ م‬9‫א‬B@OKFDP3‫ن‬C@N9ً
.'1\‫ مא‬9‫א‬B
SQL Injection
.4.4
W‫ א‬zŽ‫'א‬S‫א‬Wg!i,3‫ م‬9‫א‬KB53ً9$ Stored Procedure ‫م‬$+‫!\ذא‬3$Q €N'
.ً‫^
א‬:g‫ن‬CD
442
:H‫א\و‬F‫مو‬$+\‫ˆאא‬Q5D،‫'ل‬I$‫א‬K`F‫'م‬7KI‫دא‬C‫ض‬ZON
‫ﻛﻮد‬
SQL Server
string cmd = "select id from Users where nams like '"+textBox1.Text+"' and pass like
'"+textBox2.Text+"'";
‫ض‬ZON‫وאšن‬،`N‫'د‬5!@P‫א‬U3CIDF.‫א‬$‫א‬$f'!‫'د‬%'3–‫'نא‬:C1‫א‬
:‫*אول‬N‫א‬03U‫א‬zŽ‫א‬P‫م‬.3ًV+,‫ن‬C
—('insert into Users values(1,'NewUser','1234
‫'ل‬I$‫א‬:P3‫'ن‬P7 ‫א‬i\‫א‬U، ‫ول‬$`‫م‬$+\‫אא‬WS!s‫'م‬7:NP‫و‬،i\‫א‬lWSKI$Q5
!!!1234.‫و‬NewUser
:‫ط‬T‫ˆא‬7R‫א‬Wg!،*N‫א‬3U‫א‬FŽ‫א‬P‫م‬.'،‫ذ‬53a‫وא‬C
a' or 't'='t
‫'ع؟‬s'\‫אא‬WS:Q‫ن‬C5P>W‫א‬HM‫§€`א‬KS
:P‫'م‬7Q‫ن‬CًMQC5P>
–drop table Tablename
!!!a7!‫و‬
gNP> 9‫ و‬a7! q3 33 K3 q\‫ א‬KI‫ دא‬kI‫ אد‬Q F. C ‫ن‬C U Stored Procedure ~‫ א‬¤$O
...ً79gDfNAIC7Q1gFDNNP>‫و‬،ً‫א‬$CWON‫א‬
443
‫اﻟﻌﻼﻗﺎت‬
.4.5
:‫א‬WSK^3 ً J,2N‫'نא‬P،o&'3KgDKFQt‫א‬0QHT\‫א‬:!0Mً ^3D!‫ول‬$% KF.
7‫א‬GR.‫ و‬Add New HI.، Database Diagram $`Ž‫א‬Fj7‫א‬53،h. ‫א‬a
:ً ^3‫א‬KPT . ‫א‬Ug1H‫'د‬t‫א‬
SQL _D U $Q\‫ א‬nD f‫ א‬G €N ' Sql Server U ‫ ^
ًא‬:‘ ‫ Ÿ ‰ج‬Ng‫ א‬$. ‫'ن‬P NS
:NS53z$‫א‬NP>Server
‫رابط‬
http://msdn.microsoft.com/en-us/sqlserver/default.aspx
...4‫א‬qAICi3‫'د‬N‫وאšن‬
444
‫اﻟﻮﺿﻊ اﻟﻤﺘﺼﻞ‬
.5
ConnectionStringBuilder ‫اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬
.5.1
^‫ א‬s'Q ‫א א\^ل‬WS ، ‫ אœص‬ConnectioString ‫ אل‬zN VO 7Q 5jP‫א א‬WS !'Q
:ً 3‫א‬$+‫א‬
C#
SqlConnectionStringBuilder cnStrBuilder = new SqlConnectionStringBuilder();
cnStrBuilder.InitialCatalog = "Employee";
cnStrBuilder.DataSource = @"(local)\SQLEXPRESS";
cnStrBuilder.ConnectTimeout = 30;
cnStrBuilder.Password = "124";
cnStrBuilder.UserID = "Ahmed";
SqlConnection cn = new SqlConnection();
cn.ConnectionString = cnStrBuilder.ConnectionString;
cn.Open();
‫ﻛﻮد‬
VB
Dim cnStrBuilder As New SqlConnectionStringBuilder()
cnStrBuilder.InitialCatalog = "Employee"
cnStrBuilder.DataSource = "(local)\SQLEXPRESS"
cnStrBuilder.ConnectTimeout = 30
cnStrBuilder.Password = "124"
cnStrBuilder.UserID = "Ahmed"
Dim cn As New SqlConnection()
cn.ConnectionString = cnStrBuilder.ConnectionString
cn.Open()
‫ﻛﻮد‬
:${
h‫א‬i$D.‫א‬$Q$R- InitialCatalog
h‫א‬i$D. H3$Q$R- DataSource
‫ אو‬h‫ א‬i$D. „‘ ‫'ل‬b'‫ )و א‬K%‫ א‬53 :.‫א‬q‫ א‬5P> W‫€ א‬.'‫ א‬$Q$R - ConnectTimeout
.lzg‫א‬$NDF‫א‬f7Q‫א‬
.h$%‫‘نو‬h‫א‬i$D.H‫و‬3F- Password
.$%‫‘ن و‬h‫א‬i$D7‫م‬$+\‫אא‬- UserID
445
:NS53gs‫ אא‬NP>ًMQCAI‫א‬bN‫א‬53$Q$‫א‬¤NS
‫رابط‬
http://msdn.microsoft.com/enus/library/system.data.sqlclient.sqlconnectionstringbuilder_members.aspx
Command ‫اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻔﺌﺔ‬
.5.2
7N،h‫א‬i$D.nDhF‫א‬53‫א'ع‬WON g3$+t‫ مא‬9‫א‬BS Command ‫אل‬
:jH‫א'אع‬E ‹„‘
StoredProcedure−
TableDirect−
Text−
:ً ^3‫א‬KPT€،Texti,3V‫ א م‬F` Command ‫אل‬N3$+‫א\^لאˆא‬U
C#
string strSQL = "Select * From Employee_Info";
SqlCommand myCommand = new SqlCommand(strSQL, cn);
‫ﻛﻮد‬
VB
Dim strSQL As String = "Select * From Employee_Info"
Dim myCommand As New SqlCommand(strSQL, cn)
‫ﻛﻮد‬
:KPT‫אא‬Wg‫و‬C
C#
SqlCommand testCommand = new SqlCommand();
testCommand.Connection = cn;
testCommand.CommandText = strSQL;
‫ﻛﻮد‬
VB
Dim testCommand As New SqlCommand()
testCommand.Connection = cn
testCommand.CommandText = strSQL
‫ﻛﻮد‬
446
:WON‫ ق‬i$D‫ق‬i$D¤NS0.‫א'א‬U، ExecuteReader ‫אم‬$+i,3g1NF.WON‫ א‬zN‹C
: 2N‫ א‬aH‫ و‬DataReaderoQ Q ، h‫ א‬53 ‫د‬$D 2N‫ 'ن א‬U : ExecuteReader
.7K‫א‬3U:D N!3'S‫و‬،:z‫א‬7
2N‫ א‬Delete ‫ אو‬updateFDoQ K^3،ً b‫א‬2‫'د'א‬%‫مو‬$DU: ExecuteNonQuery
.ً 79:Df‫ א‬،:3$D53F‫א‬WON'S$'‫א‬
.‫א‬Gb*+T‫אول‬9‫א‬5Da7!5D ‫ م‬9‫א‬K^3،$‫و‬2N‫'نא‬U: ExecuteScalar
. xxxxxx 3'7‫א‬
،:z‫א‬7:2N‫א‬aH‫ و‬XmlReaderoQQ XML KP,nD:‫د‬D‫وא‬2N‫א‬WON:ExecuteXmlReade
. XmlReader 5D$Q\‫ \!א‬XML ‫وس‬H‫'ع‘„د‬%‫א‬NP>
: Parameterized Command Objects ‫ اﺳﺘﺨﺪام ال‬K( ‫ م‬9‫א‬KFŽQ$7‫א‬7Q1‫!¦نא‬، SQL Injection ‫אل‬5D:!N‹$W‫سא‬H$‫ א‬53€(9F
Stored 03 K3 5P _ ' n ً MQ‫ א‬NQ$ ‫ م‬9‫ א‬KFŽ Parameters ‫אم‬$+ C$ ‫א‬W ، i1I
.Procedure
:` ‫א\^لא‬WIC'
‫ﻛﻮد‬
C#
string strSQL = "Select [First Name]+[Last Name] as [Full Name], Age From Employee
where ID=" + ID;
SqlCommand myCommand = new SqlCommand(strSQL, cn);
‫ﻛﻮد‬
VB
Dim strSQL As String = "Select [First Name]+[Last Name] as [Full Name], Age From
Employee where ID=" + ID
Dim myCommand As New SqlCommand(strSQL, cn)
‫אم‬$+ ‫'ن‬PQ KQ$‫א א‬W ، 'g ‫(م‬N‫א א‬WS ‫אق‬ZI‫ א‬53 SQL Injection ‫ }د¨ אل‬5QH‫د‬. N‫ א‬$`
: SqlParameteroQ‫و‬
‫ﻛﻮد‬
C#
string sql = string.Format("Select [First Name]+[Last Name] as [Full Name], Age From
Employee where ID=@ID");
447
using(SqlCommand cmd = new SqlCommand(sql, this.sqlCn))
{
// Fill params collection.
SqlParameter param = new SqlParameter();
param.ParameterName = "@ID";
param.Value = 10;
param.SqlDbType = SqlDbType.Int;
cmd.Parameters.Add(param);
// NSKP,]‫ م‬9‫א‬BWON
cmd.ExecuteNonQuery();
}
‫ﻛﻮد‬
VB
Dim sql As String = String.Format("Select [First Name]+[Last Name] as [Full Name],
Age From Employee where
ID=@ID")
Using cmd As New SqlCommand(sql, Me.sqlCn)
' Fill params collection.
Dim param As New SqlParameter()
param.ParameterName = "@ID"
param.Value = 10
param.SqlDbType = SqlDbType.Int
cmd.Parameters.Add(param)
' NSKP,]‫ م‬9‫א‬BWON
cmd.ExecuteNonQuery()
End Using
.234‫א‬5FsgP5‰NF.‫א م‬B„‘ h‫א‬Z3HQFNF.€(9FNS
Bً ^3NsZ!‫ 'א‬، Stored Procedure oQS‫אم‬$+9‫א‬jT‫א‬S‫و‬NQ$t‫א^א‬L‫ א‬ :‫א‬KPTN‫س‬H‫ولد‬CUS]TCt‫ مא‬9‫א‬
SQL Server
ALTER PROCEDURE dbo.GetAge
@condition int,
@firstname char(10) output
AS
SELECT @firstname=[First Name] from Employee_info where age > @condition
‫ﻛﻮد‬
448
:ً ^3‫א‬KPT ‫ذ‬Q،234‫א‬53SzD$‫א‬$Q‫אšن‬، GetAge g(OrNF.‫و‬
C#
using (SqlCommand cmd = new SqlCommand("GetAge", cn))
{
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param = new SqlParameter();
param.ParameterName = "@condition";
param.SqlDbType = SqlDbType.Int;
param.Value = myAge;
param.Direction = ParameterDirection.Input;
cmd.Parameters.Add(param);
‫ﻛﻮد‬
param = new SqlParameter();
param.ParameterName = "@firstname";
param.SqlDbType = SqlDbType.Char;
param.Size = 10;
param.Direction = ParameterDirection.Output;
cmd.Parameters.Add(param);
cmd.ExecuteNonQuery();
MessageBox.Show(cmd.Parameters["@firstName"].Value.ToString());
}
VB
Using cmd As New SqlCommand("GetAge", cn)
cmd.CommandType = CommandType.StoredProcedure
Dim param As New SqlParameter()
param.ParameterName = "@condition"
param.SqlDbType = SqlDbType.Int
param.Value = myAge
param.Direction = ParameterDirection.Input
cmd.Parameters.Add(param)
param = New SqlParameter()
param.ParameterName = "@firstname"
param.SqlDbType = SqlDbType.[Char]
param.Size = 10
param.Direction = ParameterDirection.Output
cmd.Parameters.Add(param)
cmd.ExecuteNonQuery()
MessageBox.Show(cmd.Parameters("@firstName").Value.ToString())
End Using
‫ﻛﻮد‬
449
q3oQNF.‹53‫و‬، Text 'Ss‫א‬Z!9‫(אًنא‬NS Command ‫'عאل‬oQNF.،€(9F
.ً MQC‫
אœوج‬q3‫'لو‬I$‫א‬
DataReaders ‫اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬
.5.3
:‫א‬KPT‫אمא‬$+‫א‬5P>،ˆ‫א‬3 DataReader 53h‫א‬iz‫א‬.‫د‬HC'
‫ﻛﻮد‬
C#
string listItem = "";
while (myDataReader.Read())
{
listItem= "Full Name: " + myDataReader["Full Name"].ToString() + " Age: "
+ myDataReader["Age"].ToString();
listBox1.Items.Add(listItem);
}
VB
Dim listItem As String = ""
While myDataReader.Read()
listItem = "Full Name: " + myDataReader("Full Name").ToString() + " Age: " +
myDataReader("Age").ToString()
listBox1.Items.Add(listItem)
End While
‫ﻛﻮد‬
„‘K7NkzD$‫א‬K03€.'‫@א‬OU‫و‬،iz‫א‬7h `¤NS‫ دאم‬3 true X Read ‫א‬$‫'دא‬
...‫א‬K`‫א‬
GZ‫ א‬U :F.H $Q$R ‫ אو‬myDataReader["Age"] :z‫א‬. ‫ א\אد‬K7L‫ א‬$Q$R ‫'ن‬P iz‫א‬7‫ א‬7Q
.ً ^3myDataReader[2]
2jN‫א‬5Fsi$FD–‫دא‬$DN1t‫ وא‬FieldCount bœ‫ًא‬MQC¤NS
450
: NextResult
zƒ‫ ‹ א‬YO&'\‫ א‬zƒ‫ א‬i‫د‬D9 ً ^F! ، 2N‫ א‬i‫د‬D9 ‫ א م‬tB oQ 53 DataReader ‫ אل‬NPe
:0QHT\‫א‬
C#
string strSQL = "Select * From Employee_info;Select * from projects";
SqlCommand myCommand = new SqlCommand(strSQL, cn);
do
{
while (myDataReader.Read())
{
for (int i = 0; i < myDataReader.FieldCount; i++)
listItem= "Data: " + myDataReader[0].ToString() ;
}
}
while (myDataReader.NextResult());
‫ﻛﻮد‬
VB
Dim strSQL As String = "Select * From Employee_info;Select * from projects"
Dim myCommand As New SqlCommand(strSQL, cn)
Do
While myDataReader.Read()
For i As Integer = 0 To myDataReader.FieldCount - 1
listItem = "Data: " + myDataReader(0).ToString()
Next
End While
Loop While myDataReader.NextResult()
Data Access Layer
‫ﻛﻮد‬
.6
QK،h‫א‬71!s‫א‬234‫א‬hFD‫'و‬QHN03g(\‫ א‬03‫'د‬P‫א‬0s‫و‬Q9،Q$Ž‫א‬h71‫א‬U
%‫א‬3NP>‫'ع‬s'\‫אא‬WS5D$Q\‫\!א‬، Layers fQ3'S‫و‬VON37 UgN3KKV!
:‫א‬a‫אא‬
‫رابط‬
http://www.al-asiri.com/ShowRecord.aspx?Action=Open&id=cefa426c-d9e0-4625a66b-87fd6082ff89
451
:NSًMQ‫ˆא‬1¤NS‫و‬
‫رابط‬
http://vb4arab.com/vb/showthread.php?t=10969
:YFg3Y17ˆ7Rh‫א‬$D‫'א‬.03K3bI ‫'ن‬P data layer KFD‫ول‬RN،\‫א‬lWSU
.i353^‫א‬g3‫א‬$+‫א‬i‫د‬D‫א‬ .71‫א‬lWSnDA'KQ$‫א‬Q9KQ$‫א‬U‫و‬،'g lH$V3$Q$Q]1I‫'د‬%‫و‬U:Q$3K‫אن‬،h‫א‬i$D7‫ل‬V9‫א‬O„‘ 234‫א‬53z%‫א‬2343‫ق‬1Q5L‫א‬lWSU‫و‬
‫ دون‬N3 h‫א‬Z3H 03 S$QQ t‫ א‬hF‫ א‬K‫ و‬KQ$‫ وא‬fWL‫ل وא‬V ‫وאل‬$‫ א‬53 D'F S
.ً 3eh‫א‬$D‫'א‬7‫ل‬V9‫א‬OU KI$‫א‬
KF‫'م‬7‫ و‬F‫א‬lWg‫'م‬7t‫א‬iSŽ‫א‬23‫א‬4‫אم™א‬$+‫א‬g1‫א‬،‫ق‬i$71‫א‬lWS KFDNP>
، F‫ א‬lWk 7Q € h‫و‬$‫'! א‬Q ً MQ‫ א‬، S‫د‬$ t‫ א‬4‫ א‬q G layer ‫ אل‬lWk ‫אج‬+‫א‬
...Q‫و‬$‫א‬7Q1‫א‬S^‫א‬7Q1‫א‬
nDSO\‫@א‬Oˆ15P>،YO&'\‫א‬K%‫א‬53F‫ א‬lWka‫^ل‬3nDfN‫א`א‬U
.79Q$Ž‫א‬23‫א‬4‫א‬
:‫ ﻋﻤﻠﻴﺎت ﻓﺘﺢ واﻏﻼق ﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت‬-1
C#
private SqlConnection cn = new SqlConnection();
public void OpenConnection(string connectionString)
{
cn.ConnectionString = connectionString;
cn.Open();
}
public void CloseConnection()
{
cn.Close();
}
‫ﻛﻮد‬
452
VB
Private cn As New SqlConnection()
Public Sub OpenConnection(ByVal connectionString As String)
cn.ConnectionString = connectionString
cn.Open()
End Sub
Public Sub CloseConnection()
cn.Close()
End Sub
‫ﻛﻮد‬
.‫ ﺳﻴﻨﺎرﻳﻮ ﻋﻤﻠﻴﺔ اﻟﺤﺬف‬-2
ً ^3 o&'\‫ א‬fW ‫ אو‬، :F. o&'\‫ א‬fW ‫ אو‬، :ƒ o&'\‫ א‬fW ‫م‬$+F N F‫ א‬lWS U
KFDC$3‫ و‬OverLoading ‫אل‬C$3‫אم‬$+‫א‬03ً ^3‫و‬Q ‫אو‬K.‫אوא‬4‫א‬z‫'א‬h‫א‬HI‫א‬i$‫و‬F‫א‬9$
.7‫وس‬H‫د‬UFg, ”‫אن‬W‫ًوא‬MQ‫א‬Enums
‫ € א‬234‫ א‬U g3‫א‬$+‫ א‬5P> t‫وאل א‬$‫ א‬K KFD S \‫ א‬lWS U Fg3 ‫ אن‬ª9 ***
:f‫א(و‬53f&
C#
public void DeleteEmployee(int id)
{
string sql = string.Format("Delete from Employee where ID = {0}",
id);
using(SqlCommand cmd = new SqlCommand(sql, this.sqlCn))
{
try
{
cmd.ExecuteNonQuery();
}
catch(SqlException ex)
{
Exception error = new Exception("some error occures: ", ex);
throw error;
}
}
}
‫ﻛﻮد‬
453
public void DeleteEmployee(string name)
{
string sql = string.Format("Delete from Employee where [First Name] = '{0}'",
name);
using(SqlCommand cmd = new SqlCommand(sql, this.sqlCn))
{
try
{
cmd.ExecuteNonQuery();
}
catch(SqlException ex)
{
Exception error = new Exception("some error occures: ", ex);
throw error;
}
}
}
enum deletecondition
{
morethan=0,
lessthan=1,
equal=2
}
public void DeleteEmployee(int age,deletecondition delcondition)
{
string sql="";
if(delcondition == deletecondition.morethan)
sql = string.Format("Delete from Employee where age > {0}",age);
else if(delcondition == deletecondition.lessthan)
sql = string.Format("Delete from Employee where age < {0}",age);
else
sql = string.Format("Delete from Employee where age = {0}",age);
using(SqlCommand cmd = new SqlCommand(sql, this.sqlCn))
{
try
{
cmd.ExecuteNonQuery();
}
catch(SqlException ex)
{
Exception error = new Exception("some error occures: ", ex);
throw error;
}
454
}
}
‫ﻛﻮد‬
VB
Public Sub DeleteEmployee(ByVal id As Integer)
Dim sql As String = String.Format("Delete from Employee where ID = '{0}'", id)
Using cmd As New SqlCommand(sql, Me.sqlCn)
Try
cmd.ExecuteNonQuery()
Catch ex As SqlException
Dim [error] As New Exception("some error occures: ", ex)
Throw [error]
End Try
End Using
End Sub
Public Sub DeleteEmployee(ByVal name As String)
Dim sql As String = String.Format("Delete from Employee where [First Name] =
'{0}'", name)
Using cmd As New SqlCommand(sql, Me.sqlCn)
Try
cmd.ExecuteNonQuery()
Catch ex As SqlException
Dim [error] As New Exception("some error occures: ", ex)
Throw [error]
End Try
End Using
End Sub
enum deletecondition
{
morethan=0,
lessthan=1,
equal=2
}
Public Sub DeleteEmployee(ByVal age As Integer, ByVal delcondition As
deletecondition)
Dim sql As String = ""
If delcondition = deletecondition.morethan Then
sql = String.Format("Delete from Employee where age > {0}", age)
ElseIf delcondition = deletecondition.lessthan Then
sql = String.Format("Delete from Employee where age < {0}", age)
Else
sql = String.Format("Delete from Employee where age = {0}", age)
End If
455
Using cmd As New SqlCommand(sql, Me.sqlCn)
Try
cmd.ExecuteNonQuery()
Catch ex As SqlException
Dim [error] As New Exception("some error occures: ", ex)
Throw [error]
End Try
End Using
End Sub
:‫ ﺳﻴﻨﺎرﻳﻮ ﻋﻤﻠﻴﺎت اﻻﺿﺎﻓﺔ واﻟﺘﻌﺪﻳﻞ‬-3
.‫ق‬i$!s9‫אوא‬h‫א‬HIi$KQ$‫ א‬5P>7Q1‫@א‬ON
.a7!
I‫אولوא‬9‫لא‬I‫ אد‬nDl4`N!s9‫א‬FN
.a7!‫אول‬9‫א‬.‫א‬9$‫ل‬$N ًN35P‫ و‬،iH'V‫@א‬ON‫'ن‬PQ‫ن‬CًMQCqNQKQ$‫وא‬
C#
public void InsertEmployee(string fname, string lname, int age)
{
// Format and execute SQL statement.
string sql = string.Format("Insert Into Employee_info" +
"([First Name], [Last Name]) Values" +
"('{0}', '{1}')",fname, lname);
using(SqlCommand cmd = new SqlCommand(sql, this.sqlCn))
{
cmd.ExecuteNonQuery();
}
}
‫ﻛﻮد‬
public void UpdateEmployee(int id, string newFirstName)
{
string sql =
string.Format("Update Employee Set [First Name] = '{0}' Where ID = '{1}'",
newFirstName, id);
using(SqlCommand cmd = new SqlCommand(sql, this.sqlCn))
{
cmd.ExecuteNonQuery();
}
}
456
‫ﻛﻮد‬
VB
Public Sub InsertEmployee(ByVal fname As String, ByVal lname As String, ByVal age As
Integer)
' Format and execute SQL statement.
Dim sql As String = String.Format("Insert Into Employee_info" + "([First Name],
[Last Name]) Values" + "('{0}', '{1}')", fname, lname)
Using cmd As New SqlCommand(sql, Me.sqlCn)
cmd.ExecuteNonQuery()
End Using
End Sub
Public Sub UpdateEmployee(ByVal id As Integer, ByVal newFirstName As String)
Dim sql As String = String.Format("Update Employee Set [First Name] = '{0}'
Where ID = '{1}'", newFirstName, id)
Using cmd As New SqlCommand(sql, Me.sqlCn)
cmd.ExecuteNonQuery()
End Using
End Sub .‫ ﺳﻴﻨﺎرﻳﻮ ﻋﻤﻠﻴﺎت اﻟﺒﺤﺚ‬-4
‫ אل‬FD S‫م و‬S z, gV7NQ 7‫وאل א‬$‫
‘„ ‘ن א‬T ‫ن‬C ‫ 'د‬، R‫ א‬FD 'QHN U z$‫ א‬K.
U،a7!s'7‫^א‬39‫€א‬5P، Sql Injection ‫אل‬5D{N‫א‬KT\‫ א‬U Parameters
.PT\‫א‬lWSKLlNF3ˆ1N‫אšن‬R‫א‬FD
Data UG13CnN9،Y3 ID .‫ص‬+, I‫אولوא‬9‫ א‬5Di$‫وא‬rFDX`N
‫ א م‬B n P ‫ج‬d 9 P 234‫ א‬hFD 2343 g%d $. t‫ א‬h1‫ א‬K KFLayer
.i$‫وא‬
: Stored Procedure KFً9‫'مאو‬7N
SQL Server
‫ﻛﻮد‬
457
CREATE PROCEDURE GetFirstNameByID
@id int,
@fName char(10) output
AS
SELECT @fName=[First Name] from Employee_info where ID > @id
:‫א‬KPTR‫א‬Fbœ‫אא‬$‫א‬oQ‫'م‬7‹53‫و‬
C#
public string SelectName(int id)
{
using (SqlCommand cmd = new SqlCommand("GetFirstNameByID", cn))
{
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param = new SqlParameter();
param.ParameterName = "@id";
param.SqlDbType = SqlDbType.Int;
param.Value = id;
param.Direction = ParameterDirection.Input;
cmd.Parameters.Add(param);
param = new SqlParameter();
param.ParameterName = "@fName";
param.SqlDbType = SqlDbType.Char;
param.Size = 10;
param.Direction = ParameterDirection.Output;
cmd.Parameters.Add(param);
cmd.ExecuteNonQuery();
return cmd.Parameters["@fName"].Value.ToString();
}
return carPetName;
}
‫ﻛﻮد‬
VB
Public Function SelectName(ByVal id As Integer) As String
Using cmd As New SqlCommand("GetFirstNameByID", cn)
cmd.CommandType = CommandType.StoredProcedure
Dim param As New SqlParameter()
param.ParameterName = "@id"
param.SqlDbType = SqlDbType.Int
param.Value = id
param.Direction = ParameterDirection.Input
cmd.Parameters.Add(param)
‫ﻛﻮد‬
458
param = New SqlParameter()
param.ParameterName = "@fName"
param.SqlDbType = SqlDbType.Char
param.Size = 10
param.Direction = ParameterDirection.Output
cmd.Parameters.Add(param)
cmd.ExecuteNonQuery()
Return cmd.Parameters("@fName").Value.ToString()
End Using
End Function
‫אم‬$+9‫א‬U،ˆ153^‫א‬03gqT‫ن‬FMVON3 dll Un DataLayer ‫אل‬KV!NP>ً79 -ˆ1‫ و‬، myDataLayer 9‫ א‬KF DataLayer h‫ א‬71 Class JO‫אض אن א‬Z!‫ א‬nD‫ ً و‬79
:š‫א‬K^35Q1'SN3X'1\‫א‬KfWL‫א‬K^3FD
C#
myDataLayer example=new myDataLayer();
example.OpenConnection(myconnectionstring);
example.DeleteEmployee(10);
example.DeleteEmployee("Ahmed");
‫ﻛﻮد‬
VB
Dim example As New myDataLayer()
example.OpenConnection(myconnectionstring)
example.DeleteEmployee(10)
example.DeleteEmployee("Ahmed")
‫ﻛﻮد‬
!!!a7!‫و‬
.7Q1‫@א‬ONg3‫א‬$+.‹ US‫
אد‬. dll €'‫(م‬N‫@א‬ON‫و‬
، h‫א‬$D‫'א‬.5D$‫א‬Kً‫א‬$:FD.‫و‬234‫'א‬QHN234\‫א‬b‫ א‬7Q1‫א‬lWg،€(9'
.s‫و‬CiH'VKT\‫א‬¤H‫א‬$‫ن‬P39b‫وא‬s‫و‬CbCKF‫א‬7‫אن‬F
459
Asynchronous Data Access
.7
0N\ €.'‫@ א‬O U h‫ א‬$D‫'א‬. nD hFD i$D KFD 53 NNe 7Q ‫ول‬RN jŽ‫ א‬lWS U
NH‫'عد‬s'3'SW‫ وא‬Disconnected KVON\‫א‬0s'‫א‬U4‫א‬iH'VNg%‫ 'א‬PT\‫אنא‬03‫و‬،XHM‫א‬
:‫א\^لא‬X%،Q‫א`א‬lWSUKL‫א‬X`NN‫א‬9‘ ،‫دم‬7‫א‬
C#
SqlConnection cn = new SqlConnection();
cn.ConnectionString =
@"Data Source=(local)\SQLEXPRESS;Integrated Security=SSPI;" +
"Initial Catalog=AutoLot;Asynchronous Processing=true";
cn.Open();
‫ﻛﻮد‬
‫ﻛﻮد‬
VB
Dim cn As New SqlConnection()
cn.ConnectionString = "Data Source=(local)\SQLEXPRESS;Integrated Security=SSPI;"
+ "Initial Catalog=AutoLot;Asynchronous Processing=true"
cn.Open()
ConnectioString ‫ אل‬U Asynchronous Processing=true 0s'‫ א‬oQ S g NF. i'1I ‫ول‬C
:‫وאلא‬$‫א‬53i‫د‬O9‫א‬nD5QH‫د‬. NRb‫א‬7Q1‫א‬lWg
EndExecuteReader()‫و‬BeginExecuteReader()
EndExecuteNonQuery()‫و‬BeginExecuteNonQuery()
EndExecuteXmlReader()‫و‬BeginExecuteXmlReader()
„‫ مאو‬9‫א‬B
I]C$N‫و‬، EndExecuteReader ‫ و‬BeginExecuteReader nD‫אšن‬X`N
:ً ^3‫@ ‹'אن‬Fœ
C#
string strSQL = "WaitFor Delay '00:00:05';Select * From Employee_info";
SqlCommand myCommand = new SqlCommand(strSQL, cn);
‫ﻛﻮد‬
VB
Dim strSQL As String = "WaitFor Delay '00:00:05';Select * From Employee_info"
‫ﻛﻮد‬
460
Dim myCommand As New SqlCommand(strSQL, cn)
:IŠ$Q‹nDAIChFDWON‫'م‬7NNS
‫ﻛﻮد‬
C#
IAsyncResult itfAsynch;
itfAsynch = myCommand.BeginExecuteReader(CommandBehavior.CloseConnection);
‫ﻛﻮد‬
VB
Dim itfAsynch As IAsyncResult
itfAsynch = myCommand.BeginExecuteReader(CommandBehavior.CloseConnection)
$Q^‫א‬WON53zg9‫א‬nhF‫™א‬WON‫و‬
C#
while (!itfAsynch.IsCompleted)
{
// ً ^3,p3F.
q .
‫ﻛﻮد‬
Thread.Sleep(1000);
}
VB
While Not itfAsynch.IsCompleted
' ً ^3,p3F.
q .
‫ﻛﻮد‬
Thread.Sleep(1000)
End While
.S$Qt‫א‬F‫א‬WON‫'م‬7N‫אšن‬،‫אول‬WON‫א‬zg‫א‬cQ‫א‬Wg!7‫ א‬Loop ‫אل‬53N%INC}‫אšن‬
C#
SqlDataReader myDataReader = myCommand.EndExecuteReader(itfAsynch);
while (myDataReader.Read())
{
MessageBox.Show(myDataReader[0].ToString());
}
myDataReader.Close();
‫ﻛﻮد‬
VB
‫ﻛﻮد‬
461
Dim myDataReader As SqlDataReader = myCommand.EndExecuteReader(itfAsynch)
While myDataReader.Read()
MessageBox.Show(myDataReader(0).ToString())
End While
myDataReader.Close()
Transactions
.8
‫א\^ل‬،Q'o.'‫و‬CQ'‫ن‬C$9hF‫א‬53D'F‫'د‬%‫'و‬S$Q$,HVI F‫א‬lWSoQ
.2KFD„‘1KFD53PN‫א‬KQ'R‫א‬hFDSF‫א‬lWkg,‫א‬
:‫א‬KPT ‫'ن‬P‫ن‬C$9h‫א‬$D‫'א‬.UKF‫א‬h‫'א‬1I‫א‬W
.1KFDX53H9‫دو‬500GR .2KFDXUH9‫دو‬500‫אع‬$Q‫א‬ً ^3‫ل‬V9‫ع א‬179^‫א‬F‫אو„و_א‬F‫€א‬e'nN}،Q'‫אن‬$9 ‫ن‬F‫نא‬S‫و‬
fQ3'S‫و‬AI‫دونא‬gN3 FD‫א‬fW‫و‬CYF‫دא‬FD‫א‬Q‫אن‬$9‫א‬W،‫'ل‬73
—‫א‬Wg!
.roll back
nD DBMS h‫א‬i$D.‫(م‬UhF‫א‬53D'F¡‫א‬lWSoQ transaction KFNF. ‫‘ذא‬
.Q'SWON‫م‬$D‫אو‬Q'SWONQri$‫وא‬i$‫و‬KP,
zƒ‫ ل א‬5Fs i‫'د‬%'\‫ א‬SqlTransaction JO‫ א‬S NQ$ F‫ א‬lWS 5D ‫و‬p\‫ א‬JO‫א‬
:K^3ًMQ‫ א‬.net zƒC‫ل‬5FsF‫א‬lWSˆ1gNP> AIChJ!¤NS،System.Data.SqlClient
lWSUD$‫א‬N‫م‬$7t‫ א‬COM+ h'P303‫ل‬V9‫א‬JO‫א‬lWSN:System.EnterpriseServices
.F‫א‬
. transactions‫אل‬D$h71zN JO‫א‬lWSN :System.Transactions
.ً MQ‫ א‬transaction ‫د¨אل‬3 ˆ153‫ن‬JO‫نא‬SNNPe : WWF ‫و‬WCF
KF ‫'م‬7Q Stored ProcedureoQ ˆQ 5D Fg\‫ א‬lWg ‫م‬7‫ א‬NP> h‫ א‬$D‫'א‬. ( U n
462
53‫'ع‬N‫אא‬WSUz$‫א‬NP>،COMMIT ‫ و‬ROLLBACK ‫و‬TRANSACTION ˆQ5D transactions
:NS
‫رابط‬
http://msdn.microsoft.com/en-us/library/ms187844.aspx
W‫ وא‬IDbTransaction interfaceg%‫ˆ א'א‬1 t‫ א‬DBTransaction JO‫ א‬NQ$ ADO.net U
:‫א‬j‫وאلא‬$‫א‬nD'd
C#
public interface IDbTransaction : IDisposable
{
IDbConnection Connection { get; }
IsolationLevel IsolationLevel { get; }
void Commit();
void Rollback();
}
‫ﻛﻮد‬
VB
Public Interface IDbTransaction
Inherits IDisposable
ReadOnly Property Connection() As IDbConnection
ReadOnly Property IsolationLevel() As IsolationLevel
Sub Commit()
Sub Rollback()
End Interface
‫ﻛﻮد‬
Ug‘‫'ع‬%‫א‬Q17ªONt‫ وא‬Save Si$Q$%‫ دא‬SqlTransaction ‫אل‬NoMQ
K‫א‬3nDF‫و א‬CF‫א‬53z‫א‬%‫א‬¤NS‫'ن‬−K3PF‫א‬U‫'ع‬%‫لא‬$F‫مא‬e‫ א‬UKTO‫א‬
(‫א\'دع‬£\‫ א‬− KF‫)אא‬nD'd‫ول‬$% ‫'د‬%‫אضو‬Z!‫'א‬S ،F‫ א‬lWSˆ1nD‫^ل‬3a‫א‬
:‫א‬KPTF‫'م‬7IŠ„‘X53KQ' F‫'م‬73$ND‫و‬
C#
SqlCommand cmdGet = new SqlCommand("update customers set total=total-" +
totalmoney.ToString() + " where ID" + custID.ToString(), cn);
cmdSelect.ExecuteNonQuery();
SqlCommand cmdSet = new SqlCommand("update customers set total=total+" +
totalmoney.ToString() + " where ID" + SuppID.ToString(), cn);
cmdSelect.ExecuteNonQuery();
‫ﻛﻮد‬
463
VB
Dim cmdGet As New SqlCommand("update customers set total=total-" +
totalmoney.ToString() + " where ID" + custID.ToString(), cn)
cmdSelect.ExecuteNonQuery()
‫ﻛﻮد‬
Dim cmdSet As New SqlCommand("update customers set total=total+" +
totalmoney.ToString() + " where ID" + SuppID.ToString(), cn)
cmdSelect.ExecuteNonQuery()
N]h‫ א‬i$D.‫(م‬HI‫ولא‬RN‫א‬W،F‫א‬53^‫א‬zŽ‫א‬o.'Q$.‫ن‬G‫ و‬F‫א‬lWSU
.i,3AI‫א‬zq‫ א‬FgN3i$‫وא‬WONQ_'‫و‬،€.'‫@א‬OUYF‫ א‬WONN
C#
SqlCommand cmdGet = new SqlCommand("update customers set total=total-" +
totalmoney.ToString() + " where ID" + custID.ToString(), cn);
SqlCommand cmdSet = new SqlCommand("update customers set total=total+" +
totalmoney.ToString() + " where ID" + SuppID.ToString(), cn);
SqlTransaction sqltr = null;
try
{
sqltr = sqlCn.BeginTransaction();
cmdGet.Transaction = sqltr;
cmdSet.Transaction = sqltr;
cmdGet.ExecuteNonQuery();
cmdSet.ExecuteNonQuery();
if (throwEx)
{
throw new ApplicationException("all operation canceld, some errors occures");
}
sqltr.Commit();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
tx.Rollback();
}
}
‫ﻛﻮد‬
VB
Dim cmdGet As New SqlCommand("update customers set total=total-" +
totalmoney.ToString() + " where ID" + custID.ToString(), cn)
‫ﻛﻮد‬
464
Dim cmdSet As New SqlCommand("update customers set total=total+" +
totalmoney.ToString() + " where ID" + SuppID.ToString(), cn)
Dim sqltr As SqlTransaction = Nothing
Try
sqltr = sqlCn.BeginTransaction()
cmdGet.Transaction = sqltr
cmdSet.Transaction = sqltr
cmdGet.ExecuteNonQuery()
cmdSet.ExecuteNonQuery()
If throwEx Then
Throw New ApplicationException("all operation canceld, some errors occures")
End If
sqltr.Commit()
Catch ex As Exception
MessageBox.Show(ex.Message)
tx.Rollback()
End Try
WON‫א‬W‫طو‬T‫א‬UKI$5!]1ICE$d_3‫و‬، transaction ‫אل‬FDz$‫'م‬7،€(9F
throw Exception 3‫'م‬7N!]1I‫א‬E‫و‬$U3C،FS‫د‬FD‫وא‬YF‫א‬WON Commit ‫دא‬
t‫ א‬h‫ א]‹
א‬0B zq‫ א‬K%‫ א‬53 rollback ‫א‬$‫ א‬zD$ ¤NS ‫'م‬7N Catch „‘ i,3 N7NQ W‫وא‬
.€‹$
.E$d3X%‫ و‬throwEx=trueF.K%X%،:‹‫و‬$O!\‫אא\^ل‬WS {‫€'د‬N'
^‫א‬FŽ‫א‬U]1I‫'د‬%‫مو‬$DU3C،‹]_ ً ^3 1KF‫א‬£3F.‫אن‬$`‫^אšن‬3€%'
.2KFD„‘1KFD53g7”$.£\‫ א‬53i‫د‬$[‫א‬FP‫אنא‬$`!
‫ﻣﻼﺣﻈﺔ‬
‫ولאو‬$%¤NS‫'ن‬Pi‫אد‬UK ،KPT‫אא‬WgfV‫אعوא‬$Q9‫'ن(مא‬PQ5Q$Ž‫א‬71Uً
.:! I‫و‬GR‫و‬fb‫אعو‬$Q‫א‬53 KFDKPl‫א¡א‬hF‫א‬nD'd‫ول‬$%53^‫א‬
465
‫اﻟﻮﺿﻊ اﻟﻤﻨﻔﺼﻞ‬
.9
]TNQ W‫'א‬S‫ و‬connected layerKV\‫ א‬0s'‫ א‬5D ADO.net N7 U N^Q$V.‫ א‬7‫ א‬N‫و‬H‫ د‬U
N:3$7W‫א^א‬zŽ‫א‬،ً(Lg! Q$0B ‹prh‫א‬i$D.Y‫و‬Ni,31‫א‬H
i$D. 03 K3 FQ W‫ وא‬disconnected layer KVON\‫ א‬0s'‫ˆ א‬1 P3‫ א‬S N7‫ א‬lWS
.h‫א‬i$D. „‘i$‫وא‬i3h Q$‫!א‬K7‹53‫و‬hJO‫א‬53D'FˆQ5Di‫א‬W‫א‬U h‫א‬
zT‫ ‹ א‬53‫ و‬، 234‫ א‬Y‫ و‬h‫ א‬i$D. Y a‫'ن و‬PQ DataAdapter KFD ˆQ 5D ‫ ذ‬Q
.h‫א‬i$D.„‘AICi3kH‫‹ א‬gDKF‫א‬QDataSet
. DataColumn‫ و‬DataRow hNjnD' DataTable 53‫د‬$DCnD DataSet ‫'אل‬
i$D.gOS DataSet ‫!ل‬،hi$D.03‫ل‬V9‫א‬53‫א'ع‬:!‫م‬Q90s'‫אא‬WS‫]ن‬W‫ אن‬7
‫א‬WSQgUAICi3g‘‫!‹'د‬h i$D7‫ل‬V‫دونאא‬Q‫א‬$‫א‬UN‫و‬H‫د‬Kb‫'א‬N‫א‬Wh
.7‫א‬
DataSet ‫ اﻟـ‬.9.1
hQ'[‫א‬،−€.p3−i‫א‬W‫א‬U5P‫و‬h$D‫'א‬.‫(م‬N iH'b5DiHDS DataSet ‫אل‬$Q$,HVI
:SJO‫א‬lWk‫א‬
: ‫א‬hJO‫א‬
.i$D7‫א‬lWSU‫אول‬$Ž‫ א‬:DataTableCollection
.O+\‫אولא‬$Ž‫א‬Yh. ‫א‬:DataRelationCollection
DataSet .‫*‘„אل‬jVI!s9:PropertyCollection
:‫*א‬jVœ‫א‬
466
.9‫א‬:DataSetName
،hQ'RF serialize KFDgQt‫א‬7Q1‫א‬$Q$:RemotingFormat
.l
—‫ אو‬XML ‫ אو‬binary K^3
:‫وאلא‬$‫א‬
AcceptChanges KFD ”i3IŠWN3 DataSet ‫אل‬nD€et‫א‬h‫
א‬q‫ˆא‬1:AcceptChanges()
.h‫א‬i$D.„‘k
KFD ” i3 IŠ WN3 DataSet ‫ אل‬nD €e t‫ א‬h Q$‫ א‬0B zq‫ א‬: RejectChanges()
.kAcceptChanges
DataSet .‫אل‬hQ')!3:Clear()
h. ‫אولوא‬$Ž‫א‬g!}h‫א‬i$D7 structure KPk‫א‬¢:Clone()
.h‫א‬0B „‘!s‫א‬KPk‫א‬¢:Copy()
AcceptChanges KFD”i3IŠWN3 h‫א‬i$D7€‹$t‫א‬h‫
א‬q‫!!א‬3: GetChanges()
.k
KFD ” i3 IŠ WN3 €e $. h‫
א‬q ¤NS € ‫ אذא‬F! $Q$ Boolean F. : HasChanges()
.9‫אم‬AcceptChanges
. DataSet i$D23‫د‬:Merge()
DataSet ‫ אل‬53 XML KP,nDiz‫א‬7‫وא‬P‫ א‬: WriteXml() ‫و‬ReadXml()
: DataSet ‫اﻧﺸﺎء‬
:‫א‬KPT 7Qa‫'د‬P‫ˆא‬Q5D DataSet zT‫א‬NP>
C#
DataSet empDataSet = new DataSet("My Employee");
‫ﻛﻮد‬
VB
Dim empDataSet as DataSet = New DataSet("My Employee")
‫ﻛﻮد‬
467
g(‫و‬gR. DataSet $` Data h‫אدوא‬Fj.53، .net h‫دوא‬CˆQ5DSzT‫א‬NP>‫و‬C
:‫א‬KPTi,3©\‫א‬
DataTables ‫ اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬.9.2
:S:‫א‬bN‫*وא‬jVœ‫א‬،i$FDC‫و‬f'ObnD ً 79'RW‫وא‬9‫א‬VN‫'א‬S‫ول‬$Ž‫א‬
.‫ول‬$Ž‫א‬KPS¢:Copy()
Table .‫אאل‬WSnD'dW‫ א‬DataSet ‫אل‬:DataSet
.‫ول‬$Ž‫אא‬Wk PrimaryKey ‫אل‬:PrimaryKey
.‫ول‬$Ž‫אא‬:TableName
.‫ول‬$Ž‫אא‬WSgQ'dt‫א‬h. ‫א‬:ParentRelations
DataTable ‫ اﻧﺸﺎء‬.9.3
C#
DataTable EmployeeTable=new DataTable();
EmployeeTable.PrimaryKey = new DataColumn[] { EmployeeTable.Columns[0] };
‫ﻛﻮد‬
VB
Dim EmployeeTable As New DataTable()
‫ﻛﻮد‬
468
EmployeeTable.PrimaryKey = New DataColumn() {EmployeeTable.Columns(0)}
: DataSet ‫ إﻟﻰ‬DataTable ‫اﺿﺎﻓﺔ‬
C#
empDataSet.Tables.Add(EmployeeTable);
‫ﻛﻮد‬
VB
empDataSet.Tables.Add(EmployeeTable)
‫ﻛﻮد‬
DataColumns ‫ اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬.9.4
KPT DataColumns ‫ אل‬53 D'F ‫ !¦ن‬IŠ nN}‫ و‬، h‫ א‬i$D. U $‫'د وא‬FD JO‫ א‬lWS K^e
:SJO‫א‬lWk‫א‬h'P\‫א‬،h‫ א‬i$D.KPSnD'dDataTable
ob'‫א‬
bœ‫א‬
F7‫ א‬nD ‫'د‬F‫אא‬WSU7‫™א‬z‫مא'א‬$vF‫א‬$Q$R
AllowDBNull
Null
F j7 . bI KFD E ^‫* א‬jVœ‫ א‬lWS 
$Q$R ‫م‬$+‫ و‬، SQL Server 5D NH‫ دو‬Q‫א‬$ U SNRs‫אو‬
GZ‫ א‬nDi3K03i‫د‬Q‫א‬H‫א‬$73‫و‬Q‫א‬$‫א‬17$Q$‫و‬bœ‫א‬
AutoIncrement
AutoIncrementSeed
AutoIncrementStep
‫'د‬F‫אא‬
Caption
h‫'ع א‬
DataType
‫'د‬F‫אא‬WSU‫'ل‬7L‫א‬7s‫א‬Z!9‫א‬F7‫א‬
DefaultValue
‫'د‬F‫אא‬WS:0QW‫ א‬DataTable ‫אل‬$Q$
Table
Primary keyH‫א‬P.
—F7‫א‬lWS ‫د'ن‬$
Unique
:
: DataColumns ‫اﻧﺸﺎء‬
9Fg!F‫وא‬9‫א‬3C،j7.ًMQ‫وא‬jHvO3'S W‫א‬.‫א‬nD'hi$D.zT‫ضא‬ZON
:‫ول‬$Ž‫אא‬WSUi$FD‫א‬KP,'S‫א‬WS‫'ن‬P،iŸ .CnD‫ن‬Q'd
469
C#
DataColumn EmpIDColumn = new DataColumn("ID", typeof(int));
EmpIDColumn.Caption = "Employee ID";
EmpIDColumn.ReadOnly = true;
EmpIDColumn.AllowDBNull = false;
EmpIDColumn.AutoIncrement=true;
EmpIDColumn.AutoIncrementSeed=1;
EmpIDColumn.AutoIncrementStep =1;
EmpIDColumn.Unique = true;
DataColumn EmpNameColumn = new DataColumn("Name", typeof(string));
EmpNameColumn.Caption = "Employee Name";
DataColumn EmpAgeColumn = new DataColumn("Age", typeof(int));
EmpAgeColumn.Caption = "Employee Age";
‫ﻛﻮد‬
VB
Dim EmpIDColumn As New DataColumn("ID", GetType(Integer))
EmpIDColumn.Caption = "Employee ID"
EmpIDColumn.[ReadOnly] = True
EmpIDColumn.AllowDBNull = False
EmpIDColumn.AutoIncrement = True
EmpIDColumn.AutoIncrementSeed = 1
EmpIDColumn.AutoIncrementStep = 1
EmpIDColumn.Unique = True
Dim EmpNameColumn As New DataColumn("Name", GetType(String))
EmpNameColumn.Caption = "Employee Name"
Dim EmpAgeColumn As New DataColumn("Age", GetType(Integer))
EmpAgeColumn.Caption = "Employee Age"
‫ﻛﻮد‬
:‫א‬KPT DataTable ‫‘„אل‬gOM‹53‫و‬
C#
EmployeeTable.Columns.AddRange(new DataColumn[] { EmpIDColumn,
EmpNameColumn , EmpAgeColumn });
‫ﻛﻮد‬
VB
EmployeeTable.Columns.AddRange(New DataColumn() {EmpIDColumn,
EmpNameColumn, EmpAgeColumn})
‫ﻛﻮد‬
470
DataRows ‫ اﻟﻌﻤﻞ ﻣﻊ‬.9.5
:SJO‫א‬lWkj‫א‬h'P\‫א‬،f'OV‫א‬03K3 JO‫א‬lWS*§
ob'‫א‬
bœ‫א‬
objects‫אل‬53 array !'OV3KP,nDoV‫אא‬WSh!
ItemArray
oV‫אא‬WSnD'dW‫ولא‬$Ž‫א‬
Table
oV‫אא‬WSnD€et‫א‬h‫
א‬q‫ˆ א‬1
AcceptChanges()
zD$‫ ” א‬i3IŠ WN3 oV‫א א‬WS nD €e t‫ א‬h‫
א‬q‫ א‬zq‫א‬
RejectChanges()
g!AcceptChanges()
oV‫אא‬WSnDKQ$‫א‬FD z$
BeginEdit()
h Q$‫א‬ªO‫و‬KQ$‫א‬FDzg‫א‬
EndEdit()
KQ$‫א‬FDzq‫א‬
CancelEdit()
AcceptChanges()zD$‫א‬$NDoV‫אא‬WSfW
Delete()
9 ‫ אم‬null SKS‫و‬oV‫אא‬WSU3‫'د‬FDF.!\
IsNull()
nF\‫ א‬enum ‫ אل‬53 gz‫א‬. 5P> t‫ وא‬oV‫ א‬
RowState
DataRowState
:‫א‬7‫א‬nD−DataRowState–'dW‫وא‬
471
: DataRows ‫اﻧﺸﺎء‬
:]1I]TNQf'1‫אא‬WSK^3،i,3 DataRows zT‫א‬5P>9
C#
DataRow r = new DataRow();
‫ﻛﻮد‬
VB
Dim r As DataRow = new DataRow();
‫ﻛﻮد‬
. 0s‫ وو‬DataRow 53 + zT9 ‫א א\^ل‬WS ، ‫ول‬$Ž‫ א‬53+ 53 DataRow zT‫ א‬53 $ 9 5P
.Q‫א‬$‫א‬U:FNF.W‫ولא‬$Ž‫א‬Gg!f'OV‫™א‬
C#
DataRow EmpRow = EmployeeTable.NewRow();
EmpRow["Name"] = "Ahmed Gamal";
EmpRow["Age"] = 22;
EmployeeTable.Rows.Add(EmpRow);
EmpRow = EmployeeTable.NewRow();
EmpRow[1] = "Ahmed Essawy";
EmpRow[2] = 23;
EmployeeTable.Rows.Add(EmpRow);
‫ﻛﻮد‬
VB
Dim EmpRow As DataRow = EmployeeTable.NewRow()
EmpRow("Name") = "Ahmed Gamal"
EmpRow("Age") = 22
EmployeeTable.Rows.Add(EmpRow)
EmpRow = EmployeeTable.NewRow()
EmpRow(1) = "Ahmed Essawy"
EmpRow(2) = 23
EmployeeTable.Rows.Add(EmpRow)
‫ﻛﻮد‬
3‫א‬9‫'ل‬7R ‫'ل‬b'‫א‬g!„‫אو‬L‫אنא‬F،j7. :ً‫ (א‬ID K7L‫א‬0M_N‫(€ א‬9'
. Index ‫אل‬.4!^‫א‬
‫ وﻣﻌﺮﻓﺔ اﻟﺼﻔﻮف‬DataSet ‫ ﻣﻌﺮﻓﺔ ﻛﻞ اﻟﺠﺪاول ﻓﻲ ﻗﺎﻋﺪة اﻟﺒﻴﺎﻧﺎت‬: ‫ ﻣﺜﺎل ﺷﺎﻣﻞ‬:‫واﻷﻋﻤﺪة‬
472
C#
Text1.Text="";
foreach (DataTable dt in empDataSet.Tables)
{
Text1.Text+=dt.TableName + ":\n\r";
for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
{
Text1.Text+= (curCol+1).ToString() + dt.Columns[curCol].ColumnName+"\n\r";
}
Text1.Text="Rows: \n\r";
for (int curRow = 0; curRow < dt.Rows.Count; curRow++)
{
for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
{
Text1.Text+= dt.Rows[curRow][curCol].ToString() + " - ";
}
}
}
‫ﻛﻮد‬
‫ﻛﻮد‬
VB
Text1.Text = ""
For Each dt As DataTable In empDataSet.Tables
Text1.Text += dt.TableName + ":" & Chr(10) & "" & Chr(13) & ""
For curCol As Integer = 0 To dt.Columns.Count - 1
Text1.Text += (curCol + 1).ToString() + dt.Columns(curCol).ColumnName + "" &
Chr(10) & "" & Chr(13) & ""
Next
Text1.Text = "Rows: " & Chr(10) & "" & Chr(13) & ""
For curRow As Integer = 0 To dt.Rows.Count - 1
For curCol As Integer = 0 To dt.Columns.Count - 1
Text1.Text += dt.Rows(curRow)(curCol).ToString() + " - "
Next
Next
Next
‫ ﻟﻘﺮاءة اﻟﺒﻴﺎﻧﺎت ﻣﻦ‬DataTableReader ‫ اﺳﺘﺨﺪام‬.9.7
DataTable
C#
Text1.Text="";
DataTableReader dtReader = dt.CreateDataReader();
‫ﻛﻮد‬
473
while (dtReader.Read())
{
for (int i = 0; i < dtReader.FieldCount; i++)
{
Text1.Text+= dtReader.GetValue(i).ToString();
}
}
VB
Text1.Text = ""
Dim dtReader As DataTableReader = dt.CreateDataReader()
While dtReader.Read()
For i As Integer = 0 To dtReader.FieldCount - 1
Text1.Text += dtReader.GetValue(i).ToString()
Next
End While
‫ﻛﻮد‬
XML ‫ إﻟﻰ‬Serializing ‫ﻋﻤﻞ‬
.10
C#
EmpDataSet.WriteXml("Employee.xml");
‫ﻛﻮد‬
VB
EmpDataSet.WriteXml("Employee.xml")
‫ﻛﻮد‬
:@P‫وא‬C
C#
EmpDataSet.ReadXml("Employee.xml");
‫ﻛﻮد‬
VB
EmpDataSet.ReadXml("Employee.xml")
‫ﻛﻮد‬
:ً Q7KPT‫אא‬Wg Employee.xml o\‫א‬2‫'ن‬P
‫ﻛﻮد‬
<?xml version="1.0" standalone="yes"?>
<Employee_XML>
474
<Employee>
<ID>1</ID>
<Name>Ahmed Gamal</Name>
<Age>22</Age>
</Employee>
<Employee>
<ID>2</ID>
<Name>Ahmed Essawy</Name>
<Age>23</Age>
</Employee>
</Employee_XML>
DataGrid ‫اﺳﺘﺨﺪام ال‬
.11
DataGridView i‫אدא‬GR'SD3K،YO&'\‫ولא‬$%:!Ns‫ ً وو‬7lzTNF.W‫א‬ND‫و‬T3U
:‫א‬KPTi‫'د‬%'\‫ א‬h‫אدوא‬5Fs53
New !s‫ א‬HI . ، Choose DataSource ˆQ 5D H$V\ h‫ א‬i$D. aH 'S ND 3 K
.Nbœ‫א‬h‫ א‬i$D.HI‫'م‬7‹53‫ و‬DataBase !s‫א‬،©\‫א‬0.‫و‬،DataSource
‫ﻣﻼﺣﻈﺔ‬
‫ وאض אل‬DataSource KF ‫'م‬.‫ א‬ConnectionString ‫ אل‬5D r‫ א‬53 9
ً $ i‫ אد‬U
gjq ‫'م‬.‫‹א‬،ConnectionString
t‫ مא‬9‫א‬B‫و‬C‫ول‬$Ž‫א‬HI¤4§,, g(،‫س‬H'‫א‬$‫א‬HIbœ‫א‬,T‫א‬zg‫א‬$
X`Nˆ9‫^ل‬3U‫و‬،YO&'\‫ولא‬$%'S‫ و‬i,3‫ول‬$%HI‫א‬X`N ،‫ول‬$Ž‫א‬Ug(‫ن‬Ck‫'د‬
.‫ א م‬BHI‫א‬
475
:‫א‬WSK^3ًJ,2N‫'نא‬P
.‫ول‬$Ž‫א‬53!s9‫وא‬KQ$bO‫אא‬NP> 01
=‫אول‬9‫א‬kt‫א‬A'h‫ضא‬DQ9rR‫ط‬,ˆ1N،ً‫א‬$% a KQ$X`N‫אšن‬
‫ א م‬B G‫ ‹ א‬53‫ و‬Add Query ZI‫ א‬dataGrid ‫ אل‬53 ، * 03 U ‫'د‬%'\‫א אول א‬
:
476
:2jN‫א‬$S,‫و‬QgN‫א‬n9‫א‬X%،‫א‬KPTnD‫א‬U,,H'g& ª ‫؟‬K‫א‬WPS53Kg‫א‬$%'Q KS
DataAdapter ‫اﺳﺘﺨﺪام‬
.12
:‫لא‬PT DataAdapter oQ.،i$Q$,
C#
string connectionString = @"Data Source=AHMED-PC\SQLEXPRESS;Initial
Catalog=Employee;Integrated Security=True;Pooling=False";
‫ﻛﻮد‬
DataSet ds = new DataSet("Employee");
SqlDataAdapter dAdapt = new SqlDataAdapter("Select * From
Employee_info", connectionString);
dAdapt.Fill(ds, "Employee_info");
‫ﻛﻮد‬
VB
Dim connectionString As String = "Data Source=AHMED-PC\SQLEXPRESS;Initial
Catalog=Employee;Integrated Security=True;Pooling=False"
Dim ds As New DataSet("Employee")
Dim dAdapt As New SqlDataAdapter("Select * From Employee_info", connectionString)
dAdapt.Fill(ds, "Employee_info")
477
‫اﻟﺒﺎب‬
18
LINQ
.O+\‫א‬h‫א‬$D‫'א‬.03g3gNi\‫א‬lWS،LINQ03AICi3‫'د‬N
478
479
‫ﻣﻘﺪﻣﺔ‬
.1
Language Integrated N7nDfNH‫و‬$‫א‬z%، ADO.net _DU‫ط‬7N‫™א‬nDN!‫אن‬$
ˆ‫س‬H‫د‬UNO‫א‬Ff$g€!'‫و‬PQ3 53i$Q$%N7S‫و‬، LINQ ً‫א‬HVI‫א‬fQ3‫ אو‬Query
B $' ‫ ‘„ ذ‬os‫ א‬، 'Q‫ !`'אل 'د‬J ‫ ل‬I 53 g! PR‫ א‬5P> Q'. h3 ‫ א‬zN „‘
o3‫و‬C XML File ‫و‬Chi$D.‫ن‬z‫'א‬:3K3W‫א‬h‫א‬$D‫'א‬.H$V3 D'5PFg3‫ م‬9‫א‬
.:! I‫و‬CK‫א‬o3‫ אو‬V
:Sgj‫א‬%C nDf‫ولא‬RNjH‫א'אع‬E ‹ LINQ K
LINQ to SQL −1
LINQ to XML −2
LINQ to Objects−3
U lN, W‫ض א\^ل א‬ZON ، Array ‫ 'ع‬53 q3 „‘ i,3 ‫ م‬9‫ א‬S ‫ م‬9‫'אع א‬C aC
:‫א‬KPT‫وس‬H‫د‬i$DK. LINQ „‘N3$73
‫ﻛﻮد‬
from d in developers
where d.Language =="C#"
select d.Name;
:‫ א‬KPTgPNt‫ مא‬9‫א‬BgOSlWS
‫ﻛﻮد‬
select name from developers where language=’C#’
nDg71 NP3Hb K،gDlWS ‫ م‬9‫א‬BWONhi$D.‫'د‬%'‫ ‰ج‬$_‫אšن‬5P‫و‬
:‫א‬KPT!'OV3
480
C#
public class Developer
{
public string Name;
public string Language;
}
Developer[] developers = new Developer[] { new Developer { Name = " Ahmed",
Language="C#" }, new Developer { Name="Khaled", Language="Java", new
Developer { Name="Ali", Languag="C++"} };
‫ﻛﻮد‬
‫ﻛﻮد‬
VB
Public Class Developer
Public Name As String
Public Language As String
End Class
Dim developers As Developer() = new With { New Developer { .Name = " Ahmed",
.Language="C#" }, New Developer { .Name="Khaled", .Language="Java", New
Developer { .Name="Ali", .Languag="C++"} }
:‫א‬KPT1 ‫א م‬BGP‹ 53‫و‬
C#
IEnumerable<string> LINQresult =
from d in developers
where d.Language =="C#"
select d.Name;
‫ﻛﻮد‬
VB
Dim LINQresult As IEnumerable(Of String) =
From d In developers
Where d.Language ="C#"
Select d.Name
‫ﻛﻮد‬
:‫א‬KPT2N‫א‬DKPP3bC‫و‬
C#
foreach ( string s in LINQresult )
{
MessageBox.Show(s);
}
‫ﻛﻮد‬
481
VB
For Each s As String In LINQresult
MessageBox.Show(s)
Next
‫ﻛﻮد‬
‫ج‬9€3‫د‬3RRbF`! ،:3$D‫אو‬7‫א‬h 3\‫א‬53K33‫אمא‬$+‫א‬NP>ª F
:‫ط‬T‫א‬
C#
IEnumerable<string> LINQresult =
from d in developers
select d.Name;
‫ﻛﻮد‬
VB
Dim LINQresult As IEnumerable(Of String) =
From d in developers
Select d.Name
‫ﻛﻮد‬
:‫א‬KPT‫'ل‬1‫ دאא‬K^3‫ط‬T‫א‬5FsQ‫د‬D.net‫אمدא‬$+‫ًא‬MQ‫א‬NP>F
C#
IEnumerable<string> LINQresult =
from d in developers
where d.Name.Length > 3
select d.Name
orderby d.Name;
‫ﻛﻮد‬
VB
Dim LINQresult As IEnumerable(Of String) =
From d in developers
Where d.Name.Length > 3
Select d.Name
Orderby d.Name
‫ﻛﻮد‬
: ‫ﺗﺮﺗﻴﺐ ﺟﻤﻞ اﻻﺳﺘﻌﻼم‬
S‫'ن‬P Select ‫م‬$+ LINQUNNP‫و‬، Select From Where GnD‫ م‬9‫ א‬KBU‫'د‬
‫`'אل‬O‫ א‬nD $F ‫ 'د אن‬N‫ א‬IntelliSense fQ 3 'S  KP G‫ א‬، ً Fj‫ دא‬i
I‫א‬
482
‫`'אل‬O‫ א‬01Q 5! From K. Select N ' F! ، N H'g(‫ א‬gNP> t‫ א‬i$FD‫ א‬N g( 'Q‫'د‬
.$:N3C7‫ن‬C$Q‫ول‬$%‫א‬fQ9:i‫'د‬%'\‫א‬h‫א‬Hœ‫א‬$Q$U$D3 'Q‫'د‬
:3P‫ مא‬9‫א‬B
‫ﻛﻮد‬
from id in source
{ from id in source /
Join id in source on expr equals expr [into id] |
Let id = expr |
Where condition |
Orderby ordering, ordering, … [Ascending | Descending]
}
Select expr |
Group expr by key
[into id query]
…‫א‬z,‫وس‘ن‬H$‫א‬lWSUNFD ‫ ل‬IgDfN،a7!U3‫א‬qV‫א‬lWS0s
LINQ ‫دوال‬
.2
53D'F¡‫א‬lWSh‫و‬,‫و‬3nD f‫ولאšنא‬RN،O†O&‫ دوאوو‬51nD LINQ'
.N‫و‬H‫ لد‬IgN3ًM‫م‬$+Nt‫وאلوא‬$‫א‬
ob'‫א‬
‫א‬$‫א‬
‫و‬Cgs‫و‬C‫م‬.HCi$D0Bً ^3،L‫א‬hFHP\‫ˆא‬1
Aggregate
:‫א\^لא‬،FDC
int product=ints.Aggregate(1, (a,b)=> a* b );
.‫م‬.H‫א‬53!'OV3Sints‫ن‬C
KS!3‫'د‬Cً ^3‫ض‬ZON،KP‫א‬nD‫ط‬,ˆ1A$3!\
All
:9‫م‬CY%‫و‬3YO&'\‫א‬K
bool
isMarried=employees.All(emp=>emp.statues==1);
a7!$‫'نوא‬URRbF.$g!،7‫@א‬PDnD
Any
483
:‫אא\^ل‬WS،‫ط‬T‫ˆא‬7dD'F¡‫א‬53K.‫א‬nD
bool isMarried=employees.Any(emp = >
employees.statues==1);
:‫אא\^ل‬WS،7‫א‬53D'F¡a'\‫א‬
Average
double avg=ints.Average();
.‫م‬.H‫א‬53D'FSints‫ن‬C
:‫אא\^ل‬WS،‫د‬$)‫‘„'ع‬bN‫א‬53D'FKQ'R
Cast
var newString=ints.Cast<string>();
.‫م‬.H‫א‬53D'FSints‫ن‬C
: query2 ‫ ` و‬: query1 NQ$ ‫^ ً ' ن‬F! ، 5QVND 23$
Concat
:‫א‬3‫אمא‬$+‫א‬5P>g‫و'دد‬AIC`
var result=query1.Concat(query2);
$F):ƒ‫ א‬o&'35DRً ^3،!'OV3KI‫دא‬R‫م‬$+
Contains
:‫א‬1‫א‬GP
bool find=employees.Contains(new
employee(“Mohammed”);
.‫د‬DQueryˆQ5D‫ذ‬KF:gT3S‫و‬
:5PQ3ًQC‫و‬C!'OV\‫א‬bND‫د‬$D‫و‬C‫א– م‬2j$‫'م‬7Q
Int count = employees.Count();
:ks‫א‬Z!‫א‬F.0s‫—!و‬H!F.¤NS€‫‘ذא‬
Count
DefualtIfEmpty
var result=ints.DefualtIfEmpty(100);
ً ^3 ، h‫'ع א‬N s‫א‬Z!9‫ א‬F7‫ א‬0s‫ ! و‬S$Q$ Q _ '
.Objectnull‫'صو‬VN""‫مو‬.H Ob
:ً ^3،h‫א‬H‫א‬PC‫ون‬$h‫א‬i‫د‬D‫'م‬7Q
Distinct
var pure=query.Distinct();
:ً ^3،Y3‫ن‬P3UF7‫א‬i‫د‬D‫'م‬7Q
ElementAt
Employee newemp=query.ElementAt(4);
` ‫אن‬YU 4.HGP$.Cˆ‫א\^لא‬U€(9'
ElementAtOrDefualt
U :C ‫ א‬FŽ‫ א‬4§ ‫א‬W ، ً bC f'Ob 0HC $ _ ‫א– م‬
‫و‬CJOs‫א‬Z!9‫א‬7:NDs9‫א‬Q‫'د‬%'3
—.‫'نא‬
:h‫'عא‬N
Employee newemp=query.ElementAtOrDefualt(4);
:ً ^3‫א‬KPT،bN‫א‬53—H!D'F‫'مج‬7Q
Var
newresult=System.Query.Sequence.Empty<employee
Empty
484
>();
:‫ن‬713FgC53$]‫א موא‬t`YH7\‫א‬
EqualAll
bool iseuql=query1.EqualAll(query2);
D'F¡‫א‬Ui‫'د‬%'\‫א‬7‫عא‬%Z‫وא‬bN‫א‬53YD'FH73
Except
:^‫א‬D'F¡‫א‬U‫'ن‬P‫ن‬C‫אو„دون‬
var result=query1.Except(query2);
...h‫א‬H‫א‬P‫ون‬$‫'ن‬P2N‫א‬
:D'F¡‫א‬UVND‫ول‬Ci‫د‬D‫'م‬7Q
First
employee firstone=employees.First();
.—H!lWSbN‫א‬D'F‫'ن‬P9‫ن‬C$9***
‫ول‬Ci‫د‬D!،D!‫א م‬UVND‫ول‬C$Q‫ن‬CًMQC5P>F
:‫وج‬3o&'3
employee firstone=employees.First(emp =>
emp.ismarried==1);
‫ م‬9‫وא‬C—H!D'F¡‫'نא‬U:C‫א‬$D3ˆ‫א‬K^3
FirstOrDefault
:s‫א‬Z!9‫א‬F7‫א‬$Q‫ن‬C`N$Q_DO‫א‬
employee firstone=employees.FirstOrDefault(emp =>
emp.ismarried==1);
Aggregate‫אل‬K^3
Sql ‫אل‬U1‫א‬GroupByK^3،$Q$R‫א‬GbN‫א‬0F{
Fold
GroupBy
:‫אא\^ل‬WS،Statement
var newGroup=employees.GroupBy(emp =>
emp.Countery);
.bœ‫א‬lWS4D:‫'ل‬b'‫א‬5P>‫و‬keynFQ‫و‬
.Join‫אل‬FD
GroupJoin
:a7!YD'F¡‫ א‬Ui‫'د‬%'\‫א‬bN‫א‬،YD'F07
Intersect
var inter=query1.Intersect(query2);
.Sql StatementsUinnerjoin‫אل‬FD
Join
:VNDIŠ$gNP‫و‬FirstK^3
Last
Employee lastone=employees.Last();
Employee lastone=employees.Last(emp =>
emp.Countery==”Egypt”);
‫ م‬9‫وא‬C—H!D'F¡‫'نא‬U:C‫א‬$D3ˆ‫א‬K^3
LastOrDefault
485
:s‫א‬Z!9‫א‬F7‫א‬$Q‫ن‬C`N$Q_DO‫א‬
employee firstone=employees.LastOrDefault(emp =>
emp.ismarried==1);
:‫אא\^ل‬WSLong‫'ع‬N‫א‬53‫'ن‬PQ2N‫א‬5P‫و‬CountK^3
LongCount
long empCount=employees.LongCount();
:D'F¡‫א‬UF.VND4C
Max
int num=ints.Max();
‫وس‬H‫د‬UNFFhJO‫א‬YhH7\‫\!א‬7Q$Q$5P>‫و‬
7
:D'F¡‫א‬UF.VNDqb‫א‬
Min
int num=ints.Min();
‫وس‬H‫د‬UNFFhJO‫א‬YhH7\‫\!א‬7Q$Q$5P>‫و‬
7
a7!int‫אل‬bN‫אجא‬+9،a7!Y3‫'ع‬53bN‫אجא‬+‫א‬
OfType
:GPً ^3
var newResult=list.OfType<int>();
:‫^ل‬F‫'د‬P‫אא‬WS(ًQ$DV)N37QG2jN‫א‬GZ
OrderyBy
Var orderlist=employees.OrderBy(emp => emp.Age);
:‫אא\^ل‬WS،‫ز‬NiH'V5P‫و‬GZ‫א‬
OrderyByDescending
Var orderlist=employees. OrderyByDescending (emp
=> emp.ID);
:YN35Q$YRRV‫مא‬.H‫א‬53D'F$'
Range
var newlist=System.Query.Sequence.Range(1,5);
:h‫א‬3@¾"1".HH‫א‬Pً ^3،h‫א‬3i$DY3.HH‫א‬P
Repeat
var list=System.Query.Sequence.Repeat(1,5);
:D'FCG@PD
Reverse
Var revList=list.Reverse();
:KP‫א‬5DQ‫ن‬C5P>،Q‫אد‬R‫א‬B
Select
var newSelect=list.Select( emp => emp);
a7!N3z‫א‬%C‫و‬C
var newSelect=employees.Select( emp => new
{emp.Name , emp.Age});
،a7!ً‫א‬$‫ًوא‬Ob‫'ن‬PQ52N‫!¦نא‬Group‫ل‬N3‫א‬$+‫א‬U
:‫א‬KPTSelectMany‫م‬$+W
var newSelect=groupedlist.Select( l => l);
SelectMany
486
:l
—nDD'F¡‫'א‬9C‫ط‬Ta7!i$‫وא‬F.i‫د‬D‫א‬
Var result=query.Single();
C‫'د‬%‫مو‬$DUs‫א‬Z!9‫א‬F7‫א‬$Q:C‫א‬$Dˆ‫@א‬O
Single
SingleOrDefault
:bND
Var result=query.SingleOrDefault();
bND10‫ول‬C‫^ ً`وز‬3،.‫א‬i‫د‬D‫وא‬bN‫א‬53‫د‬$D‫{وز‬
Skip
:7‫א‬i‫د‬D‫وא‬
var newResult=query1.Skip(10);
ً ^35P‫و‬Y3‫ط‬,ˆ7nbN‫א‬KS`Q:NP‫אˆو‬K^3
SkipWhile
:100‫אل‬$3.H‫{وز‬
var newResult=query1.SkipWhile(x => x < 100);
:D'F.0B
Sum
:Q‫א‬$‫א‬53Y3‫د‬$bND‫ع‬%Z‫'م‬7Q
Take
Double sum=ints.Sum();
var top=ints.Take(3);
.H‫א®د‬n‫ع‬%Z9‫^ ًא‬3،3‫ط‬,E‫و‬$nbND‫ع‬%Z‫א‬
TakeWhile
:100534‫א‬
var top=ints.TakeWhile(x => x < 100);
nDzNGZGZ‫'دאœص‬P‫א‬Uً ^3،hQ'‫אو‬$Q$R
ThenBy
:ً ^3G\‫א‬nD‹F‫א‬
var orderemp=employees.OrderBy(emp => emp.Age
ThenBy emp => emp.Salary);
:ً‫ز‬N‫'ن‬PQf'i\‫א‬lWSGZ‫نא‬C‫א‬$D3ˆ‫@א‬O
var orderemp=employees.OrderBy(emp => emp.Age
ThenByDesecnding emp => emp.Salary);
:!'OV3„‘KQ'
ThenByDesecnding
ToArray
Employee[] emps=query.ToArray();
.‫אد‬jN‹!'OV3UgNQ§035P‫@אˆو‬O
ToDictionary
List<T>5jUgNQ§
ToList
Lookup<K, V>5jU2N‫א‬5Q§
ToLookup
UhsH‫א‬PT3Kd03Sequence„‘2N‫א‬KQ'
ToSequence
.‫'ل‬7L‫א‬zƒC‫وאلو‬$‫א‬Yzƒ‫א‬
KKFTD'FnD2N‫'א‬d،sQ‫دא‬9‫א‬FD
:YD'F¡‫א‬bND
Union
487
var result=query1.Union(query2);
.Q‫طאد‬TR‫א‬B
Where
‫ﻣﻼﺣﻈﺔ‬
:a‫אאא‬WS53:FNP>،(LINQC$‘)X53ˆ‫א‬zŽ‫א‬Uً‫^
א‬h$O‫א‬
http://www.vb4arab.com/vb/uploaded/2730/11202261862.pdf
: ‫ اﻟﻤﺘﻐﻴﺮات ﻏﻴﺮ اﻟﻤﻌﺮﻓﺔ‬: ‫* ﺗﺬﻛﻴﺮ ﺳﺮﻳﻊ‬
N7$j‫ !'א‬53i$‫وא‬SlWS،K.53gOQ7_J!g!2N‫'نא‬PQ‫א م‬BKF ‫'م‬7ً‫א‬
:‫^ل‬F FŽ‫א‬lWS،ً7g,”t‫א‬Implicitly Typed Local Variables
‫ﻛﻮد‬
var subset =
from i in numbers
where i < 10
select i;
: LINQ ‫ ﻣﻊ‬Lambda Expressions ‫ اﺳﺘﺨﺪام‬: ‫* ﺗﺬﻛﻴﺮ آﺧﺮ‬
7Q1 LINQ ‫א م‬53ً9$ Lambda Expressions ‫دא‬39h‫אم
א‬$+‫א‬hD1‫ن‬CW
.Q‫אد‬
LINQ TO DATASET
.3
i$%17KPg!‫א‬W،i‫א‬W‫א‬Uh‫א‬i$D.53+‫و‬CiH'bKPT NO‫א‬F dataset ‫אل‬
.Nbœ‫ א‬LINQ h3 ‫א‬gD‫م‬$+N
h‫™א‬nD‫'ل‬VL‫ وא‬DataTable~g1H‹53‫ و‬DataSet‫אم‬$+hi$D.aHX`Nً ^F!
:gN3
C#
DataSet ds = LoadDataSetSomeway();
‫ﻛﻮد‬
488
DataTable employees = ds.Tables["Employee"];
var query =
from emp in employees.AsEnumerable()
where emp.Field<Long>( "Age" ).Year >= 40
select emp;
VB
Dim ds As DataSet = LoadDataSetSomeway()
Dim employees As DataTable = ds.Tables("Employee")
‫ﻛﻮد‬
Dim query =
From emp In employees.AsEnumerable()
Where emp.Field<Long>( "Age" ).Year >= 40
Select emp;
LINQ TO XML
.4
53IŠ‫'ع‬C03g3K^3 XML03K3 LINQ‫و‬،ًD',h‫^†زنא‬C$C‫ אšن‬XML€RbC
.Q'gDfNt‫وא‬a7!XMLX*§t‫!א‬s–‫*א‬jVœ‫!™א‬s‫א‬،h‫א‬$D‫'א‬.
:‫א‬KPTh`N\‫™א‬nD'dXMLo3NsZ!‫^ ً'א‬F!
‫ﻛﻮد‬
<?xml version="1.0"?>
<Items>
<Item Number="122">
<ItemName>Item1</ItemName>
<Quantity>100</Quantity>
<Price>23</Price>
</Item>
<Item Number="123">
<ItemName>Item2</ItemName>
<Quantity>10</Quantity>
<Price>14.5</Price>
</Item>
<Item Number="124">
<ItemName>Item3</ItemName>
<Quantity>31</Quantity>
489
<Price>1000</Price>
</Item>
<Item Number="125">
<ItemName>Item4</ItemName>
<Quantity>22</Quantity>
<Price>97</Price>
</Item>
</Items>
</Items>
:‫א‬KPTXML‫אل‬o\LoadKF‫'م‬7NQ‫א‬$
‫ﻛﻮد‬
C#
XElement purchaseOrder = XElement.Load("Items.xml", LoadOptions.SetBaseUri |
LoadOptions.SetLineInfo);
VB
Dim purchaseOrder As XElement = XElement.Load("Items.xml",
LoadOptions.SetBaseUri Or LoadOptions.SetLineInfo)
‫ﻛﻮد‬
:‫א‬KPT:PW‫'دא‬P‫'نא‬P،NQ$i‫'د‬%'\‫א‬fNb‫א‬D'F‫'دאאض‬NCNsZ!‫'א‬،‫אšن‬
C#
var newSearch =
from item in Items.<Item>
select item.@Number
‫ﻛﻮد‬
VB
Dim newSearch =
From item In Items.<Item>
Select item.@Number
‫ﻛﻮد‬
‫^ ً؟‬3H9‫دو‬100534CSt‫א‬D'F¡‫א‬nDH'^‫و‬
C#
var newSearch =
from item In Items.<Item>
where item.<Price>.Value > 100
select item.@Number
‫ﻛﻮد‬
490
VB
Dim newSearch =
From item In Items.<Item>
Where item.<Price>.Value > 100
Select item.@Number
‫ﻛﻮد‬
LINQ TO SQL
.5
gDf‫ولא‬RN‫و‬3‫א‬$+‫א^א‬S i‫אد‬U، SQL Server D$ًVVIg%'3 LINQ hJ!53J!
.‫س‬H$‫אא‬WSUًQ
: ‫اﻟﺒﺤﺚ واﻻﺳﺘﻌﻼم‬
$QQ 5QW‫ص א‬+, i$Q$% J! KP, nD ‫ج‬+‫ א‬¢QH‫ و‬9‫ א‬i‫د‬D9 ً ^3 ‫א א\^ل‬WS ، ً 7 :D N!
:V3U‫'ن‬N17Q‫ و‬N305DSFD
C#
var query = from c in Employee
where c.Age > 30
&&
c.Countery == "Egypt"
select new { c.Name, c.GraduationDate};
‫ﻛﻮد‬
VB
Dim query = from c in Employee
Where c.Age > 30
And
c.Countery = "Egypt"
Select New { c.Name, c.GraduationDate};
‫ﻛﻮد‬
: Stored Procedures ‫اﺳﺘﺪﻋﺎء‬
‫`'אل‬O‫ א‬g ‫'م‬7Q 3 S‫ و‬، Attributes ‫@ אل‬O k Procedure :T ‫ دא‬oQ a7! 'S D 3 K
: ( $‫
وא‬q3K7Q‫)א م‬KPT‫אא‬Wg3C'S D3K‫אšن‬،ًs‫א‬Z!‫'א‬Q‫'د‬
491
C#
var c = db.ProceduresName("Egypt");
‫ﻛﻮد‬
VB
Dim c = db.ProceduresName("Egypt")
‫ﻛﻮد‬
: Compiled Query
53 fQ h‫ א‬$D‫'א‬. ‫ (م‬K% 71N\‫ א‬53 @! h‫א‬3 i$ g3$+ ‫ א م‬B ¤NS ‫‘ذא ن‬
h‫ذא‬N‫م‬$7 LINQ ً MQC،17N‫א‬lWkKL‫א‬h‫ א‬$D‫'א‬.(N!'‫א‬W،i3K‫ م‬9‫א‬nD$Q$%
. Compiled Query nFQ34DQ(N‫א‬
Compile KF CompiledQuery.Compile‫אمدא‬$+‫א‬nD$F Compiled Query ‫אل‬iP!
:‫^ل‬F‫א‬KPT‫א‬،‫ م‬9‫א‬FŽ
C#
var c = CompiledQuery.Compile(
( DataContext context, string counteryName, int age) =>
from c in Employee
where c.Age > age
&&
c.Countery == counteryName
select new { c.CustomerID, c.CompanyName, c.City } );
‫ﻛﻮد‬
VB
Dim c = CompiledQuery.Compile(
( DataContext context, string counteryName, int age) =>
From c in Employee
Where c.Age > age
And
c.Countery = counteryName
select New { c.CustomerID, c.CompanyName, c.City } )
‫ﻛﻮد‬
KFD ” W‫ م א‬9‫ א‬U R‫ وא‬، a7! Z3H‫
א‬q i3 53 ^ g3‫א‬$+‫ { א‬NP> ‫وאšن‬
::Compile
492
C#
foreach ( var row in query(dc, "Egypt",22))
{}
foreach ( var row in query(dc, "USA",28))
{}
foreach ( var row in query(dc, "Saudi",38))
{}
‫ﻛﻮد‬
VB
For Each row As var In query(dc, "Egypt", 22)
Next
For Each row As var In query(dc, "USA", 28)
Next
For Each row As var In query(dc, "Saudi", 38)
Next
‫ﻛﻮد‬
: ‫اﺳﺘﺨﺪام دوال ﻓﻲ ﺟﻤﻠﺔ اﻻﺳﺘﻌﻼم‬
:‫ مא‬9‫א‬BNs! '
‫ﻛﻮد‬
SQL Server
SELECT SUM( emp.salary ) AS TotalSalary FROM Employee emp Join Department dem
ON emp.DepartmentID = dep.ID Group By dep.ID
:‫א‬KPT LINQ KPTg 01
C#
var c =
from emp in db.Employee
join dep in db.Department
on emp.DepartmentID equals dep.ID
into TotalSalary
select TotalSalary.Sum( emp => emp.Salary );
‫ﻛﻮد‬
VB
Dim c =
From emp In db.Employee
Join dep In db.Department
On emp.DepartmentID Equals dep.ID
Into TotalSalary
Select TotalSalary.Sum( emp => emp.Salary );
‫ﻛﻮد‬
493
: LINQ ‫اﺳﺘﺨﺪام ﺟﻤﻞ اﻻﺳﺘﻌﻼم داﺧﻞ‬
nD، PIVOT 3‫א‬K^3Q$7‫ مא‬9‫ א‬KBh‫Ÿא‬53i$‫אموא‬$+9ً‫אًא‬1M3O${$.
: LINQ ‫אل‬KI‫ دא‬SQLBWON‫אم‬qV‫א‬SlWSK
: - ‫'ل‬7N3‫^ل‬3
‫ﻛﻮد‬
C#
var query = db.ExecuteQuery<EmployeeInfo>(@" With EmployeeHierarchy
(EmployeeID, LastName, FirstName, ReportsTo, HierachyLevel) AS ( SELECT
EmployeeID, LastName, ForstName, ReportsTo, 1 as HierarchyLevel FROM Employees
WHERE ReportsTo IS NULL UNION ALL SELECT e.EmployeeID, e.LastName,
e.FirstName, e.ReportsTo, eh.HierarchyLevel + 1 AS HierarchyLevel FROM Emplyees e
INNER JOIN EmployeeHierarchy eh ON e.ReportsTo = eh.EmplyeeID ) SELECT * FROM
EmployeeHierarchy ORDER BY HierarvhyLevel, LastName, FirstName" );
: LINQ‫ ﻓﻲ‬Inseret ‫اﺳﺘﺨﺪام‬
C#
var NewEmp = new Employee { [First Name] = "Ahmed", Age = 25,
Countery="Egypt"};
db.Employee.Add( NewEmp );
‫ﻛﻮد‬
‫ﻛﻮد‬
VB
Dim NewEmp = New With { .[First Name] = "Ahmed", .Age = 25, .Countery="Egypt"}
db.Employee.Add( NewEmp )
.V353‫و‬N25F‫و‬$"C $Q$%o&'3!sNF.ˆ‫א\^لא‬U
: Update ‫اﺳﺘﺨﺪام‬
C#
var EditEmp = db.Employee.Single
( c => c.Countery == "Egypt" );
EditEmp.Age = 30;
‫ﻛﻮد‬
494
VB
Dim EditEmp = db.Employee.Single
( c => c.Countery == "Egypt" )
‫ﻛﻮد‬
EditEmp.Age = 30
.N30VV3 53‫ص‬+,9‫א‬KFKQ$NF.ˆ‫א\^لא‬U
: Delete ‫اﺳﺘﺨﺪام‬
C#
var deleteEmp = db.Employee.Single
( c => c.Age > 50 );
db.Employee.Remove( deleteEmp );
‫ﻛﻮد‬
VB
Dim deleteEmp = db.Employee.Single
( c => c.Age > 50 )
‫ﻛﻮد‬
db.Employee.Remove( deleteEmp )
.N505DSHFD‫א‬$Q5QW‫ א‬YO&'\‫א‬fWrNF.ˆ‫א\^لא‬U
SubmitChanges
.6
h‫
א‬q‫א‬KO db.SubmitChanges()‫א‬$‫א‬zD$‫א‬53$ 9KQ$‫وא‬CfWR‫و‬C!s FD‫א‬$
.h‫א‬i$D.U
:‫اﻟﺘﺤﺪﻳﺚ ﺑﺎﻟﺘﺰاﻣﻦ ﻓﻲ ﻗﺎﻋﺪة اﻟﺒﻴﺎﻧﺎت‬
W‫ وא‬ChangeConflictExeption5jP‫ א‬:$`‫א‬W،KV\‫و@א‬KVON\‫א‬0s'K3 LINQ ‫*אل‬
KPT]1œ‫א‬H‫אאض‬5P>،Y3$+3i$DYh‫ א‬i$D.nDKQ$‫א‬hFD‫ض‬H5D2NQ
:‫א‬
495
C#
try
{
Db2.SubmitChanges();
break;
}
catch ( ChangeConflictExeption ex)
{
MessageBox.Show( ex.Message );
Db2.Refresh( somequery, RefreshMode.KeepChanges );
}
‫ﻛﻮد‬
VB
Try
Db2.SubmitChanges()
Exit Try
Catch ex As ChangeConflictExeption
MessageBox.Show(ex.Message)
Db2.Refresh(somequery, RefreshMode.KeepChanges)
End Try
‫ﻛﻮد‬
.AICi3 Refresh 3C03 ‫ول‬d‫]و‬1œ‫א‬Hg(Q01Q_'،WON‫ مא‬9‫ولא‬dNS
:‫א‬KPT‫א‬K^3‫ض‬HE‫و‬$U234‫ א‬¤'$Q$ SubmitChanges 3‫א‬UًMQ‫א‬5P>
C#
Db.SubmitChanges(ConflictMode.FailOnFirstConflict);
Db.SubmitChanges(ConflictMode.ContinueOnConflict);
‫ﻛﻮد‬
VB
Db.SubmitChanges(ConflictMode.FailOnFirstConflict)
Db.SubmitChanges(ConflictMode.ContinueOnConflict)
‫ﻛﻮد‬
.5QVN‫א‬5QWSnDA''9t‫ وא‬ConflictMode JO‫א‬53‫وذ‬
496
‫ ﻣﻦ ﺧﻼل اﻟﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ‬LINQ TO SQL ‫اﻧﺸﺎء ﻓﺌﺎت‬
.7
,T‫ א‬53، ً 79 g PR‫ א‬NP> LINQ TO SQL Classes zT‫ א‬53 2008'Q‫`'אل 'د‬O‫ א‬NP>
:„‫אو‬
.‫א‬W، Server Explorer ‫אل‬53hi$D.GR‫אو‬i$Q$%‫אول‬$%‫و‬h. DzT‫א‬NP>،lHI‫ א‬$
:‫אمא‬KPT‫ א‬$`،‫אول‬$Ž‫א‬GRz$.‫و‬Nbœ‫א‬h‫א‬i$D.O
€N ' Data Access Layer -zT‫ א‬U $D} ‫م‬. 'Q‫`'אل 'د‬O‫ אن א‬ª  KP ‫אšن‬
:ً ^3‫وאلא‬$hOQ$`،−SW
497
C#
partial void InsertEmployee_info(Employee_info instance);
partial void UpdateEmployee_info(Employee_info instance);
partial void DeleteEmployee_info(Employee_info instance);
‫ﻛﻮد‬
VB
Private Partial Sub InsertEmployee_info(ByVal instance As Employee_info) ‫ﻛﻮد‬
End Sub
Private Partial Sub UpdateEmployee_info(ByVal instance As Employee_info) End Sub
Private Partial Sub DeleteEmployee_info(ByVal instance As Employee_info) End Sub
}H3$F)‫س‬$Ng\‫א‬XP! LINQ5D$Q\‫!א‬3‫€'د‬N'، LINQX‫אœص‬KVO‫א‬gC‫ن‬CK.
:a‫אאא‬WSnDl${،‫אא¡ل‬WSUi$%Q‫א‬$ًN3‫'ن‬PQ
‫رابط‬
http://www.vbcoffee.net/SamerSelo/linqcourseebook.pdf
498
‫‪499‬‬
‫اﻟﺒﺎب‬
‫‬
‫‪19‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‪WWF‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
500
501
، WWF ‫ ًא‬HVI‫ א‬fQ‫ و‬Windows Workflow Foundation ~nFQ3!s‫ ”א‬.net 3.0 H‫א‬$b9‫א‬WN3
‫ ‘ن‬hF‫ אو א‬workflow ~‫ א‬WON‫ و‬.‫א‬3‫ و‬iH‫ دא‬F API ‫وאل‬$‫م وא‬g\‫ א‬53 D'F S‫و‬
. BZ‫€א‬Rb
viusal ‫אل‬KI‫دא‬g!s‫€א‬et‫א‬h4‫א‬$Ng\*jVœ‫א‬0O‫ א‬53i$‫وא‬bœ‫א‬lWS$ً
.i,3O‫א‬WON‫وא‬C‫'د‬P‫א‬03 workflows ‫אل‬23‫ند‬P39 b‫א‬studio
53234‫'ن א‬PQ،gDzN234‫א‬KPTQt‫א‬hF‫א‬D'FS Workflow ‫ אوאل‬WF ‫אل‬
‫م‬g\‫א‬53D'FnDSH‫و‬$ 't‫ وא‬Business Process ‫אل‬53™‫א‬gM0313D'F
.Q'KFt‫א™وא‬gMY‫و‬gNV‫א‬h‫ذא‬
: ‫ﻣﺜﺎل‬
h‫א‬i$D.nD Check KFD‫و‬:F.H‫ل‬I‫لوאد‬VQ9‫א‬GnD234‫א א‬WS'd:2N\V‫א‬3$I
.b‫ل‬VQ‫א‬D‹V‫א‬3$IQ$7‹l‫'د‬%‫ و‬53$]
i$D 53 ‫'ن‬PQ 234‫ وא‬tasks nF I‫א‬$‫ א‬bN‫ وא‬Business Process nF g F‫ א‬lWS
.Business Process
‫'د‬Pً7‹‫ًو‬H‫א‬13g‫א‬NSi\‫ א‬5P‫و‬، Workflow ‫אل‬i‫אدא‬3$I‫م‬$7t‫א‬23‫א‬4‫א‬53$Q$‫א‬¤NS
KQ$‫א‬:P3‫‘„ذא‬os‫א‬،h$%‫‘نو‬z1I‫א‬0‫ و‬i$ nDi$‫وא‬KP trace KFD5P>r
.Q‫'و‬gA4P‫ א‬hjŽ‫א‬Uً79
WF‫ﻣﻜﻮﻧﺎت واﺳﺎﺳﻴﺎت‬
.1
h‫א‬H‫א‬P‫ وא‬T‫א‬KFŽ!‫א‬W، visio K^3Rs'h3'H‫د‬a7!@‫و‬WONK.‫'د‬S WF ‫אل‬
.ً !SWONQ WF ‫אل‬Ui‫'د‬%'\‫א‬:! I‫و‬
.net .Kh'P3‫]نא‬,g],:! I‫ و‬assemblies ‫ و‬namespaces nD' WF ‫!ل‬G‫אא‬Wk‫و‬
502
: Workflow Activity
gN‫ل‬79‫وא‬aKj‫'و‬Q‫`'אل'د‬O‫א‬NQ‫ و‬Activities KP,nDN ‫אœص‬KF‫א‬ob'Q
:N3h‫'א‬1I KP,nDSWONQ‫אو‬Y3 Invoke ‫'ل‬V‫و‬CiZO delay ‫و‬C if else K^3™‫א‬Y‫و‬
WF ‫اﻟﺒﺪأ ﻣﻊ‬
.1.1
: Empty WorkflowZI‫ ‹א‬Workflow ‫وع‬T\‫'عא‬K%‫א‬،$Q$% ‫وع‬T3zT.
h‫א‬$ t‫'אعאوא‬ !s‫א‬،bIh7N‫א‬nD'd9‫غ‬H!‫وع‬T3: Empty Workflow
:h4‫א‬FV_D
Sequential Workflow
.1.2
KP, nD :! KF‫ א‬s' Q ، N ‫ אœص‬UML ‫ אل‬s' t‫ א‬Diagrams ‫ א'אع אل‬53 ‫'ع אول‬N‫א‬
:ً 3‫א‬$+‫وא^א‬g,‫'عא‬N‫'א‬S‫ و‬،hF‫א‬K3P‫אم‬KPT‫א‬s'37 3hFD
503
State Machine Workflow
.1.3
:h‫
א‬q‫وא‬h1‫א‬53D'F ˆQ5DE‫א‬$g3^‫א‬g
504
WWF ‫ﺗﻄﺒﻴﻖ‬
.2
H‫א\و‬F‫'ن‬U،H‫א\و‬F‫ل‬I‫مאد‬$+\‫א‬53G1 ‫'م‬7N،aˆ1KF‫'مאšن‬7N
.AICi3H‫א\و‬F‫ل‬I‫د‬9‫א[و‬i‫د‬D‫א‬9‘‫و‬GH‫'م ض‬7f'RRb
g( ، $Q F :ƒ‫ و‬Sequential Workflow Console Application $Q$% ‫وع‬T3 z$ . ‫א‬W
:Q‫א‬$‫א‬KPTFV\‫א‬,,
: codeActivity1_ExecuteCodeE$L‫א‬U‫א‬3‫א‬0MN‫ و‬Code Activity ‫אج‬H‫'مد‬7N ‫אšن‬
C#
private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("***** First WPF Example *****\n\n");
Console.ForegroundColor = ConsoleColor.White;
}
‫ﻛﻮد‬
505
‫ﻛﻮد‬
VB
Private Sub codeActivity1_ExecuteCode(ByVal sender As Object, ByVal e As EventArgs)
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("***** First WPF Example *****" & Chr(10) & "" & Chr(10) & "")
Console.ForegroundColor = ConsoleColor.White
End Sub
While GR.‫א‬W،RRbH‫و‬3F‫ل‬I‫ د‬9‫א‬gN3‫אœوج‬Q9QH‫א‬P7!s‫א‬S‫א‬i'1œ‫א‬
:nDzN3‫א‬:N3‫ج‬+W‫ א‬Condition ‫אل‬$Q$R‫'م‬7N‫و‬،Loop
‫و‬C o.' false $‫ و‬Loop K 03 gjD$‫ א‬Q r Boolean 71N3 F7 ‫ 'د‬function ‫ دא‬ .H‫א‬F true
.bIBˆQ5D‫ א‬declarative rule condition nD zN‫ אو‬$F!‫אل‬p‫א‬i‫د‬D9œ‫א‬FŽ‫א‬U True N$t‫ وא‬AskAgain ‫ دא‬fN‫א‬WSN^3U
.RRV‫אא‬FP‫'ل‬b'‫א‬U false N
H‫א\و‬FPbIoQ$−‫א‬KPT Condition ‫ط‬T‫א‬U‫א‬$‫ אא‬G‫אŽא‬,T‫א‬53‫א‬W
- :9
ً ‫אو‬
:‫א‬$‫و'د א‬
C#
public string Password { get; set; }
private void AskAgain(object sender, ConditionalEventArgs e)
{
Console.Write("Enter Password: ");
Password = Console.ReadLine();
if (Password == "Ahmed Gamal")
‫ﻛﻮد‬
506
e.Result = false;
else
e.Result = true;
}
VB
Public Property Password() As String
Get
End Get
Set
End Set
End Property
Private Sub AskAgain(ByVal sender As Object, ByVal e As ConditionalEventArgs)
Console.Write("Enter Password: ")
Password = Console.ReadLine()
If Password = "Ahmed Gamal" Then
e.Result = False
Else
e.Result = True
End If
End Sub
‫ﻛﻮد‬
This FDg!،RRbH‫و‬3F‫ل‬I‫ אد‬Q_'F! Activity !s‫א‬Si
I‫א‬N'1I‫אšن‬
:g!‫'د‬P‫אא‬WS0s‫ و‬Activity GR .‫א‬W،Password is Wrong
C#
private void codeActivity2_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("This Password is Wrong...");
}
‫ﻛﻮد‬
‫ﻛﻮد‬
VB
Private Sub codeActivity2_ExecuteCode(ByVal sender As Object, ByVal e As EventArgs)
Console.WriteLine("This Password is Wrong...")
End Sub
:‫א‬KPT Sequential WF KK3P‫א‬KPT‫'نא‬P‫א‬WPS
507
:2jN‫ א‬,,‫و‬
a‫'ل‬I‫ (مد‬U‫ل‬L‫' א‬SFً‫א‬$%$73‫'ل‬I‫(مد‬nD:715P> WF ‫אאل‬WSK^3‫אن‬ª9***
KgUً‫^
א‬$OQ3'S‫و‬Rs‫وא‬3‫א‬iH'V‫א‬5P،FgN3KP‫'د‬P‫ א‬hQ')f I‫א‬03KPk‫@א‬O،
. Debug ‫ وאل‬trace ‫אل‬hF!s‫'دא‬P‫א‬hQ') g!‫و‬iz‫א‬.
WF Code Liabrary
.3
a7!@‫ و‬Windows Forms 03‫و‬C ASP.net 03KF‫א‬:NP> WF zT‫א‬NP3b‫א‬D'N‫א‬lWSU
.IŠˆ1‫א‬Ug3‫א‬$+‫‹א‬53‫ و‬.dll o3„‘gQ' ،Console
508
‫‪509‬‬
‫اﻟﺒﺎب‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‪WCF‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‪20‬‬
510
511
h71g%'3i$Q$%N7g¦‫ذ‬XP‫א‬013U .net_DUi$Q$Ž‫א‬hN7Ns‫ لאא‬I53
ً‫א‬z$i$Q$Ž‫א‬hN7‫אل‬$‫א‬gCًNFs‫وذ‬،:! I‫و‬D‫א\'ز‬h71‫وא‬ChPT‫א‬nDKFt‫א‬
.Sockets~zg‫وא‬Winsock53
.Q‫א‬$‫א‬WN3Web Services_DnDQi(ˆNWCF_z$‫א‬K.‫و‬
Web Service
.1
K nD ‫و‬C  .net 23‫ א‬5D iHD S Web Service ‫ א‬gD ˆ1Q 3 ‫و‬C GQ‫ و‬h3$I ً j$3
Interface €‫אمو‬$+9‫א‬g%‫وא‬Sg%‫'א‬NS‫'د‬V7\‫)א‬g%‫ وא‬k@gNP‫ و‬ASP.net g!$Q$R‫א‬
G`Q ‹ Request G‫و‬C3CˆQ،Y3 Interface 1‫'א‬k‫'ل‬b'‫'نא‬3$+\‫ א‬01Q‫( و‬
23‫א‬4‫א‬YQ 3gFgO‫و‬CgFgOQ ‫ن‬C53pt‫وא‬XML ¿ Q3nDً‫دא‬FD‫ א‬http protocol ˆQ5Dk
.3€Z–‫א‬0.‫'א‬3‫و‬ig%‫وא‬
235DiHDGQ‫و‬3$+!، AIC7Q1‫'ع‬s'\‫א‬gO‫ولאن‬RN‫و‬3$7\‫אˆوא‬oQ‫א‬nNN‫وאšن‬
، h3'\‫ א‬lWg 3$œ‫ א‬:D ‫ ‹ د‬53‫ و‬:N3 h3'\‫ ™ א‬G‫ و‬:‫دא‬N} ‫م‬$+\‫'م א‬7Q g%‫ون وא‬$
N3NQ$3U@71‫א‬gN3G1،@71bœ‫א‬GQ‫و‬h3$I SWh71‫א‬g,C53$‫ووא‬
nD i‫'د‬%'3 ‫'ن‬P gC „‘ !s‫אم א‬$+‫ א‬g%‫ وא‬k ‫'ن‬PQ ‫ن‬C ‫ ذ‬K‫ و‬، ً ^3 iH‫א‬L‫ א‬%H$ ‫'د‬
.€Z–‫א‬
53‫א‬0BU23‫א‬4‫א‬0B‫ن‬CcQ3 ،h‫א‬K^FHF XML nD$FGQ‫و‬h3$+!NOCF‫و‬
.4‫א‬q‫و‬CKqT‫(مא‬5D (N‫™א‬qgFg!‫و‬g3K3‫א‬nDiH‫د‬.
‫'ع‬N‫אא‬WSD$Q‫ن‬C$9€Z–‫א‬nDgOMW‫!¦نא
!א‬، ً 7NOCF23‫א‬h3$œ‫نא‬C}‫و‬
23KFR €F.C53$]!V+T‫א‬¤‫ز‬g%nDbœ‫א‬3$IX{‫ن‬Ch‫د‬HC‫ و‘ذא‬،4‫א‬53
.^C‫ و‬Windows 2000 €!'‫و‬PQ353z‫א‬$‫א‬53IIS
512
.net ‫ ﺧﺎﺻﺔ ﺑﻚ ﻣﻦ ﺧﻼل‬Web Service ‫ﻋﻤﻞ‬
.1.1
%H‫ )د‬i$‫ و‬53 iH‫א‬L‫ א‬%H‫ د‬gj1D ‫'م‬7 Web Service KF ‫'م‬7 f' 0Q‫س א‬H$‫א א‬WS U
:S3‫وא\دא‬،(Q'J3%H‫)د‬i$‫‘„و‬gQ'R‫'م‬7(€Qgg!
result=(input-32) * 5/9
U k ً ƒ‫ א‬ZI‫ وא‬، ASP.net Web Service ZI‫ وא‬New Project $Q$% ‫وع‬T3 HI . z$‫و‬
:ً ^3،V+T‫ א‬nDg{QPlocalhost
http://localhost/ConvertWebService
$` F ، ASP.net U F ً 3e Web Config o3 gN3 hO\‫ ™ א‬zT 'Q‫'م !`'אل 'د‬7
. Service1.asmx ]TNf'!j‫א‬hROV‫א‬3CGlobal.asax
9 ‫א‬W ، ‫ אœص‬WebService‫'ل ‘„ אل‬b'‫ א‬g Q t‫ א‬7Q1‫ א‬S Service1 9‫'ن א‬P ً 79
..ً ^3 ConvertWS5P‫و‬GN3‫‘„א‬S
qnN
Web ‫ن‬C @N 9 5P ، 7‫ˆ א\د א‬1 . .net ‫אم‬$+ ˆ1 C 4 ‫'م‬7 F ً 3e ‫وאšن‬
.ً ^3 TextBox j3h‫دوא‬CnD'9C$9Service
:ً ^3 VB.net ‫א‬KPT‫!'د‬s.‫א‬W‫و‬
C#
‫ﻛﻮد‬
<Webmethod(Description:="iH‫א‬L‫א‬h%H‫د‬KQ'F‫^ل‬3">
public decimal Convert(decimal degree)
{
result = (degree - 32) * 5 / 9;
return result;
}
VB
‫ﻛﻮد‬
<Webmethod(Description:="iH‫א‬L‫א‬h%H‫د‬KQ'F‫^ل‬3">
Function Convert(ByVal degree As Decimal) As Decimal
result=(degree-32) * 5/9
Return result
End Function
.¤‫ز‬g%nDً‫'دא‬%'3 IIS ‫'ن‬PQ‫ن‬C@N9‫و‬،3$œ‫א‬lWSˆ1X`N‫وאšن‬
513
:‫א‬1‫א‬P.‫ و‬Internet Explorer 5P‫و‬OV\‫א‬O.
http://localhost/ConvertWebService/ConvertSW.asmx
.RRbiH'VKFg'53$]‫وא‬bœ‫א‬3$œ‫אšن{א‬01
‫ز‬g%nD3$œ‫`א‬a7!‫م‬$+7Q1‫א‬lWS‘‫ و‬،KPT‫אא‬Wg3$œ‫אمא‬$+‫א‬Q5!0.‫א'א‬U‫و‬
.izOPKF gC53$]‫موא‬$+\‫א‬
:`‫א‬K nDgN3W،GQ'‫א‬3$œ*jVœ‫א‬53‫د‬$D0s‫و‬U Webmethod ‫אم‬$+‫א‬Q
،‫م‬$+F‫ل‬H9‫א‬K. buffering KFD‫‘ذאن‬F!‫د‬$bœ‫א‬lWS‫و‬: BufferResponse −1
. False ‫و‬C True F.k‫و‬
‫د‬$‫^و‬F.HF.WI]‫ و‬Cash KFD: I53QW‫€א‬.'‫دא‬$S‫و‬: CacheDuration −2
.$Q$%
53
h‫א‬
‫ل‬H‫א‬
i‫د‬D‫א‬
K.
‫ق‬q\‫א‬
€.'‫א‬
.9‫م‬C Session bIKO”‫‘ذא‬F! ‫د‬$:EnableSession−3
‫ ﺧﺎﺻﺔ ﺑﻚ ﻓﻲ ﻣﺸﺮوﻋﺎﺗﻚ اﻟﻔﻌﻠﻴﺔ‬WebService ‫اﺳﺘﺨﺪام‬
.1.2
Web Service ‫م‬$+‫ن‬C$Q‫و‬،L‫א‬hFً ^323UGQ‫و‬3$I53i‫د‬O9‫ א‬$QNC‫ض‬ZON
–‫ א‬: ‫ ن‬W‫ وא‬Q'J3 %H‫€ ‘„ د‬Qgg! 53 KQ'R ‫'م‬7Q W‫س אˆ وא‬H$‫ א‬U : NF. W‫א‬
.ConvertSW
. Add Web RefernceZI‫ א‬Project Fj.53‫ و‬،‫د‬D‫وز‬$NQ‫ˆو‬1zT‫אšن‬.
3$+‫ و‬، ˆ‫س א‬H$‫ א‬U :4 NF. W‫ א‬ConvertSW.asmx HI . H‫ 'א‬03 g(
.3$œ‫א‬lWSgQ't‫وאلא‬$‫*وא‬jVœ‫ضא‬D! Viusal Studio 53!s‫א‬
:‫'د‬P‫ ً ‘„א‬QK7N‫وאšن‬
C#
LocalHost.ConvertSW conv = new LocalHost.ConvertSW();
‫ﻛﻮد‬
514
VB
Dim conv As New LocalHost.ConvertSW()
‫ﻛﻮد‬
P (N‫ אول و‬U iH‫א‬L‫ א‬%H‫ل د‬I‫'م د‬7 C Label1 ‫ و‬Textbox1 0s' ً ^3 . ‫وאšن‬
، conv €P´‫אو‬oQ ‫אˆאœص‬3‫א‬nD'dF‫א‬lWkK3P‫'دא‬P‫א‬،^‫א‬U‫ض‬
:‫א‬1!s‫א‬
C#
Label1.Text = Convert.toString(conv.Convert(textBox1.text));
‫ﻛﻮد‬
VB
Label1.Text = Convert.toString(conv.Convert(textBox1.text))
‫ﻛﻮد‬
‫ﻣﻼﺣﻈﺔ‬
g3$+Q W‫א‬234‫א‬U.،3$œ‫א‬UKQ$KF€F.‫'א‘ذא‬S‫س‬H$‫א‬lWSzg‫א‬K. I‫א‬:N‫א‬
Update Web HI‫ ‹ א‬53‫ و‬5>‫ א\وس א‬H gD aqM‫ˆ א‬Q 5D k Update Q$ KF
.Reference
‫اﺳﺘﺨﺪام ﺧﺪﻣﺎت اﻹﻧﺘﺮﻧﺖ اﻟﺠﺎﻫﺰة‬
.1.3
R‫ א‬$‫و‬،€Z–‫א‬nDi‫'د‬%'\‫ א‬Web Service ‫אل‬h3$I$C‫م‬$+Q‫وع‬T3KF‫'مאšن‬7 f'
: h3$œ‫م™א‬$7QW‫אא‬0.'\‫א‬nDh^D
‫رابط‬
http://www.webservicex.net/WCF/
: S‫و‬gN3i$‫وא‬HI€F.،3$I70‫ 'א‬nD0.'\‫אא‬WS'd
‫رابط‬
http://www.webservicex.net/ValidateEmail.asmx
‫م‬$7t‫א‬hT‫ א‬UK>9‫אא‬WS5DR‫و‬9‫م‬CKPT‫אא‬WgK>‫א‬¤NS‫‘ذאن‬F!3$œ‫א‬lWS 4§‫و‬
. False ‫ אو‬True F7‫ و'د‬: IsValidEmail gƒ‫ˆدאא‬Q5D‫وذ‬،‫و‬ZP–‫א‬$Q4‫א‬h3$I
515
‫'م‬7N‹53‫و‬،ً7:!sNF.W‫א‬H\‫وع‬TF$Q$% Web Refernce !s‫'م‬7،$D‫א‬F‫وאšن‬
*03 ‫'م‬7f'W‫و‬،'g3$œ‫א‬lWS03K3‫مא‬$+F5P>r‫م‬H'O‫א‬nD H ‫ض‬D ‹ 53‫ط و‬T‫ א‬F. HI‫ א‬Q r 3C H‫ ‹ ز‬53‫ و‬، ‫و‬ZP–‫ א‬$Q4‫ل א‬I‫ אد‬:! Q
.K>9‫א‬g!MessageBox
:'S3‫א‬H‫ز‬U:s‫ و‬W‫'دא‬P‫א‬
C#
net.webservicex.www.ValidateEmail x = new
WindowsApplication1.net.webservicex.www.ValidateEmail();
bool r = x.IsValidEmail(textBox1.Text);
if (r)
MessageBox.Show("RbK>‫;)" א‬
‫ﻛﻮد‬
else
MessageBox.Show("±IK>‫;)" א‬
VB
Dim x As net.webservicex.www.ValidateEmail = New
WindowsApplication1.net.webservicex.www.ValidateEmail()
Dim r As Boolean = x.IsValidEmail(textBox1.Text)
If r Then
MessageBox.Show("RbK>‫)" א‬
‫ﻛﻮد‬
Else
MessageBox.Show("±IK>‫)" א‬
End If
S‫ و‬، ‫אم‬$+9‫ א‬j,‫ \ ( و‬iQ$% AIC 3$I h$%‫ و‬0.'\‫א א‬WS U R‫ א‬U H‫א‬F‫ א‬03
:NS3$œ‫א‬${،:! I‫žو‬N\‫@وא‬71‫א‬nDfbœ‫א‬
‫رابط‬
http://www.webservicex.net/globalweather.asmx
‫اﻟﻤﺜﺎل اﻷول ﻻﺳﺘﺨﺪام ﻫﺬه اﻟﺨﺪﻣﺔ ﻫﻲ ﻣﻌﺮﻓﺔ اﻟﻤﺪن اﻟﻤﻮﺟﻮدة ﻓﻲ دوﻟﺔ ﻣﻌﻴﻨﺔ‬
:‫ﻼ ﻫﺬا اﻟﻜﻮد‬
ً ‫ ﻣﺜ‬، GetCitiesByCountry ‫ﺑﺎﺳﺘﺨﺪام‬
C#
‫ﻛﻮد‬
516
net.webservicex.www1.GlobalWeather m = new
WindowsApplication1.net.webservicex.www1.GlobalWeather();
MessageBox.Show(m.GetCitiesByCountry("Egypt"));
VB
MessageBox.Show(“Welcome”)
Dim m As net.webservicex.www1.GlobalWeather = New
WindowsApplication1.net.webservicex.www1.GlobalWeather()
MessageBox.Show(m.GetCitiesByCountry("Egypt"))
‫ﻛﻮد‬
‫ن‬$\‫! א‬3 $Q t‫ول א‬$‫ א‬X%‫ و‬TextBox KFD ‫ אšن‬X% ، V3 U A4P‫ن א‬$\‫ א‬zƒC N ‫ض‬Q
...kA4P‫א‬
‫ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬، GetWeather ‫اﻟﺪاﻟﺔ اﻷﺧﺮى ﻫﻲ ﻣﻌﺮﻓﺔ ﺣﺎﻟﺔ اﻟﻄﻘﺲ ﺑﺎﺳﺘﺨﺪام‬
:‫ﻼ‬
ً ‫ﻣﺜ‬
C#
‫ﻛﻮد‬
net.webservicex.www1.GlobalWeather m = new
WindowsApplication1.net.webservicex.www1.GlobalWeather();
MessageBox.Show(m.GetWeather("Asyut", "Egypt"));
VB
Dim m As net.webservicex.www1.GlobalWeather = New
WindowsApplication1.net.webservicex.www1.GlobalWeather()
MessageBox.Show(m.GetWeather("Asyut", "Egypt"))
‫ﻛﻮد‬
، \‫ א‬h Q'R 7\‫ א‬S €N‫ א‬nD i‫'د‬%'\‫ א‬h3$œ‫ א‬g,‫ن א‬C „‘ ,C ‫ن‬C 7 ‫وאšن‬
nD‫د‬FD9‫א‬53ً9$h F‫א‬KQ'RUg3‫א‬$+‫א‬NP> rًQH'!h3$œ‫א‬lWS.E$
.H‫א‬F
qt‫وא‬L‫ א‬h9‫א\د‬
N‫ א‬g3$7Q 3$I ‫אم‬$+ 234‫ˆ א‬Q 5D 0!$‫ وא‬¤'N ‫ل‬V9‫ א‬K^3 ‫ ًא‬$7 ^C h3$I ً MQC ¤NS
.:T3l{‫א‬U
gNPQ' V.S‫و‬.:! I‫و‬
،@71‫א‬nDf‫א‬3$IS‫و‬iTN3 AIC3$I،:T3 l{‫א‬U
S‫ و‬RSS 3$I¤NSًMQC
T‫א‬53 ISPN h3'3nDf‫'א‬S‫و‬IŠ‫'ع‬،:! I‫نو‬P‫ وא‬F‫ولوאوא‬$‫*א‬jVI‫و‬،žN\‫א‬
517
h7‫ وא‬h Q'R‫ א‬53 1• 3 KP GQ‫ و‬h3$I $` ً MQC ، 23‫א‬4‫ ™ א‬U ¤$OQ $. .!‫א\و‬
wcf‫ﻣﻘﺪﻣﺔ إﻟﻰ‬
.2
Windows Communication N7 € .NET 3.0 H'g& €‫ وא‬t‫ א‬i$Q$Ž‫ א‬hN7‫ א‬53 i$‫وא‬
‫لوאل‬V9‫§*_א‬t‫ א‬API's ‫وאل‬$‫א‬53D'FS‫و‬، WCF ‫ ًא‬HVI‫א‬k3Qt‫ وא‬Foundation
.:! I‫ و‬remote access ‫وאل‬web services
n y ‫ و‬x 5Q‫ز‬g%nDY YG+‫א‬O'SNSK—T‫א‬Nq,‫'ن‬P‫و‬gNDE$Rt‫א‬17N‫א‬
23‫ وא‬$ 5D ig% ‫'ل‬b'‫ وא‬hPT‫ א‬nD h71‫ א‬KF F‫ א‬lWS N F r x=y U
.L‫€א‬Z–‫א‬VDet‫א‬h71‫א‬53‡‫ א‬... hO\‫א‬K7‫א[د‹و‬
h!‫ و‬، D'N‫ א‬lWS 53 23‫ א‬Q'1 U 234F FD$ hg& t‫ א‬hN7‫ א‬53 ^P‫ א‬¤NS
، MSMQ ، DCOM K^3،:! I‫و‬hPT‫א‬hFbœ‫ א‬API's ‫אل‬03K3‫א‬Kg‫'ل‬L‫ א‬53D'F
ًMQ‫א‬¤NS،hF‫א‬lWS K^}bœ‫ א‬System.Runtime.Remoting JO‫א‬Q$7” .net N7H'g&03‫و‬
‫و‘ن‬،ً‫א‬$%i
iH'VD‫'ز‬3(KFDhFD Kg53hN7‫א‬lWSNPe، XML Web Services N7
K730‫وאو‬4‫א‬h‫א‬HInDH'^‫وא‬i‫د‬Q‫*ز‬V+‫א‬NPF!‫ אم‬A'\‫אא‬WSUKF‫א‬UG—9€N
Yً!g,9‫א‬S‫ و‬Named Pipes, Sockets, and P2P ‫אم‬$+‫ˆא‬Q5D$7‫ א‬U1i‫د‬Q‫ز‬
53
^P‫ '!א‬g‫ — א‬- 7‫ א‬hN7‫ א‬ig, ‫م‬$ ‫ א ( ًא‬NN‫ و‬U K.‫ א‬nD .net ‫ אل‬Y3$+3
- .‫^ل‬Fˆ‫سא‬H$‫א‬53z$‫א‬NP>،ً!€.'‫א‬
.N7‫א‬lWSnDf C$N‫دم‬7‫سא‬H$‫א‬U، WCF _DK. .net 234FiL‫א‬lWS€
WCF ‫اﻟﺒﺪاﻳﺔ ﻣﻊ‬
.2.1
KPT WCF Service Library ‹ WCF ‫وع‬T\‫'عא‬HI.، Visual Studio 2008KqT$
:ً ^3‫א‬
518
¤NS،ًs‫א‬Z!‫ א‬WWF N7‫و‬C RSS 3$I03g71 NP>r WCF g3$7AICh‫א‬HI¤NS
.‫אšن‬ND's'3'S‫א‬WS@5P‫ و‬WCF Service${$Q$% Web Site zT‫א‬h‫א‬HI‫א‬5FsًMQ‫א‬
:S assembly hO3E ‹zTًs‫א‬Z!‫€א‬F.$.O${‫אšن‬
WCF Service−
WCF Service host−
WCF client−
:‫א‬E ^‫א‬h3'\‫'א!א‬53$9a‫و‬
.:‫ل‬V9‫א‬QW‫'אنא‬N‫دא‬$d'S:Address−
.a‫قא‬:Binding−
. WCF ‫ ل‬I53SWONQt‫مא‬g\‫א‬ob:Contract−
Address ‫ﺷﻜﻞ وﻣﺤﺘﻮﻳﺎت ال‬
.2.2
:‫א‬3‫א‬qV‫ א‬:،:KVW‫'אنא‬N‫א‬S WCF h3'353„‫אو‬17N‫א‬
scheme://<MachineName>[:Port]/Path
519
i‫'د‬%'\‫א‬h9''‫و‬4‫א‬Y3: I53KFf'W‫و''لא‬4‫دא‬$ scheme ‫ن‬C Path ‫
ًא‬IC‫و‬،: I 53‫ل‬V9‫א‬W‫א‬WON\‫'א‬S Port :KVW‫نא‬P\‫دא‬$.MachineName
.:‫ل‬V9‫'دא‬W‫زא‬gŽ‫א‬U Services ‫אل‬H3'S‫و‬
:‫א\^ل‬KnD‫א‬WS
net.tcp://localhost:8080/MyWCFService
:‫ﺗﺠﺮﺑﺔ ﺑﺴﻴﻄﺔ‬
: IService1.csU‫א‬$oQ!s.SzT‫א‬$،i$Q$% WCF Liabrary zT .
C#
[OperationContract]
int Add(int x, int y);
‫ﻛﻮد‬
VB
<OperationContract()> _
Private Function Add(ByVal x As Integer, ByVal y As Integer) As Integer
End Function
‫ﻛﻮد‬
:‫אא‬$‫א‬P. Service1.cs U‹53‫و‬
C#
public int Add(int x, int y)
{
return x + y;
}
‫ﻛﻮد‬
VB
Public Function Add(ByVal x As Integer, ByVal y As Integer) As Integer
Return x + y
End Function
‫ﻛﻮد‬
. YF.H $ ، ً ^3 ‫ א‬KPT WCF Test Client ‫ ل‬I 53 g` .‫ و‬Run KF . ، a7!‫و‬
.KL‫ `א‬Invoke nDaqM
‫ ؟‬Web Services ‫سאˆ'ل‬H$‫א‬53
^PKgC‫א‬WS@C
520
:YN7‫א‬YSY€!'‫و‬PQ30.'353H7\‫א‬lWSK7]K،a7!‫א‬WS@
:‫א‬a‫אא‬4DgD‫א– ع‬NP>H7\‫א‬:%‫و‬C!‫€'دאאض‬N‫‘ذא‬
‫رابط‬
http://msdn.microsoft.com/en-us/library/bb310550.aspx
‫‪521‬‬
‫اﻟﺒﺎب‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫ﻧﻘﺎط ﻣﺘﻘﺪﻣﺔ‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‪21‬‬
522
523
0.‫א\'א‬Q'1_D„‘‫ل‬7–‫א‬K.‫وس‬H$‫ ل
א‬Igs_t‫!א‬s–‫طא‬7N‫™א‬Q'NS‫ض‬
Debug - ‫ اﻟﺘﻨﻘﻴﺢ‬.1
W‫نא‬P\‫!א‬3nDً‫א‬H‫د‬.‫'ن‬P9،CHGTz1ICi$DًCg(234‫א‬nDFDzN‹C
i$j!hg&NS53،g.'€Nt‫א‬F7‫א‬5DO†
q3F.i]`!${C‫و‬C،ً‫א‬$Q$]1œ‫א‬:N3g&
.KM!CiH'Vj1IC0Debug‫אل‬
: BreakPoints
Visual ‫ ‘„ אل‬¤$Q‫ و‬g‘ ‫'ل‬b'‫ א‬H'! WON‫ א‬o.'Q r ‫'د‬P‫ א‬53 N3 53C nD gs‫ و‬Q ‫ط‬7
fNJ‫א‬i‫د‬D‫א‬NP>،KT\‫א‬53S'I53$]‫وא‬gs‫وאא‬h‫
א‬q\‫א‬..‫א‬3NP>،Studio
.F5nDaqMQgNWON‫א‬b‫'א‬3‫و‬CF11nDaqM11WON‫א‬
: ^3‫א‬KPT‫'د‬P‫א‬G%nDaqM‫وא‬C،‫د‬$[‫א‬1‫א‬UF9nDaqMBreakPoint!s‫א‬NP>
F‫—אنא‬G2N‫'نא‬Pً3‫]دو‬%!‫א‬C9‘،hi$Diz‫א‬7‫'م‬7ˆ‫א‬N^3UAF،‫وאšن‬
‫؟؟؟‬PT\‫א‬S3AQ،i
7‫و‬%'3‫'ن‬P‫ن‬C$9h I$\‫א‬K‫אن‬.'‫—אن‬HXs
524
AI‫وא‬i'1œ‫א‬YK7N‫‹א‬53‫و‬234‫א‬KqTz$€F.‫و‬،.‫א‬F17N‫א‬lWS€s‫אو‬WSK%‫א‬53
.F11
lWSUgh‫
א‬q\‫א‬Q¯HNPF‫و‬،1‫אא‬WS„‘‫'ل‬b'‫€א‬.‫و‬o.'i,3‫'م‬7234‫אنא‬$`
:‫א‬KPTzN‹‫א‬
‫؟‬E$‫ذא‬3Ah‫'א‬1I6$،h‫'א‬1œ‫א‬UF‫אšنא‬
_
q\‫א‬،G„‘‫'ل‬RQ.‫א‬C$Q3$L.‫א‬KVQ3$NDً !،PT\‫א‬GK§UhC$‫אšنא‬lŠ
.‫א‬WS534‫ًא‬F.HGD'Q$Q
:X'1\‫א‬2N‫א‬nD‫'ل‬VL‫א‬NP3C‫و‬F‫€א‬g‫א‬...DoubleXM‫א‬FD2oQKL‫‘ذنא‬
525
ً‫א‬$7‫'و‬b^C‫'ع‬s'\‫'نא‬Pi
P‫א‬QHT3U، Debug‫אل‬FD53gN<t‫א‬i$jO‫א‬SlWS
.h‫אدوא‬lWSnD‫د‬FD9K^3‫א‬KL‫'نא‬P‫א‬W،‫دوאل‬i$DYh‫
א‬q\‫א‬..‫}ج\א‬H‫و‬
iW!$`:‘‫אج‬h$%‫و‬3f$k،h‫
א‬q\‫א‬.
q5P>\‫א‬lWSUK،a7!‫א‬WS@
:ً ^3‫א‬KPT
q
:‫א‬KPT.‫א‬3i‫'د‬%'\‫א‬hJO‫وא‬h‫
א‬q\‫א‬KًMQC
:‫א‬KPTAdd WatchbI.‫א‬3!s‫א‬HI‫א‬NPF!:N
q3.‫א‬3U€—H'‫و‬
526
:‫א‬KPTl$‫و‬:bI.‫א‬3iW!O‫'م‬7
‫ﺗﺠﻬﻴﺰ اﻟﺒﺮاﻣﺞ ﻟﻠﺘﻮزﻳﻊ‬
.2
9 $. ‫م‬$+\‫ز א‬g% ‫ و\ ن‬، ‫م‬$+\‫ ‘„ א‬g7N %r ‫ אšن‬5‰ ، N‫ א‬53 Ng‫ א‬$. ‫'ن‬P ‫ אن‬$
‫'م‬7 Setup KP, nD 234 Publish KF ‫'م אšن‬7 KF N 3‫ א ز‬h'P\‫ ! א‬nD 'd
.Build-PublishFj7‫א‬53‫ذ‬Q،i,3:qT‫م‬$+\‫א‬
.ً ^3C:\ahmed5P،:‘TN‫'دא‬W‫نא‬P\‫א‬$Q$R.Q‫א‬$−
.CD-DVDH+N،:N3234‫א‬+KFY3$+F‫'د‬W‫نא‬P\‫א‬$Q$R.‫א‬i'1œ‫א‬U−
.i'1œ‫א‬lWSKS{9‘‫و‬W7!Y3‫ن‬P3Uh^Q$R‫א‬5D234‫א‬RQ‫ن‬CUG—€N‫‘ذא‬−
.Finishaqs‫א‬−
527
ً ^3 ، Publish ‹ ‫وع‬T\‫ א‬h‫א‬HI ˆQ 5D h‫
א‬q‫ ™ א‬KFD NP> ، lg{ ” z, K $` −
.:! I‫و‬C!s‫א‬hO3YFM
Program FilesU234‫א‬KFQf'‫ و‬SetupnDaqM.،KFً‫א‬S%b‫ אšنא‬−
.‫ ًא‬$%‫د‬D234:3K3‫א‬NP>‫و‬
ًMQC ، setup factory ‫ و‬installshild K^3 ‫'ع‬s'\‫ א‬lWS K%C 53 ً 3$7 ^C h‫دوא‬C ‫אم‬$+‫ א‬NP> −
Fj7‫א‬53'Q‫`'אل'د‬O‫א‬U Setup‫אل‬hD‫و‬T3S!'t‫א‬3$7\‫*א‬jVœ‫א‬53i‫د‬O9‫א‬NP>
::! I‫و‬h.O9‫وא‬KFR‫א‬FDh,,‫
و‬UPR‫א‬nDً‫א‬H‫د‬.‫'ن‬PNew Project
528
C# vs Vb.net
.3
:T‫א‬:%‫و‬C‫و‬C‫ق‬H‫'א‬O‫א‬SF!، Vb.net‫ و‬C#tqnD‫'אز‬3KPT‫د‬FD‫א‬N‫و‬H‫د‬iZ!‫(€'אل‬9'
..net‫ قאل‬19Q‫א‬$‫א‬17„‘ً9‫و‬C$N.FgN
h‫ذא‬qe€!'‫و‬PQ3€\‫و‬،i$F\‫א‬q‫א‬S C#€ .net‫د¨אل‬3H'g&Q‫א‬$U
:g,Q‫'אز‬3qQ'1g43§9C€!'‫و‬PQ3hCH،‫!`'אل‬S‫€و‬.'‫ذא‬U0‫'قوא‬
+4 t‫ وא‬VB.net hz% NS 53 ، .net ‫د¨ אل‬3 ˆ1 gNP‫`'אل و‬O‫ א‬03 Syntex ‫ אل‬U
a7!P‫א‬X'‫א‬،>$7‫א‬q‫א‬Y‫و‬gN$'‫א‬:T‫'א‬S‫א‬WS‫و‬، VB‫אل‬X']5P‫ و‬C#‫אل‬53AIC
.9‘@
Fg!h! I9‫'دא‬SNSKg‫א‬،lzO‫א‬015!VB.net‫و‬C#Y:T‫א‬5DE$R‫א‬N‫א‘نو‬W‫و‬
...P‫א‬X'CUh.‫و‬O‫دא‬C$N،i$‫وא‬qQgN‫א‬U
529
1KIŠU‫؛‬0M‫ن‬C@N9XH,2343':ً9‫و‬C*
:h‫
א‬q\‫א‬oQ7Q:ً‹*
C#
int x;
ClassName x=new ClassName()
‫ﻛﻮد‬
VB
Dim X as Integer
Dim X as ClassName=new ClassName()
‫ﻛﻮد‬
53ً9$i‫مא\وא‬$=!3 ‫א‬$`F،==G‫א‬#CU3C=G‫א‬VB.netU‫وط‬T‫א‬U:ً^‹*
.<>
:ً ^3S
—‫و‬hJO‫وא‬h‫א‬z‫א‬%9‫א‬Ug3$+‫و‬EndK^3KBnDVB.netq$F:ً‫א‬H*
VB
if x=1 Then
End if
‫ﻛﻮد‬
:‫'אس‬.‫אمא‬$+#CUS${FN
C#
if(x==1)
{
}
‫ﻛﻮد‬
:ًMQCh‫א‬z‫א‬%9‫وא‬hJO‫א‬UW‫و‬
C#
using System
Namespace MyNameSpace
{
class HelloWorld
{
static void Main(string[] args)
{
System.Console.WriteLine("Hello
World")
‫ﻛﻮد‬
530
}
}
}
VB
Imports System
Namespace MyNameSpace
Class HelloWorld
'Entry point which delegates to C-style main
Private Function
Public Overloads Shared Sub Main()
Main(System.Environment.GetCommandLineArgs())
End Sub
Overloads Shared Sub Main(args() As String)
System.Console.WriteLine("Hello World")
End Sub 'Main
End Class 'HelloWorld
End Namespace 'MyNameSpace
‫ﻛﻮد‬
.!||&&‫م‬$+f'#CUFNAnd,Or,Not,OrElse‫م‬$+f'net.‫!`'אل‬U،ً3I*
.+‫م‬$+‫א‬#CU5P‫و‬VB.netU&‫م‬$+‫'صא‬VN‫א‬0B$ND:ً‫*د‬
VB.netUElseIfS#CUelse if:ً*
:ًMQC‫'אس‬.‫א‬nD#C$FQH‫א‬P‫א‬h7L‫א‬O!،End‫'ع‬s'3UNO‫א‬F:ًN3‹*
C#
for (i = 2; i < = 10; i += 2)
{
System.Console.WriteLine(i);
System.Console.WriteLine(i*10);
}
‫ﻛﻮد‬
:‫'אس‬.‫א‬5DzNq9‫א‬5P>$‫وא‬1g'U‫و‬
C#
for (i = 2; i < = 10; i += 2)
System.Console.WriteLine(i);
‫ﻛﻮد‬
:ً‫א‬$'3ً P,WI]g!VB.netU3C
531
VB
For c = 2 To 10 Step 2
System.Console.WriteLine(c)
Next
‫ﻛﻮد‬
.:! I‫و‬for each‫و‬WhileQH‫א‬P‫א‬h7L‫א‬.N3‫@א‬O‫و‬
.VB.netU()53ً9$[]‫'س‬7‫مא‬$+Q:! I‫و‬h!'OVFN:ً*
C#
int[] nums = {1, 2, 3};
for (int i = 0; i < nums.Length; i++)
Console.WriteLine(nums[i]);
‫ﻛﻮد‬
VB
Dim nums() As Integer = {1, 2, 3}
For i As Integer = 0 To nums.Length - 1
Console.WriteLine(nums(i))
Next
‫ﻛﻮد‬
nD XML CommentsW‫و‬، #CU/**/K^3 VB.netU153^ Commentً7${5*
.3‫د‬7‫א‬iH‫א‬$b9‫א‬U3'D$3‫'ن‬P$.g‫א‬hC.cC53—‫א‬
.F7‫א‬.nD‫'ل‬VRVB.netUMod53ً9$٪Q'J\‫א‬3 ‫مא‬$+f'#CU*
#C‫@אل‬PDnDAssignmentUBitwise Operations‫אم‬$+‫א‬VB.netD$5*
.‫ذ‬
h‫—
ذא‬h.‫!و‬S‫و‬،Q'qh.‫!و‬g'A$9h.‫و‬O‫א‬lWS‫ !¦ن‬−3€(9F −–K‫א‬5
‫وﻟﻜﻦ اﻵن ﻟﻨﺤﺎول اﺳﺘﻌﺮاض اﻟﻨﻘﺎط‬،‫س‬H$‫א‬QgU3gsa‫א‬HnD،i\F.
. ‫ﻏﻴﺮ ﺗﻠﻚ اﻟﻤﻬﺘﻤﺔ ﺑﺄﺳﻠﻮب اﻟﻜﺘﺎﺑﺔ‬
93'S‫ و‬ahmedgOS Ahmed‫ !¦ن‬VB.netU:C، case sensitiveSh.‫و‬O‫ولא‬C*
.GD‫م‬Ci3‫א‬WS‫‘ذאن‬F!‫د‬$C‫ن‬C01C9‫و‬،BasicA'_‫א‬UqCU$%'Q
:−HVI−VB.netUh‫Ÿא‬
.#CU‫'د‬%'3@‫و‬VB.netU‫'د‬%'3optional parameters‫אل‬D‫*د‬
.#CU‫'د‬%'3@‫و‬VB.netU‫'د‬%'3with*
532
z1I‫א‬iZOKM!Cً3(S‫و‬VB.netUi‫'د‬%'3Catch ... When*
UGDgNP‫و‬i
qV‫א‬h71‫א‬Ui3lWS‫و‬، BackGroundU‫'د‬P CompileKF VB.net‫'م‬7Q*
.'Q‫`'אل'د‬O‫א‬zaª i
P‫א‬h71‫א‬
:−HVI‫א‬−#CUh‫Ÿא‬
ً‫א‬z% @ :NP‫ و‬VB.net U ً MQC :3‫א‬$+‫ א‬NP> 3 'S‫ و‬، unsigned types fQ 3 #C D$Q *
.q‫א‬53ً‫א‬
3 unmaneged code‫و‬C unsafe‫אم‬$+vF‫א‬S VB.netU!'9t‫ وא‬#CUA'.‫א‬i\‫*א‬
image H'V‫Žא‬3K^3h9 i$DU‫ًوא‬.!ŠOQ3،:! I‫ و‬Pointers nDKF‫א‬Q
.:! I‫و‬processing
Low Level CodeA'\‫™א‬O+N3‫'د‬03g353++C53Q. #CK%Ÿi\‫א‬lWSK‫و‬
.5Q
^PK^3‫א‬HI9‫א‬XH,K®3'S‫و‬
:‫א‬KPT‫‘„'د‬1MVB.netUdecrement‫و‬increment${5*
VB
A=A+1
A-=1
‫ﻛﻮد‬
:‫א‬KPTW‫م‬7‫א‬NP>#CUFN
C#
A++
A—
‫ﻛﻮد‬
.VB.netUS${5FN#CUsizeofbœ‫א‬${‫ن‬CNP>*
F. h‫ € ذא‬g—C U g! €(9 F‫ و‬، ‫ ^
ًא‬g3 K3 t‫ وא‬h! I9‫ א‬s‫ ًא و‬%'3 ‫א‬WS ‫ن‬
.i
‫ ﻣﺎذا أﺧﺘﺎر ؟‬: ‫ﻓﻲ اﻟﻨﻬﺎﻳﺔ‬
‫ و‘ذא‬#CX! C/C++/JavaXi4IQ$€‫‘ذא‬3C VB.netX! VB 6.053ً 7N3€N‫‘ذא‬
.a7!V+,CC#,HC€N‫و‘ن‬NQ3HI‫א‬U€]!4‫لא‬Uً‫א‬$Q$%€N
533
:h.‫و‬OK3s'€!'‫و‬PQ30.'353o\‫אא‬WS
‫رابط‬
http://support.microsoft.com/kb/308470
Mono‫ﻣﻘﺪﻣﺔ إﻟﻰ‬
.4
‫אو!ن‬% ‹‫'ن‬n VM :D‫ن‬P3‫ א‬nDKF.g®W‫ وא‬VM nD$F!Ž‫_א‬DU
h‫Ÿא‬SC53‫ل‬KnD:NP‫אŽ!و‬WONUza‫'ع ™א‬s'\‫אא‬WSGQK7\‫א‬U،oQ‫و‬PQ3
.!Ž‫א‬
nDA'KF .
— MFC ‫و‬C C# ‫ و‬Visual Basic h`N3€ Microsoft _DK7\‫ א_א‬U‫و‬
.€!'‫و‬PQ353KqT‫(א‬
Mono 'SSg,C،i‫د‬$3KqT(nDKF‫א‬4Fh‫دوא‬C‫مق و‬$7”€.'‫א‬035P‫و‬
.L‫א‬NH‫'ع د‬s'3'S‫و‬
037!‫'א‬3gNP‫و‬، .net 2008037!‫'א‬3 €Rb‫ א‬Mono ‫]ن‬$OQH$V3$%C_(R‫א‬n0.‫א'א‬U
a‫وא‬Hi$Dh$%‫و—ذو‬،:! I‫و‬h$D‫'א‬.‫و‬C71 23‫وא‬C ASP.net KP,nDz‫'א‬.net 2.0
nD ‫'ل‬I$‫א‬NP>KnD،−g@−g7G—Cˆ1„‘k'b'$Oˆ!‫ 'א‬L‫א‬h9‫و‬RF
:HI9‫\א‬a‫אאא‬WS
‫رابط‬
http://www.mono-project.com/plans
‫ل‬G—t‫א‬hN7‫א‬HI.KFR‫א‬K‫א‬3‫ ل‬I‫و‬، Mono K Download KF .ˆ‫א‬0.'\‫א‬53
.g3KFMono
$`،23‫א‬4‫א‬Fj.Ul$` W‫ وא‬Mono ‫ אœصل‬Command Line ‫אل‬KqTS^‫א\א‬
:‫א‬h‫א\אدوא‬h‫אدوא‬5Fs53
534
XH,Q3' :mcs/gmcs
‫`'אل‬OQ3' :Vbnc
CILKQ3':ilasm/ilasm2
Visual Studio ‫ אل‬03 ً 7 K3 NF. F g3 K3‫ א‬Q - ‫^ل‬F XH, ‫ א‬− gN3 i$‫ وא‬K
i‫'د‬%'\‫א‬i$Q$Ž‫א‬hN7‫א‬D$Q gmcs ‫ن‬C'S mcs ‫ و‬gmcsY$'‫قא‬HO‫א‬،ً7Command Line
..net 2.0_D03
X‫ אœص‬Command Line ‫אل‬O. ،ً‫א‬$%‫د‬D C# ‫'د‬nD'd sample.cs o3‫ض‬ZON
‫א‬3‫א‬G‫‹א‬Mono
:
‫ﻛﻮد‬
gmcs /target:library /out:Sample.dll Sample.cs
!a7!‫و‬
4D gqT‫ ً و‬MQ‫ א‬exe ¤ build KFD NP> ، KqT ‫ א (م‬nD KF . P3 Q$ €Rb‫אšن א‬
...ً ^3@PNUmono
:VISUAL STUDIO‫אل‬nDF MonoDevelop ‫ل‬FD‫و‬T3!NP>@PN‫א‬nD
535
.net ‫ﺑﺮﻣﺠﺔ اﻷﺟﻬﺰة اﻟﻜﻔﻴﺔ ﻣﻦ ﺧﻼل‬
.5
ig%‫א‬S3،Q‫א‬$‫א‬K.5P‫و‬،'F[‫א‬ig%‫'א‬SGQ'‫א''ج_א‬K.3$7\‫א‬Ns‫'א‬3IŠ
‫؟‬Pocket PCOP‫א‬
KqT53gNP>Q‫دو‬HS„‘!s‫مא‬$73KqT‫אم(م‬$+F7N\‫א‬o‫'א‬k‫א‬ig%C53D'FS
Windows CE ‫(م‬N!s‫نא‬FKqT‫و(مא‬Windows MobileKqT‫א‬3(KPTQ‫و‬،‫(م‬N‫אא‬WS‫م‬g3
.OP‫א‬ig%‫א‬nDKFt‫א‬KqT‫(א‬g,C:.3‫و‬2003
536
gN3 ً M 5P ، H'gT\‫ א‬nN\ Hard Disk Q‫د د‬HS e 9 OP‫ א‬ig%! Q‫دو‬Hk‫ א‬$b nD 3C
‫'ع‬C ¤NS‫ و‬، ‫ز‬gŽ‫ א‬KqT i‫د‬D‫ א‬$ :D 53 h‫ א‬3 Q 9 Q‫د د‬Hg RAM ‫ אل‬53 z% ‫م‬$+Q
.:,3‫و‬KqT‫و(مא‬23‫א‬4‫א‬5Q+ROM‫م‬$+AIC
‫؟‬net.‫ ل‬I53Pocket PCOP‫א‬ig% :FDcNP>‫ذא‬3‫و‬
‫ن‬Cz‫م'א‬$+Fh3$Iˆ7R‫ز‬gŽ‫א‬53N3z‫א‬%C‫م‬$+23‫!א‬s‫א‬4‫א‬q‫ ل‬I5301
*• 3‫و ن א‬C ، h‫ א‬$D‫'א‬. 5Q§‫ و‬SWON‫ و‬23‫א‬4‫ א‬5Q+ (i‫א‬W‫אم א‬$+‫ )א‬a ‫אم‬$+‫א‬
.‫ز‬gŽ‫א‬U'V‫א‬ig%‫^ ًوא‬3‫
א‬3P‫אمא‬$+
‫؟‬C$Co
.3CH‫ز‬nDaqM‫א‬5DGHg(Q23KF‫'م‬7N،KP
.Visual Studio .net'Q‫`'אل'د‬O‫א‬KqT.−1
.k I534‫'دא‬t‫א‬q‫وא‬CVBHI.−2
‫و‬C Smartphone 2003 ‫و‬C Pocket PC 2003 HI . ‹ 53‫ و‬، Smart Device HI . −3
.:DKF‫'دא‬W‫زא‬gŽ‫א‬GWindows CE 5.0
.Device ApplicationHI.GN\‫א‬7‫א‬HI‫א‬$−4
:I‫دא‬U‫'د‬P‫אא‬WSP.‫و‬،h‫אدوא‬53ButtonGR.−5
C#
MessageBox.Show("Welcome...");
‫ﻛﻮد‬
VB
MessageBox.Show("Welcome...")
‫ﻛﻮد‬
HI.‫و‬C،:DKF‫'دא‬W‫زא‬gŽ‫א‬G:!G—W‫א‬deploy‫'عאل‬HI‫א‬F5nDaqM.−6
.a7!`PC~‫א‬nDKFQ‫'ع‬
9،i,3:qT‫زو‬gŽ‫ ‘„א‬exeWON‫א‬o\‫א‬K7ًMQCNP>،‫אول‬23KF€F.$7،¤‫و‬43−7
.Pocket PCOP‫زא‬gŽ‫א‬nDً‫'دא‬%'3net framework.‫'ن‬PQ‫אن‬L‫א‬lWSU$
‫ز‬gŽ‫א‬N03K3V+\‫א‬SQ$7‫א‬4‫א‬UgDh‫'د‬t‫مא–—
א‬g\‫א‬−8
:,T‫א‬g!G7N‫ن‬C5P>t‫א‬ig%‫א‬U,T‫א‬l{‫א‬$Q$Rً ^F!،:! I‫و‬
537
C#
SystemSettings.ScreenOrientation = ScreenOrientation.Angle90;
‫ﻛﻮد‬
VB
SystemSettings.ScreenOrientation = ScreenOrientation.Angle90
‫ﻛﻮد‬
:Touch KeyboardYPF‫و‬
C#
InputPanel1.Enabled = True;
‫ﻛﻮد‬
VB
InputPanel1.Enabled = True
‫ﻛﻮد‬
:coredll.dll‫א
אد‬$‫ز‬g`ResetKFً ^3‫و‬
‫ﻛﻮد‬
C#
private int CTL_CODE(int DeviceType, int Func, int Method, int Access)
{
return (DeviceType << 16) | (Access << 14) | (Func << 2) | Method;
}
private int ResetPocketPC()
{
const int FILE_DEVICE_HAL = 257;
const int METHOD_BUFFERED = 0;
const int FILE_ANY_ACCESS = 0;
int bytesReturned = 0;
int IOCTL_HAL_REBOOT;
IOCTL_HAL_REBOOT = CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED,
FILE_ANY_ACCESS);
return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0,
bytesReturned);
}
VB
Private Function CTL_CODE(ByVal DeviceType As Integer, ByVal Func As Integer,
ByVal Method As Integer, ByVal Access As Integer) As Integer
Return (DeviceType << 16) Or (Access << 14) Or (Func << 2) Or Method
‫ﻛﻮد‬
538
End Function
Private Function ResetPocketPC() As Integer
Const FILE_DEVICE_HAL As Integer = &H101
Const METHOD_BUFFERED As Integer = 0
Const FILE_ANY_ACCESS As Integer = 0
Dim bytesReturned As Integer = 0
Dim IOCTL_HAL_REBOOT As Integer
IOCTL_HAL_REBOOT = CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED,
FILE_ANY_ACCESS)
Return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0,
bytesReturned)
End Function
‫ ؟‬net. ‫ﻛﻴﻒ اﻛﻤﻞ اﻟﺒﺮﻣﺠﺔ ﻣﻦ ﺧﻼل‬
1M F! ، Pocket PC nD KFQ 234 NPF\‫ א‬£V‫ א‬aC 53 $Q 7‫ א‬23‫א‬4‫ !¦ن א‬$] KP
VN‫ א‬hO\‫אم א‬$+‫ א‬NP> h‫ א‬$D‫'א‬. 03 K3‫ وא‬Q$Ž‫ א‬23‫א‬4‫ א‬U 5Q+‫אم א‬$+9
.SQL Server CE‫'ع‬53h‫א‬$D‫'א‬.n‫و‬XMLhO3‫و‬C،h$D‫'א‬7
::N3z$€!'‫و‬PQ353a‫אאא‬WSnDi,3ًMQC‫'ل‬I$‫א‬NP>
‫رابط‬
http://msdn2.microsoft.com/en-us/library/aa458721.aspx
‫‪539‬‬
‫اﻟﺒﺎب‬
‫‬
‫‬
‫‬
‫‪22‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫اﻟﺒﺮﻣﺠﺔ ﺑﺎﺳﺘﺨﺪام ‪ASP.net‬‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
‫‬
540
‫ﻣﻘﺪﻣﺔ إﻟﻰ ﺗﻄﻮﻳﺮ اﻟﻤﻮاﻗﻊ‬
.1
lWS ‫ ل‬I‫ و‬، Desktop Applications ~‫ وא‬Console ‫_ אل‬D U E$R N ، ‫وس‬H$‫ א‬53 nM3 F!
nD $FQ 0s'‫ ن א‬$7! P, ‫'د‬%‫ و‬U n‫ و‬، WON $‫ز وא‬g% ‫'د‬%‫ و‬nD $F N K‫א\א‬
،NQCHF web serviceX‫ل‬V9‫אوא‬H‫د‬V\‫א‬UHT\‫ אوא‬5Q‫ز‬gŽ‫א‬Yh‫ل‬7‫لوא‬H‫א‬hFD
Q‫א‬$‫ א‬K.‫א‬W‫و‬،ًo†0s'!ً3'FD server side languages‫_אل‬D‫ אو‬ASP.net ‫_אل‬D033‫א‬
:€Z–‫א‬0.‫'א‬3‫א'אع‬nDf‫אن‬G‰
h, !‫و‬H'b‫אم‬$+‫ א‬5P>،HTML ‫אم‬$+hOb'‫א‬53D'F5DiHD0.‫א\'א‬lWS:‹0.‫'א‬3 .0.'\‫אא‬WSUŽ\‫א'אعא‬53‫א'ع‬$%'Q95P‫و‬:! I‫و‬
KF‫א‬G%UK(gNP‫™א'אع א\Žو‬0FQ0.‫א\'א‬53‫'ع‬N‫אא‬WS :KF‫א‬$NDP3NQ‫د‬0.'3 KF33‫א‬S‫א‬t‫א‬ROV‫א‬5P، VBScript ‫ و‬Java K^3 Scripts ‫אم‬$+‫א‬0.‫א\'א‬lWSUQ،a7!
.a7!€‫א‬¤$ND
‫אن‬5P>W‫ א‬2N‫א‬nDa7!€‫א‬KV‫א
!و‬U:Ž3KFDQ ‫'ع‬N‫אא‬WS :P3NQ‫ د‬0.‫'א‬3 .€Z‫א‬0.'3 @‫€و‬Z‫ˆא‬1nFQL‫א‬lWSU،^‫'عאولوא‬N‫א‬53‫'ن‬PQ
:‫ﻣﺜﺎل‬
!Ž‫ א‬3‫ ™ אوא‬nD ' ^‫'ع א‬N‫ א‬53 ROb S 33‫ א‬S‫ א‬t‫و א‬ZP9‫ א‬¤$Q ROb
lWg ROV‫ א‬lWS KPT ‫ !¦ن‬0.‫ א'א‬U 5P ، HTML 53 :! I‫'لو‬7L‫אول وא‬$Ž‫! ™ א‬s‫€ א‬QP
t‫אولא‬$Ž‫€א‬P,‫و‬h‫א‬$D‫'א‬.™ iz‫א‬7€3.t‫א
!א‬hFD™ˆQ5Dz%qV‫א‬
.:! I‫دو‬H‫א'א‬$Q4‫א‬nD'
i$ST301NP‫و‬،g !
‫€א‬et‫א‬q‫א'אدא‬Q¯HnD H‫د‬.
—€‫א‬ROV‫א‬lWSU‫א‬W
.a7!!
‫א‬nDŽ\‫א‬hFD‫אن‬a7!2jN‫א‬
:‫دورة ﺣﻴﺎة ﺗﻄﺒﻴﻖ اﻹﻧﺘﺮﻧﺖ‬
‫'م‬7Q http - ‫م و''ل‬$+ ‫ א‬cQ 3 'S‫ و‬http:// - X C$Q 3 0.'3 ‫'אن‬N I‫}`د אد‬
‫אאل‬WS‫'م‬7Q، DNS ً‫א‬HVI‫ وא‬Domain Name ServerXfQ3„‘‫'אن‬N‫א א‬WS‫ل‬H‫و''ل‬4‫א‬
541
KP,،0.'\‫ א‬Gb IP ‫صل‬I€Z–‫א‬nD Physical ‫'אن‬NgP€F.t‫א‬P‫א‬KQ'R DNS
:‫^ل‬F‫א‬KPT‫'ن‬PQ DNS ‫אل‬
G‫ل‬H‫א‬Q‫ و‬− 80‫'ن‬PQ3ً— port - !Q‫אšن‬،0.'\‫אא‬WkF\‫ א‬IP !3‫ن‬P39b‫אšنא‬
.http Request:Dˆ13'S‫و‬0.'\‫אא‬WS„‘Ž\‫א‬
Ž3Q dynamic ROV‫'نא‬U3‫א‬،a7!'1\‫ א‬ROV‫אد‬Q، static 0.'\‫'نא‬U
. http Response :Dˆ13'S‫مو‬$+\‫‘„א‬2jN‫א‬ROb‫ل‬H‫' وא‬1\‫א‬h‫א‬
‫ﻣﻼﺣﻈﺔ‬
a7! http 'SNS NFgQ3‫و‬،KFDiH‫دو‬K'‫و‬KP
: Client Side Web Sites ‫ﻣﻮاﻗﻊ اﻟﻌﻤﻴﻞ‬
DoV53K.‫ لא‬IgDf‫א‬NP>ً‫א‬$%gq S‫و‬، HTML X!3Q‫א‬$‫'ع‬N‫אא‬WS ‫م‬Q
:ً ^3a‫אאא‬WSˆQ5D
‫رابط‬
www.html4arab.com
‫دونא‬0.'\‫א‬KFDP3b‫א‬، Dream Waver Xzg‫ وא‬Front Page Xz‫א‬$‫א‬23‫א‬H'g&03‫و‬
.a7!h‫دوא‬9‫ˆא‬Q5D HTML ‫!ل‬3
W‫ א‬Forms ‫_אل‬D${ HTML ‫אل‬5FsًMQ‫א‬،*jVœ‫™א‬4 vbscript ‫ אو‬Java ‫ًجل‬MQ‫א‬
‫س‬H$‫א‬%‫א‬3NP>،‫'ع‬s'\‫אא‬WSU!\‫وج™א‬،%Hœ‫א_א‬03 Kb‫א'א‬53NPF
:−t‫و‬$353–vbscript~Q‫א‬$‫א‬
542
‫رابط‬
http://ahmedgamal-technical.blogspot.com/2008/08/vbscript.html
: javascript KQ‫א‬$‫سא‬H$‫وא‬
‫رابط‬
http://www.w3schools.com/JS/default.asp
...ً ‫אא¡ل‬WSU
^P‫א‬N3GC9،a7!h93‫א‬0.'‫وאšنא‬
: Web Service ‫ وﺧﺪﻣﺔ اﻟﻮﻳﺐ‬Web Application ‫اﻟﻔﺮق ﺑﻴﻦ ﺗﻄﺒﻴﻖ اﻟﻮﻳﺐ‬
bIiiH‫دو‬kt‫א‬h‫א‬$D‫'א‬.‫'אدو‬9‫א‬hO3‫ و‬hROV‫א‬53D'F5DiHD 'SGQ'‫ˆא‬1 :! I‫و‬E‫א‬$‫א‬WON‫و‬g. —‫وא‬gR! Q،23‫א‬K^3g^3
K3‫א‬Q،Ž\‫א‬hFD™$S$‫و‬h‫ ™א‬K73$I5DiHDg!GQ'‫א‬3$I3‫ א‬ .a7!hH'‫א‬.H‫و‬gƒ‫'ل‘„א‬b'‫א‬nDiH‫د‬. q‫א‬53g3
: IIS ‫اﻟـ‬
nDz‫ 'א‬ASP.net ‫אل‬¤‫'د‬KF‫طא‬,l‫'د‬%‫وو‬، ASP.net ‫ و‬ASP h4‫'א
!אœص‬S
.ً 79.'3:DoMW‫ א
!א‬nD‫و‬CV+T‫א‬¤‫ز‬g%
KFR€F.€]!.$‫ אو‬IIS ‫אل‬KFR€F.‫א‬cQ visual studio K setup KF€F.'
ً ^3 Notepad iPO\‫א‬nD4‫€'دא‬N‫‘ذא‬3‫א‬، IIS ‫אل‬KFTQ W‫ وא‬WebDev.WebServer.exe
Add 23‫!وאزאא‬s‫ א‬Control Panel - PR‫'א‬HI‫ˆא‬Q5D‫وذ‬،: setup KFD53$ !
53$` ، Add Windows Compomnent ‫وز‬$NQ‫و‬h'P3!s‫א‬ZI‫ وא‬And Remove Programmes
.−KqT‫(مא‬G7Q1‫
א‬q–IIS‫'אل‬S‫ و‬Internet Inforamtion Services gNFs
:‫ﺗﺠﺎرب ﺑﺴﻴﻄﺔ‬
543
:g!‫ א‬hQ'[‫א‬P.‹ً ^3 index.html ‫'ن‬PgF.،$Q$% Notepad O .
‫ﻛﻮد‬
<html>
<head>
<title>My First Pgae</title>
</head>
<body>
<center><img src="http://l.yimg.com/a/i/ww/beta/y3.gif"></centeR>
<br>
<font color=red size=3>Yahoo!</font>
<br>
<a href="http://www.yahoo.com">Link Here</a>
</body>
</html>
.€Z‫א‬ROb‫אول‬lWS،¤‫و‬43،gD‫א\دوج‬aqMi,3gqTX%
:h‫لא‬I‫د‬9‫مא‬H'O‫'مא‬7N‫אšن‬
:‫م‬H'O‫אא‬Wg‫'دאœص‬P‫א‬
‫ﻛﻮد‬
<html><head>
<title>My First Pgae</title>
</head>
<body>
<h2>Welcome !!</h2>
<br>
<form name="form1">
<table border=0>
<tr>
<td>
544
Name
</td>
<td>
<input type=text name=textname size=10>
</td></tr>
<tr>
<td>
Password
</td>
<td>
<input type=password name=textpass size=10>
</td></tr>
</table>
<br>
<input name="button1" type=button value="do anything"();">
&nbsp;&nbsp;&nbsp;
<input type=reset value="Clear">
</form>
</body></html>
Sg(f'!h‫ل‬I‫مد‬.' ،‫م‬H'O‫א‬Uh‫ل‬I‫مد‬.‫م‬$+\‫نא‬C53$]‫'م‬7‫אن‬$Q‫وאšن‬
:‫א‬KPTVl
q‫ و‬Button1 H GSWN‫א‬W،ًMQ‫א‬,T‫א‬nD‫و‬VHU:
‫ﻛﻮد‬
<input name="button1" type=button value="do anything" onClick="doCheck();">
:‫ א‬Script ‫אل‬P‫'م‬7f'ROV‫א‬IŠU‹53‫و‬
‫ﻛﻮد‬
<script language="javascript">
function doCheck()
{
if(form1.textname.value!="" || form1.textpass.value!="")
{
alert(form1.textname.value);
document.write(form1.textpass.value);
}
else
alert("enter data first !");
}
</script>
545
: Visual Studio ‫اﺳﺘﺨﺪام‬
‫`'אل‬O‫ א‬O . ، Visual Studio ‫ ل‬I 53 ASP.net ‫אم‬$+ 5P‫ و‬1‫ א` א‬lWS @O K7NN
: ASP.net Web Site ZI‫ ‹א‬Website $Q$%GQ‫و‬HI.‫'و‬Q‫'د‬
:Ž‫ א‬h‫دوא‬9‫א‬535P‫مو‬H'O‫@א‬O.‫אšن‬
‫‪546‬‬
‫‬
‫ﻣﻼﺣﻈﺔ‬
‫ال تنس اننا حتى اللحظة نتعامل مع ادوات ‪ HTML‬وليست ادوات ‪ASP.net‬‬
‫‬
‫و‪'73$ND‬م'‪0s‬א‪'P‬د‪aqM.،‬א\دوج‪ Button nD‬و‪P.‬אوא‪:i,3 3‬‬
547
:ROV‫א‬KO‫א‬GQ'‫ˆא‬Q5DFgN3i$‫ وא‬K‫אو‬Q'‫'د‬P‫وא‬FV‫אאضא‬NP>
. ASP.net 03K3C$N‫دم‬7‫سא‬H$‫ א‬U،1‫א‬N{SlWS€...a7!
ASP.net ‫ﻣﻘﺪﻣﺔ إﻟﻰ‬
.2
X`N‫س‬H$‫אא‬WSU،:DO —GQ‫و‬hRObKFD‫ و‬Visual Studio 03K3‫א‬N%ˆ‫א‬NH‫د‬U
.DO‫א‬0.‫א\'א‬03„‫אو‬N{
: ASP.net ‫ﺗﺠﺮﺑﺔ‬
H‫ ز‬U ، Button 3CH‫ وز‬Label ‫'אن‬ND i‫ وאدא‬TextBox * 03 . ، Standerd h‫ אدوא‬O .
:‫'دא‬P‫א‬P.3‫א‬
C#
Label1.Text= TextBox1.Text;
‫ﻛﻮد‬
548
VB
Label1.Text= TextBox1.Text
‫ﻛﻮد‬
. ASP.net ROb‫אول‬KF€F.$70.‫א'א‬U...X%‫و‬
‫ﻣﺎذا ﺣﺪث ﻓﻌﻠﻴ ًﺎ ؟‬
'S”3‫!¦ن‬0.‫א'א‬U،‫م‬H'!nD'd‫د‬D HTML ‫'د‬Q$ ‫ن‬C$` HTML ‫אل‬ROb€R!'
Ž3 €e!
‫א‬nD¤NS‫و‬،!
‫‘„א‬3‫م‬H'O‫א‬h‫ل‬H‫م‬.!
‫ ‘„ א‬Submit E‫و‬$
03A')‫ًن‬Q‫ אو א‬Ahmed A'[‫א‬nD'd Label nD't‫א‬ROV‫א‬i‫د‬D‫و”א‬h‫א‬
:‫'د‬P‫א‬53‫א‬zŽ‫א‬$`{N‫ א‬ROV‫ אœص‬HTML ‫'د‬P‫א‬i$ST3€%'،‫ل‬H9‫א‬K.*N‫א‬
‫ﻛﻮد‬
<p>
<span id="Label1">Ahmed</span>
</p>
<p>
<input name="TextBox1" type="text" value="Ahmed" id="TextBox1" />
</p>
<p>
<input type="submit" name="Button1" value="Button" id="Button1" />
</p>
.a7!!
‫א‬Ug!:! I‫'אدو‬9‫ א‬3‫א‬، Label1„‘2N‫א‬i‫د‬D‫و”א‬،h‫Žא‬3€e،‫ذ‬F
.‫اﻧﻮاع ارﺳﺎل اﻟﺒﻴﺎﻧﺎت‬
Q s‫א‬Z!9‫ א‬S‫ אو„ و‬7Q1‫ א‬U ، GET ‫ و‬POST S h‫ل א‬H9 Y7Q ¤NS Form C U
N ‫مאœص‬H'O‫א‬KQ$X%،OV\‫'אنא‬NDUkH‫ !א‬GETU3‫א‬،i,3 Form ‫אل‬h‫ل‬H‫א‬
:‫א‬KPTV
‫ﻛﻮد‬
<form id="form1" runat="server" method="get">
:‫א‬iH'V‫א‬ª9،AICi30.'\‫`א‬.
549
3C‫م‬H'O‫'لא‬nDً‫ودא‬$0MhROV\‫(א‬3ً،‫'אن‬N‫א‬U ‫م‬H'O‫א‬hQ')!‫ل‬H‫א‬Q،AF
.‫'د‬.‫א‬¤NS€! POST U
z,‫‘ن‬3‫د‬.h‫א‬3U:Df$.3'S‫و‬،‫'د‬PVON3gz‫א‬.h‫د‬H‫ 'א‬F!iz‫א‬.7QgN3i$‫وא‬KP
.„ ‫א‬
: Code Behind
U،FV‫א‬5D‫'د‬P‫ א‬KV!S>$7‫ א‬ASP 5D ASP.net 03hg&t‫א‬i$Q$Ž‫א‬h‫א‬F\‫א‬5Fs53
:ً ^3‫'د‬P‫א א‬WSA€N>$. ASP Classic ROb
‫ﻛﻮد‬
<%
v_Id = request.querystring("id")
response.write "<form action=test7.asp?id=" & v_id & " method=post>"
response.write("<font color=red><b><center>Write your
C.V.</center></b></font><br>")
%>
<table>
<tr><td>Computer Skills :</td><td>
<input type=text name=v_cs size=30></td></tr>
<tr><td>Characteristics :</td><td>
<input type=text name=v_char size=30></td></tr>
<tr><td>Interest's :</td><td>
550
<input type=text name= v_inter size=30></td></tr>
<tr><td>Language Skills :</td><td>
<input type=text name=v_ls size=30></td></tr>
<tr><td>Education :</td><td>
<textarea name=v_edu cols =30 rows=6>write your Study Field
here</textarea></td</tr>
<tr><td>Experince :</td><td>
<textarea name=v_exp cols =30 rows=6>write your Experiences
here</textarea></td</tr>
</table><br>
<hr width=75%>
<center>
<font color=red><b><center>Join Demand</center></b></font><br>
<textarea name=v_Join cols=40 rows=9 WRAP=physical></textarea><br><br>
<input type=submit value= Continue>
<input type=reset value=Erase>
</center>
</form>
‫אد‬$3‫ل‬N3o3 U FV‫א‬b‫א‬YU *.cs ‫אد‬$3o3U¤‫'אد‬C€Rb! ASP.net U3C
:*.aspx
ًMQ‫وא‬،‫^
ون‬P‫א‬gMOQ‫زאل‬37QS‫‘نא€ذو‬$‫ وא‬o3Ug‫د‬nDً‫א‬H‫د‬.€‫ز‬3‫و—ذ‬
.T\‫א‬0QHT\‫א‬Uًb'VI ASP ‫ ™א'אدאل‬aspx ‫אل‬o31‫ن‬9‫™ א‬U‫ج‬$.
X'‫א‬K(Q‫ —ذ‬5P‫و‬،234\‫א‬nD39‫א‬Kg‫و‬KI‫א‬$KFD‫م‬$Fbً !،‫'د‬P‫א‬zOI‫'صא‬Vx
:‫ط‬7i$G‫א‬i$‫وא‬RObUP‫א‬
U KFQ W‫* وא‬.cs - ROb ‫ ل‬I 53 gD KF‫ א‬01 9 t‫'אد א‬9‫ ™ א‬0s' ‫ ج‬3 ً C - .‫ذ‬¤H$Q‫אن‬01Q
‫وع‬T3
.Y4\‫א‬YK7N‫وא‬0Q‫א'ز‬UKg‫א‬Visual ‫—אن‬H−a7! $‫وא‬o3UKQ$‫א‬G1QK7‫א‬KQ$!،KQ$‫א‬UKg‫€א‬.'‫@א‬OU‫و‬ .
{ 5DFI‫و‬g.‫'א‬D‫אن‬9‘,\‫א‬KQ$‫א‬i3‫م‬$7QStudio
551
NH‫'ع د‬s'3'S‫ א™ و‬gM nD i$F3 hO3‫'د‬%‫م و‬$ Deploy ‫ אل‬FD U Kg‫ א‬S W‫ و‬.‫א‬
: ASP.net ‫ﻣﻜﻮﻧﺎت ﻣﺸﺮوع ال‬
hO\ !s‫' א‬d :‫ א‬$` ، OV\‫ א‬Y> nD ‫'د‬%'\‫ א‬Website Directory ‫ אل‬OV €F. '
:− gP7‫א‬zƒ9‫א‬lWg!i‫'د‬%'35P_'n−‫ א‬h‫א‬$¡‫א‬nDD‫و‬T3
.:P3‫א‬nDzNOV3K03K3‫و‬OV\‫*'عא‬N7t‫א‬hO\‫ א‬nD'd:App_Browsers
.GQ'‫א‬hROb*§t‫ א‬Classes hJO‫'אدوא‬9‫א‬hO3nD'd:App_Code
.h‫א‬$D‫'א‬.hO3nD'd:App_Data
. *.resx H‫د‬V\‫א‬hO3nD ':App_GlobalResources
.‫وع‬T\bœ‫א‬h Q‫ وא‬g(\ct‫א‬hO\‫א‬nD'd:App_Themes
g3$+Q Web Service‫ אل‬53 ‫ אو א 'ع‬Proxy ‫'د و‬%‫ و‬U : App_WebReferences
.NSgs‫و‬Q71
.Ug3‫א‬$+‫א‬Qt‫* وא‬.dll ‫אل‬hO3K^3iSŽ‫א‬hO\‫ א‬nD'd:Bin
:‫ دورة اﻟﺘﺮﺟﻤﺔ‬Compilation Cycle 53 7T3 ClassJ! „‘ :Q') K3P o\‫ א‬B Q ، Single File o\‫ 'ن א‬U
_aspx .‫!ل‬s‫א‬ROV‫@א‬OSystem.Web.UI.Page
552
23$5P‫و‬h‫'א‬1œ‫@א‬OKFD!، Code Behind KF‫ אœص‬Mode K3‫א‬$+‫ א‬U3C
،: Compile KFDQ InitializeComponent() ‫אل‬nD'dW‫א‬nF\‫א‬o\‫א‬،Q'hO3E ‹
.i,3 System.Web.UI.Page53@‫و‬:N3 CS + ASPX 53‫'ن‬P\‫א‬o\‫قא‬7,‫ًא‬79
…'7N3H'V‫***א‬
System.Web.UI.Page ‫اﻟﻔﺌﺔ‬
.3
:gN3،FDU¤$Ot‫א‬hJO‫*وא‬jVœ‫א‬53D'F nDJO‫א‬lWS'
ob'‫א‬
JO‫א‬
0.'\*•3‫ˆو‬1‫א‬h‫
א‬q303K3‫א‬
Application
0.'\‫אא‬Wg‫شאœص‬P‫א‬03K3
Cache
zNk Load KFDQ:‫مא‬C$Q$%53k Load KFDQROV‫א‬KS!\
IsPostBack
ROV‫א‬53€‹$ Submit FDnD
553
ً 79gDfN،Z\‫א‬ROV‫א‬$Q$
MasterPageFile
‫سא‬H$‫א‬UgDfN، Http Rquest ‫אل‬
Request
‫سא‬H$‫א‬UgDfN ، Http Response ‫אل‬
Response
HttpServerUtility5Fs!
‫ א‬03K3bœ‫وאلא‬$‫'ل‘„א‬b'‫א‬
Server
ً 79gDfN‫و‬7‫™א‬5Q+ ‫م‬$+، Session ‫אل‬03K3‫א‬
Session
ROV‫א‬lWg‫אœص‬−: BfD‫א‬9−^‫א‬$Q$R
Theme
Request ‫اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬
.3.1
gD01Qh‫لא‬H‫א‬FD،gD3Fg3WON!
‫‘„ א‬h‫ل‬H‫א‬FDS Request ‫אل‬FD
. Request ‫א‬
. Request Fg}‫'م‬7QH‫אא‬WS(‫ل‬H‫)א‬H‫ز‬nDaqM ‫'م‬7V+T‫א‬h‫لא‬I‫אد‬$:‫^ل‬3
‫ل‬H9‫א‬X'‫א‬$Q$QF، g‘h‫لא‬H‫א‬Qt‫א‬ROV‫א‬S‫ و‬Action ‫אل‬oQQ،i‫אد‬U
:ً ^3‫א‬KPT‫م‬H'O‫ א‬oQU‫ًوذ‬7SN,t‫ א‬Post ‫و‬CGet
‫ﻛﻮد‬
<form name="form1" id="form1" action="Process.asp" method = "GET">
...
</form>
:ً .O†7Q1‫م‬H'O‫א‬oQQ5P‫و‬،ًMQ‫(مא‬N‫@א‬O .net U
‫ﻛﻮد‬
<form id="form1" runat="server">
. POST Ss‫א‬Z!9‫لא‬H9‫ א‬7Q‫אن‬FROV‫@א‬OSg!‫'د‬t‫א‬ROV‫ًאنא‬s‫א‬Z!‫א‬cQ‫א‬WS
5Fs bœ‫ א‬lWS RNe gNP‫ و‬، Http Rquest „‘ i,3 ‫'ل‬b'‫  א‬9 ASP.net ‫—
אن‬
:‫*א‬jVœ‫وאلوא‬$‫א‬g!${t‫وא‬System.Web.UI.Page.Request
554
ob'‫א‬
bœ‫א‬−‫א‬$‫א‬
!
‫א‬nD 0.'\‫א‬H3
ApplicationPath
h3'\‫א‬53
‫د‬$DnD'J!S‫و‬،‫م‬$+\‫א‬OV3 ‫'ع‬
Browser
‫م‬$+\‫א‬K.53kH‫”א‬t‫'א‬P‫ א‬hO3!3
Cookies
Get‫ אو‬Set ‫ل‬H9‫א‬D'
HttpMethod
Post‫ل‬H9‫ 'نא‬U!
:H‫”א‬W‫مא‬H'O‫א‬hQ')
Form
، Get ‫ل‬H9‫ 'ن א‬U !
:H‫ ” א‬W‫م א‬H'O‫ א‬hQ')
QueryString
hQ') 5Fs 53 5P _ ' n i,3 URL ‫ אل‬hQ') iz‫א‬7 ‫'م‬7Q
‫م‬H'O‫א‬
9‫אم‬53Š Http ‫ل‬V‫ˆא‬1QKS !\ IsSecureConnection
h!s‫ونאא‬$ URL ‫!אل‬3
RawUrl
!
‫ א‬h‫
א‬q3D'F03K3‫'لوא‬b'‫א‬
ServerVariables
KF‫ א‬IP !3
UserHostAddress
KFoM\‫!אא‬3
UserHostName
!
‫ א‬nD77H3„‘X'1\‫א‬H\‫א‬KQ'R‫'م‬7‫دא‬
MapPath()
!
‫א‬nDo3nD http ‫אل‬hQ') ªO
SaveAs()
... Request ‫אم‬$+‫א‬5D^39‫ض ™א‬N‫و‬
: Form ‫ﻗﺮاءة ﺑﻴﺎﻧﺎت اﻟﺘﻲ ﺗﻢ ارﺳﺎﻟﻬﺎ ﻓﻲ‬
: Post X'‫مא‬$+€N'
C#
firstName = Request.Form("txtFirstName");
‫ﻛﻮد‬
VB
firstName = Request.Form("txtFirstName")
‫ﻛﻮد‬
: GET X'‫مא‬$+€N'‫و‬
C#
‫ﻛﻮد‬
555
firstName = Request.QueryString ["txtFirstName"];
VB
firstName = Request.QueryString ("txtFirstName")
‫ﻛﻮد‬
7Q1‫א‬lWk‫ج‬R‫א‬9‘ ،‫وس‬H$‫ولא‬CUN,F ID ‫אمאل‬$+i,3gz‫א‬.01‫و—א‬
.!s‫א‬AIChFDU
:‫ﻣﻌﺮﻓﺔ اﺣﺼﺎﺋﻴﺎت اﻟﻤﺘﺼﻔﺢ اﻟﻤﺮﺳﻞ‬
‫ﻛﻮد‬
C#
string theInfo = "";
string isAOL = string.Format("Is AOL? {0} <br/>",Request.Browser.AOL);
string isActivex = string.Format("Support ActiveX? {0}
<br/>",Request.Browser.ActiveXControls);
string isBeta= string.Format("Is Beta? {0} <br/>",Request.Browser.Beta);
string isJava = string.Format("Support Java Applets? {0}
</br>",Request.Browser.JavaApplets);
string isCookies = string.Format("Support Cookies? {0}
<br/>",Request.Browser.Cookies);
string isVB = string.Format("Support VBScript? {0} <br/>",Request.Browser.VBScript);
‫ﻛﻮد‬
VB
Dim theInfo As String = ""
Dim isAOL As String = String.Format("Is AOL? {0} <br/>", Request.Browser.AOL)
Dim isActivex As String = String.Format("Support ActiveX? {0} <br/>",
Request.Browser.ActiveXControls)
Dim isBeta As String = String.Format("Is Beta? {0} <br/>", Request.Browser.Beta)
Dim isJava As String = String.Format("Support Java Applets? {0} </br>",
Request.Browser.JavaApplets)
Dim isCookies As String = String.Format("Support Cookies? {0} <br/>",
Request.Browser.Cookies)
Dim isVB As String = String.Format("Support VBScript? {0} <br/>",
Request.Browser.VBScript)
556
Response ‫اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬
.3.2
، AIC i3 KF‫ א
! ‘„ א‬53 h‫ א‬K7 FD K^e ، Request F P‫ א‬F‫א‬
:‫وאلא‬$‫*وא‬jVœ‫א‬nD'‫و‬،‫م‬$+F:H‫ א‬W‫א‬2N‫א‬KPT
ob'‫א‬
‫א‬$‫وא‬Cbœ‫א‬
2N‫א‬U‫م‬$+\‫א‬3Z‫(مא‬
ContentEncoding
P‫א‬F‫א‬U5P‫ و‬Request ‫אل‬UF
Cache‫و‬Cookies
(R‫א‬n‫م‬$+\‫لא‬V‫א‬QH‫א‬F‫א‬53$]
IsClientConnected
Headers‫ وאل‬Body ‫ אل‬hQ')!3
Clear()
a7!lzg‫”א‬3‫ل‬H‫א\Žوא‬hFDzg‫א‬
End()
**ً‫א‬$%i$O3**Ž\‫א‬FDf7Q‫دونא‬KFl‫”א<ز‬3‫ل‬H‫א‬
Flush()
$Q$% URL „‘KF‫א‬KQ'
Redirect()
ROV‫א‬nD
Write()
: Write ‫אم‬$+P‫א‬nD ‫^ل‬3
C#
Response.Write("<u>This is javascript code</u>");
Response.Write("<script>alert('hiiiii');</script>");
‫ﻛﻮد‬
VB
Response.Write("<u>This is javascript code</u>")
Response.Write("<script>alert('hiiiii');</script>")
‫ﻛﻮد‬
557
ASP.net ‫أدوات‬
.4
F!‫و‬، *.aspx UX'P3 HTML‫ ل‬I53Q ASP.net h‫دوא‬C 53i‫אدא‬CoQ‫!¦ن‬،7N(9F
g‫ א‬9‘ ، 234F g3 3‫ و‬g(\‫ א‬53 N71 U Q‫ אد‬h‫ دوא‬:T‫ א‬i$Q$, g! ‫א ذ‬$D
.1.KPT‫'د‬P‫א‬z‫א‬H‫و‬3‫و‬z‫אدא‬Uo§
K7 Q Event ‫ א‬03‫ و‬، GQ'‫_ א‬D 03 GN k aqs KFD ” t‫ ً وא‬MQ‫ א‬E‫א‬$ N 3‫א א‬W‫و‬
.i,3!
‫‘„ א‬h‫א‬
: AutoPostBack ‫ﺧﺎﺻﻴﺔ‬
Text *N‫א‬h3Ubœ‫א‬lWS${،g!Q$‫א‬03 i,3!
‫‘„א‬K7N‫א‬bœ‫א‬lWS
Combo ‫ و‬List Box gD‫'א‬j‫'א‬7‫ وא‬Check Box & Radio Buttons $Q$R‫ وא‬HI9‫א‬h‫ وאدوא‬Box
. false Sks‫א‬Z!9‫א‬F7‫ وא‬،Box
‫اﻟﺨﺼﺎﺋﺺ اﻷﺳﺎﺳﻴﺔ ﻷدوات اﻟﻮﻳﺐ‬
.4.1
:‫وאل א‬$‫*وא‬jVœ‫א‬k$<t‫ وא‬System.Web.UI.Control JO‫א‬53GQ'‫א‬h‫دوא‬C0B ˆT
ob'‫א‬
‫א‬$‫وא‬Cbœ‫א‬
i‫אدא‬lWkzN‫א‬h‫ אدوא‬0B$
Controls
i‫אدא‬lWSKI‫دא‬h‫دوא‬C‫'د‬%‫م و‬$D‫و‬C‫'د‬%'71N3F.$
HasControls()
-lH‫א‬P5P>9−i‫אدא‬KP$'\‫א‬9‫א‬
ID
i‫دא‬9‫א‬lWS't‫א‬ROV‫א‬nD
q}‫'د‬
Page
i‫אدא‬lWkNsL‫ א‬i‫אدא‬
Parent
i‫دא‬9‫א‬lWSzOI‫אوא‬H'g&
Visible
*jVœ‫ ™ א‬gN3 7T\‫ א‬h‫دوא‬ System.Web.UI.WebControls.WebControl JO‫م א‬$7 F
:gN3،‫وאض‬g(\ 7\‫א‬
558
ob'‫א‬
bœ‫א‬
Oœ‫'نא‬
BackColor
‫ود‬$L‫'نא‬
BorderColor
‫ود‬$L‫א‬KQ
BorderStyle
‫ود‬$L‫ضא‬D
BorderWidth
i‫אدא‬KO‫م‬$D‫و‬CKO
Enabled
i‫אدא‬lWk styles ‫ אœصل‬class ‫אل‬
CssClass
i‫دא‬9‫א‬lWk:! I‫و‬9‫`وא‬L‫א‬53 aœ‫א‬h3'3
Font
P‫א‬aI‫'ن‬
ForeColor
‫'ل‬1‫א‬
Height
‫אض‬
Width
Tab‫אم‬$+K7N‫א‬53g.'3
TabIndex
i‫ دא‬Tips ‫'د‬%‫و‬U
ToolTip
:‫ اﺳﺘﻌﺮاض اﺳﻤﺎء ﺟﻤﻴﻊ اﻷدوات ﻓﻲ اﻟﻔﻮرم‬: ‫ﻣﺜﺎل‬
h‫دوא‬C ‫'د‬%‫ \! و‬HasControls()‫א‬$ !s‫א‬Controls bœ‫ א‬5D 2N‫ א‬Collection ‫אم אل‬$+
‫'دא‬P‫ א‬NP>،:3$D53
C#
string Information="";
if(myPanel.HasControls())
{
foreach (Control c in PanelName.Controls)
{
if (!object.ReferenceEquals(c.GetType(),typeof(System.Web.UI.LiteralControl)))
{
Information+= string.Format("Control Name: {0} <br/>", c.ToString());
Information+= string.Format("ID: {0} <br/>", c.ID);
Information+= string.Format("Control Visible: {0} <br/>", c.Visible);
Information+= string.Format("ViewState: {0} <br/>", c.EnableViewState);
Information+= "<br/><hr/><br/>";
Response.Wite(Information);
}
}
}
‫ﻛﻮد‬
559
VB
Dim Information As String = ""
If myPanel.HasControls() Then
‫ﻛﻮد‬
For Each c As Control In PanelName.Controls
If Not Object.ReferenceEquals(c.[GetType](),
GetType(System.Web.UI.LiteralControl)) Then
Information += String.Format("Control Name: {0} <br/>", c.ToString())
Information += String.Format("ID: {0} <br/>", c.ID)
Information += String.Format("Control Visible: {0} <br/>", c.Visible)
Information += String.Format("ViewState: {0} <br/>", c.EnableViewState)
Information += "<br/><hr/><br/>"
Response.Wite(Information)
End If
Next
End If
:‫ اﻧﺸﺎء أدوات وﻗﺖ اﻟﺘﺼﻤﻴﻢ‬: ‫ﻣﺜﺎل‬
C#
TextBox t1 = new TextBox();
t1.ID = string.Format("dynamict1");
myPanel.Controls.Add(t1);
‫ﻛﻮد‬
VB
Dim t1 As New TextBox()
t1.ID = String.Format("dynamict1")
myPanel.Controls.Add(t1)
‫ﻛﻮد‬
: ASP.net ‫أﻗﺴﺎم اﻷدوات ﻓﻲ‬
:jH‫'אع‬Ci$ ASP.net Ui‫'د‬%'\‫א‬h‫אدوא‬7N
: Simple controls
Label ‫'אن‬N‫ وא‬TextBox *N‫ א‬h3K^3ً‫ א‬HTML bND53gNP‫ و‬ASP.net 0t‫א‬h‫אدوא‬
.:! I‫ و‬Buttons 3‫א‬H‫א‬H‫ز‬C‫و‬
560
: Rich controls
i‫ وאدא‬Calendar Q'7‫ א‬i‫ אدא‬g^3‫ א‬53، *jVI‫ًو‬T^‫ א‬gNP‫ و‬Q‫ אد‬ASP.net h‫دوא‬C 53 D'F
:! I‫ و‬Menu j‫'א‬7‫ وא‬TreeView i`T‫ضא‬D
: Data controls
GridView g^3‫א‬g,‫א‬53،h‫א‬i$D7a‫א‬nD$Fh‫אدوא‬S
: Validation controls
g! JavaScript hQ')ˆ1 Q،KF‫א‬$NDSWONQ5P‫
!و‬h‫אدوא‬S،ˆ7R‫א‬h‫אدوא‬
.ˆ7R‫א‬hFD™WON
: Login Controls
.:! I‫'لو‬I$‫א‬K` 3P\‫א‬h‫دوא‬9‫א‬53D'F
: Web part controls
.ROV‫א‬z‫א‬%‫* א‬jVI‫'نو‬UPR.'3‫م‬$+\bO‫א‬9VV†h‫אدوא‬D'F
.7gND N‹$t‫ وא‬HTML Controls 01¤NS
‫אאل‬$D3„‫אو‬iFNDFt‫א‬bœ‫א‬h‫אدوא‬lWS ™nDf‫א‬3‫د‬7‫وسא‬H$‫א‬5Fs‫ول‬RN
.h‫א‬$D‫'א‬. + ASP.net ‫אل‬.ngNDQ$L‫ א‬K%pNt‫وא‬GridView
MasterPages
.5
z`‫و‬$Q،hROV‫א‬KU l
qQ90.'\‫א‬53ً‹ً‫א‬z%‫אن‬0.‫א\'א‬53
‫د‬$DUª .hROV‫ א‬KUً‫א‬HP3‫و‬$Q:NP‫و‬g3KDOQ‫و‬ROV‫א‬53
zŽ‫@א‬OKF€F.‫و‬ROb 100:0.'\‫אنא‬K+،hROV‫א‬KUً‫'دא‬%'3@zŽ‫אא‬WS0.‫א'א‬U
.3 ROb 100 ‫ אل‬U KQ$ 1M! ، :VjVI $‫
א‬q U €—H ‹ ، i3 K U
53 z% ‫ א‬U gN ROV Include KFD Q ‫ ن‬W‫ وא‬ASP U include ‫ אل‬C$3g& NS 53
hROV‫א‬KPjHROb3ROb53K{t‫ وא‬Master Pages‫אل‬Nhg& ASP.net 03‫و‬،ROb
:‫א‬KPT Master Page ZI‫ وא‬New Item !s.،Q'C$\‫אא‬WSX`N
561
:‫א‬$Q$Ž‫א‬VN‫'دא‬%‫'و‬S‫'د‬P‫ א‬RObU:( 3‫אول‬،k¤zT‫א‬$
‫ﻛﻮد‬
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
lWS$‫و‬K.O+\‫ א‬¤‫א'אد‬0s'.،k Master Page KFDt‫א‬ROV‫א‬Yƒ'‫א‬5QWSK^>
.g!j‫א‬ROV‫ضא‬D!71N\‫א‬lWS3‫א‬،71N\‫א‬
‫א\^ل‬U،a7!ROV‫!'قو€א‬K(g‫א‬cQ 9'‫'د!'قو€א‬P‫نא‬C‫א‬،a7!‫א‬WS@
nD'AI9‫א‬h3 9‫אل‬F!ROV‫א‬a‫و‬a7!
qb03U g(j‫א‬ROV‫א‬K`N‫א‬
:ً ^3‫א‬iH'V ،3h
562
:‫ א‬KPT‫'ن‬PROV‫א‬lWg‫'دאœص‬P‫א‬
‫ﻛﻮد‬
<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<center>
<table border="1" width=80%>
<tr>
<td>hiiii, i am here</td>
<td><img src="http://vb4arab.com/vb/attachments/logo.jpg" /></td>
<td>any thing</td>
</tr>
<tr>
<td>hii again</td>
<td>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</td>
<td><input type="button" /></td>
</tr>
<tr>
<td colspan=2>large TD :)</td>
<td>bye</td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>
563
RObzT.FV‫א‬53 zg9‫א‬$،a7!‫'د‬P‫א‬53@‫ و‬Designer ‫ لאل‬I53gFFV5P>ً‫و‬
:‫ א‬KPT:S$Q$R. Master Page G,,U‫و‬،i$Q$%
‫'م‬7KPT‫@א‬OnDk'VUG—ROb‫א‬03‫ وאšن‬،AI‫א‬,,US$Q$N3G1ً79
Page :U‫א‬bœ‫א‬KQ$NP>>$.ROb€ 'n،F7‫@א‬OSz1D
:‫ ًא‬$Q$'‫אא‬WS‫'د‬%‫و‬iD‫א‬3‫و‬
‫ﻛﻮد‬
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
</asp:Content>
. html ‫ وو‬head ‫אل‬K^3h‫א‬H‫א‬PnD'9‫@אن‬N95P
Sitemap ‫اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬
.6
KPTً7901،g‫و‬.'3hQ')oQ t‫ وא‬SiteMap ‫אل‬5j033‫ ل‬I53
:‫א‬KPT sitemap !sً9‫אو‬z$N،.'3 hROV`,‫ض‬D‫و‬j‫'א‬.
564
:ً s‫א‬Z!‫'دאא‬P‫א‬$`
‫ﻛﻮد‬
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="" title="" description="">
<siteMapNode url="" title="" description="" />
<siteMapNode url="" title="" description="" />
</siteMapNode>
</siteMap>
:YO† YRObg‫و‬Q‫א‬$‫א‬RObً ^3‫ض‬ZON، Nodes ‫אل‬lWSoQNFg3‫אšن‬
‫ﻛﻮد‬
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Default1.aspx" title="Q‫א‬$‫א‬ROb" description="">
<siteMapNode url="Default2.aspx" title="‫'و‬S‫'א‬%'ROb !" description="" />
<siteMapNode url="Default3.aspx" title="A$N\‫'א‬%'ROb" description="" />
</siteMapNode>
</siteMap>
565
Menu !s‫'م‬7N‫و‬N bœ‫ א‬MasterPage ‫‘„אل‬K7NN،h3'\‫א‬lWS53i‫د‬O9‫ولא‬RN‫אšن‬
: sitemap‫אאل‬WS‫'ن‬Pk DataSource ‫אل‬$Q$‫و‬
Site map ZI‫א‬، DataSource ‫'عאل‬$Q$N3G1‫א‬i'1œ‫א‬U
:‫ א‬KPT‫'ن‬PW‫وא‬.'3KqTX%،‫אšن‬
: SiteMapPath
:ً ^3‫א‬KPT‫ن‬P\‫ א‬$Q$gFg3،D'F¡‫@א‬O0AI‫א‬i‫دא‬C
566
iH'VROb K303KF‫و‬، masterpage ‫אل‬Ugs'.
‫أدوات اﻟﺘﺤﻘﻖ‬
.7
h‫אدوא‬nD '‫و‬، Client SideKF‫א‬g%g—‫א‬KFQh I$\‫א‬53ˆ7R‫א‬h‫אدوא‬53D'F S
:‫א‬
F $] i‫د‬D‫ א‬U ً ^3 $O ، AIC h I$} g% U h I$\‫ א‬H7\ :CompareValidator −
ˆ7R‫אא‬WSˆ1Ui‫אدא‬lWS aH،H‫א\و‬
l$Q$QY3‫ق‬15Fs07 h I$\‫אنא‬53$]:RangeValidator−
.h‫ل‬I‫مد‬. ‫م‬$+\‫نא‬C53$]:RequiredFieldValidator−
¤$O Regular ExpressionnDzN ˆ7R‫א‬53‫'ع‬$Q$NP>: RegularExpressionValidator−
Regular ‫ אل‬5D $Q\‫ \! א‬، oS .H ‫و אو‬ZP‫ א‬$Q ‫و‬C 0.'3 Rb 53 ˆ7R‫ א‬U ً ^3
:−D− ‫س‬H$‫א א‬WS%‫א‬3NP>Expressions
‫رابط‬
http://www.arabteam2000-forum.com/index.php?showtopic=77787
::G— RegularExpression ‫אجא‬+9Y.'\‫א‬5QWS53i‫د‬O9‫א‬NP>ًMQC
‫رابط‬
http://regexlib.com/DisplayPatterns.aspx
http://www.regular-expressions.info/
.bœ‫ˆא‬7R‫א‬h‫א‬z‫א‬%‫א‬zN :CustomValidator−
.‫م‬H'O‫א א‬WS U €e t‫ˆ א‬7R‫ א‬hFD %'3 ‫ ض‬: ValidationSummary −
:‫*א‬jVœ‫א‬nDD'F¡‫א‬lWS'
gN3ˆ7R‫א‬X'1\‫لא‬I‫د‬9‫א‬i‫دא‬C:ControlToValidate
567
.]1œ‫א‬E‫و‬$U‫אض‬:Display
.]1œ‫א‬H:ErrorMessage
.]1œ‫א‬H ‫'ن‬:ForeColor
$]‫و‬H‫א\و‬.H‫و‬،9‫א‬nD'،1h K`‫م‬H'!FV‫'م‬7N،D'F¡‫א‬lWS`‫אšن‬
. F‫ووא‬ZP9‫ א‬$Q4‫وא‬،H‫א\و‬F
RequiredFieldValidator : ً I‫'ن‬PQ‫אن‬5P>99‫א‬ CompareValidator :Y71N3‫''א‬PQ‫אن‬$9S$]‫و‬H‫א\و‬F RegularExpressionValidator : ً RRb‫'ن‬PQ‫אن‬$9K>9‫א‬ RangeValidator : 50‫و‬10Y‫'ن‬PQ‫ن‬C$9F‫א‬ ...gBˆ7R‫א‬2j ‫ض‬NQgN‫א‬U‫و‬ :‫א‬KPT‫'نא‬Pg‫ אœص‬K7L‫א‬G´i‫אدא‬K0s‫و‬،‫م‬H'O‫א‬FV.
:‫'د‬P‫وא‬
‫ﻛﻮد‬
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs"
Inherits="Default4" %>
568
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Name:<br />
&nbsp;<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="you must eneter
Name"></asp:RequiredFieldValidator>
<br />
<br />
Age:<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="TextBox2" ErrorMessage="Age must be between 10 and
50"
MaximumValue="50" MinimumValue="10"></asp:RangeValidator>
<br />
<br />
Password:<br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<br />
Retype Password:<br />
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="TextBox3" ControlToValidate="TextBox4"
ErrorMessage="The passwords must be the same"></asp:CompareValidator>
<br />
<br />
E-mail:<br />
&nbsp;<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server"
ControlToValidate="TextBox5" ErrorMessage="invalid email address"
ValidationExpression="^((?&gt;[a-zA-Z\d!#$%&amp;'*+\/=?^_`{|}~]+\x20*|&quot;((?=[\x01-\x7f])[^&quot;\\]|\\[\x01\x7f])*&quot;\x20*)*(?&lt;angle&gt;&lt;))?((?!\.)(?&gt;\.?[a-zA-Z\d!#$%&amp;'*+\/=?^_`{|}~]+)+|&quot;((?=[\x01-\x7f])[^&quot;\\]|\\[\x01-\x7f])*&quot;)@(((?!)[a-zA-Z\d\-]+(?&lt;!-)\.)+[a-zA-Z]{2,}|\[(((?(?&lt;!\[)\.)(25[0-5]|2[04]\d|[01]?\d?\d)){4}|[a-zA-Z\d\-]*[a-zA-Z\d]:((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-
569
\x7f])+)\])(?(angle)&gt;)$"></asp:RegularExpressionValidator>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Go On" />
<br />
<br />
Summery:r />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
</div>
</form>
</body></html>
.g!i$‫وא‬KP ControlToValidate‫אل‬$Q$R€F.‫و‬،gN3KP Error Message q€F.ً
:'S7‫وسא‬H$‫€™א‬%‫א‬H$.5P_'K>9‫א‬F‫ א زم‬RegularExpression ~‫א‬
‫ﻛﻮد‬
^((?>[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+\x20*|"((?=[\x01-\x7f])[^"\\]|\\[\x01\x7f])*"\x20*)*(?<angle><))?((?!\.)(?>\.?[a-zA-Z\d!#$%&'*+\/=?^_`{|}~]+)+|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*")@(((?!-)[a-zA-Z\d\-]+(?<!)\.)+[a-zA-Z]{2,}|\[(((?(?<!\[)\.)(25[0-5]|2[0-4]\d|[01]?\d?\d)){4}|[a-zA-Z\d\-]*[a-zAZ\d]:((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-\x7f])+)\])(?(angle)>)$
Range ‫אل‬U‫و‬، ControlToValidatebœ!s‫ א‬ControlToCompare bI¤Ng!،H7FN‫و‬
. Maximum Value‫ و‬Minimum Value *jVI
:`N‫ א‬$S,‫و‬،Iš‫א‬z‫א‬H‫]و‬1Iz1I9‫א‬XPH‫א‬X%‫وאšن‬
570
:‫ﻧﻘﺎط ﺳﺮﻳﻌﺔ‬
:NS 53 Web Parts 5D$Q\‫!א‬3NP>
‫رابط‬
http://msdn.microsoft.com/en-us/library/e0s9t4ck.aspx
Q$7‫א‬KL‫א‬، F3VYRY7Q¤NS،ً‫א‬$% j‫א‬$(R‫א‬ng‫'م‬7t‫א‬3V!A F :NSgND$Q\‫!א‬3NP>lWS‫و‬، CSS K‫אم‬$+‫א‬nD$FQ
‫رابط‬
http://www.w3.org/Style/CSS/learning
571
:NS53g!z$‫א‬NP>، Themes fQ3‫אم‬$+‫'א‬S ASP.net 53z‫א‬$‫א‬$Q$Ž‫א‬KL‫א‬
‫رابط‬
http://msdn.microsoft.com/en-us/library/ykzx33wh.aspx
State Management
.8
‫א‬WS K(! 3 q\ OQ €.‫ א و‬¤H$ Desktop Application Q'1 U H{ ‫ ل‬I 53‫ و‬
0s'‫אא‬WS ‫ن‬C9‘،
q\‫אא‬Wg‫ אœص‬Scope ‫جאل‬HI‫وאœوج‬C234‫א‬zg‫א‬n:F7 ً (O)
q\‫א‬
‫'م‬7 ‫ن‬C D ‫ א زم‬53 ‫א ن‬W ، KQ$ ‫ول‬C 03 h‫
א‬q\‫ א‬. 0M ASP.net U ً 3e o†
.‫س‬H$‫אא‬WSU:N7™nD fN3'S‫و‬،gD%Z‫א‬NP>r.‫
אو‬q35Q+
:‫قא‬53i$‫'א‬7‫א‬5Q§NP>
.View state−
.Control state−
.Application-Level Variable−
.Cache−
.Session−
.Cookies−
Control state .8.1
'‫و‬ni‫دא‬C EnableViewState F7‫
א‬q'SD3K،h&O Kg‫א‬7Q1‫ א‬S
‫א— ق‬ngF7(O)K(‫ ]‹و‬5‫دوא‬C53CUi‫'د‬%'\‫א‬7‫א‬L‫א‬lWSU،KPROV
.ROV‫א‬
‫אل‬ªOd‫א‬zŽ‫א‬$` View State ‫م‬$+ROVOV\‫ א‬5D2N‫ א‬HTML ‫€אل‬R!'
.:F7ViewState
572
‫ﻛﻮد‬
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwUKMTIxNDIyOTM0Mg9kFgICAw9kFgICAQ8PFgIeBFRleHQFBWFobWVkZ
GRkCq8FGqyXBP0pBDpvdnycvM5zSQE=" />
:‫ﺧﻄﺄ ﺷﺎﺋﻊ‬
‫م‬$+ 5QH'1\‫א‬G—‫א‬، Form_Load ‫אل‬E$U Q$Fj.hQ')zK}‫'م‬7‫ج–ن‬3ًC
:‫א‬X'9‫א‬
C#
‫ﻛﻮد‬
ListBox1.Items.Add("Ahmed");
ListBox1.Items.Add("Mohammed");
ListBox1.Items.Add("Ali");
VB
ListBox1.Items.Add("Ahmed")
ListBox1.Items.Add("Mohammed")
ListBox1.Items.Add("Ali")
‫ﻛﻮد‬
!!!h‫א‬i$D.‫ ل‬I53QFj7‫א‬zK3‫ً 'ن‬b'VI،ً‫א‬$%37Q1‫א‬lWS0.‫א'א‬U
53 $] IsPostBack bœ‫אم א‬$+‫ وא‬، EnableViewState bI nD ‫د‬FD9‫' א‬S ، KQ$‫ א‬KL‫א‬
‫א‬KPTa7!„‫אو‬i\‫א‬US }‫'م‬7 NC
C#
if (!IsPostBack)
{
ListBox1.Items.Add("Ahmed");
ListBox1.Items.Add("Mohammed");
ListBox1.Items.Add("Ali");
}
‫ﻛﻮد‬
VB
If Not IsPostBack Then
ListBox1.Items.Add("Ahmed")
ListBox1.Items.Add("Mohammed")
ListBox1.Items.Add("Ali")
End If
‫ﻛﻮد‬
573
View state .8.2
5Q+‫'دא‬P‫^ ًא‬3NP> ،h‫אدوא‬5Dً‫א‬$5P‫'مو‬gO\‫@א‬OnD$FAIC7Q
:7Q1‫@א‬ON3F.
C#
ViewState["CustomViewStateItem"] = "Ahmed";
‫ﻛﻮد‬
VB
ViewState("CustomViewStateItem") = "Ahmed"
‫ﻛﻮد‬
::‫د‬9‫و‬
C#
Label1.Text = (string)ViewState["CustomViewStateItem"];
‫ﻛﻮد‬
VB
Label1.Text = DirectCast(ViewState("CustomViewStateItem"), String)
‫ﻛﻮد‬
Session .8.3
:P،a7!NP‫א‬f I‫א‬037‫ א‬View State 7Q@ON‫و‬،ً‫א‬$%K3‫ א‬g7Q
C#
Session["mySession"] = "Ahmed";
‫ﻛﻮد‬
VB
Session("mySession") = "Ahmed"
‫ﻛﻮد‬
:i‫د‬9‫وא‬
574
C#
string name = (string) Session["mySession"];
‫ﻛﻮد‬
VB
Dim name As String = DirectCast(Session("mySession"), String)
‫ﻛﻮد‬
:‫א‬KPT Session Remove KFD NP>
C#
Session.Remove["mySession"];
‫ﻛﻮد‬
VB
Session.Remove("mySession")
‫ﻛﻮد‬
7.‫د‬20Sًs‫א‬Z!‫وא‬،ˆj.$:F7 Session ‫&אل‬O‫ א‬iZ!‫د‬$t‫ وא‬Timeout bI¤NS‫ن‬CF
C#
Session.Timeout = 5;
‫ﻛﻮد‬
VB
Session.Timeout = 5
‫ﻛﻮد‬
Cookies
.8.4
)VhO3 U7‫א‬lWg&O9‫א‬Q،KF‫زא‬g%$ND5P‫و‬7&O9‫א‬Kj‫و‬53 AIC7Q
^‫א‬7Q1‫א‬S‫و‬،F‫א‬lWS K^}FQKF‫א‬OV3‫'ن‬PQ‫אن‬iD‫א‬3qNQ5P‫ن(و‬9‫א‬G—‫א‬U
JO‫ א‬53 7T3 S‫ و‬،
O+\‫ א‬0.‫ א\'א‬U K`‫'ل وא‬I$‫ א‬h3'} &O9‫ א‬U ig,
. System.Web.HttpCookie
"‫وא‬CMI9‫ א'ن א‬−‫א'אن‬53‫م‬$+\‫א‬HI‫א‬K`‫'م‬7N،'P‫א‬nDً9^3‫ אšن‬X`N
‫ 'ن‬z'`‫ א‬Q 9‘‫ و‬، KMO\‫אم א'ن א‬$+‫ א‬Q ' ‫'د‬%‫ و‬U 0.'F KqT K 03‫ و‬،− ً ^3
.ً ^3Ob‫'א‬S‫و‬s‫א‬Z!9‫א‬
:Ob‫א‬s‫א‬Z!9‫ً'نא‬9‫אو‬ROV‫'م א‬7N
575
:g‫'د אœص‬P‫א‬
‫ﻛﻮد‬
<asp:Panel ID="Panel1" runat="server" Height="134px" Width="446px"
BackColor="Yellow">
X'1\‫א'نא‬HI. :<br />
<br />
<asp:RadioButton ID="RadioButton1" runat="server" Text="MIC"
GroupName="colors" />
<br />
<asp:RadioButton ID="RadioButton2" runat="server"
oncheckedchanged="RadioButton2_CheckedChanged" Text=""C"
GroupName="colors"/>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="ˆ1" onclick="Button1_Click1"
/>
</asp:Panel>
،(ˆ1)H‫ ز‬nDaqM‫א‬E$U‫א‬KPTًH+\‫א'نא‬:!‫ن‬µ'zT‫'م‬7N ،‫وאšن‬
:zg ً•H'P‫אא‬WS1N‫و‬
576
C#
string color;
if (RadioButton1.Checked)
{
color = "Green";
Panel1.BackColor = System.Drawing.Color.Green;
}
else if (RadioButton2.Checked)
{
color = "Red";
Panel1.BackColor = System.Drawing.Color.Red;
}
else
color = "";
HttpCookie Cookie = new HttpCookie("myColor", color);
Cookie.Expires = DateTime.Parse("01/01/2009");
Response.Cookies.Add(Cookie);
‫ﻛﻮد‬
VB
Dim color As String
If RadioButton1.Checked Then
color = "Green"
Panel1.BackColor = System.Drawing.Color.Green
ElseIf RadioButton2.Checked Then
color = "Red"
Panel1.BackColor = System.Drawing.Color.Red
Else
color = ""
End If
Dim Cookie As New HttpCookie("myColor", color)
Cookie.Expires = DateTime.Parse("01/01/2009")
Response.Cookies.Add(Cookie)
‫ﻛﻮد‬
!3! myColor ‫'د‬%‫و‬U‫و‬،'P‫א‬iz‫א‬7‫'م‬7N ،KqT Form_Load ‫אل‬E$U‫وאšن‬
::F.
C#
if (Request.Cookies["myColor"]!=null)
{
string color = Request.Cookies["myColor"].Value;
if (color=="Green")
Panel1.BackColor = System.Drawing.Color.Green;
else if (color=="Red")
Panel1.BackColor = System.Drawing.Color.Red;
}
‫ﻛﻮد‬
577
VB
If Request.Cookies("myColor") IsNot Nothing Then
Dim color As String = Request.Cookies("myColor").Value
If color = "Green" Then
Panel1.BackColor = System.Drawing.Color.Green
ElseIf color = "Red" Then
Panel1.BackColor = System.Drawing.Color.Red
End If
End If
‫ﻛﻮد‬
Application .8.5
QK، $‫وא‬KFh‫א‬5Q§Q9k I535P‫و‬، HttpApplicationState 537T3 AIC7Q
$NDً‫‹א‬p3‫'ن‬PQ ‫אن‬qNQ W‫ وא‬H‫دאوא‬$D'Sk‫^ل‬3a‫א‬،z F‫א‬0FŽKV ‫אن‬5P>h5Q§
.a7!$‫وא‬KFD@‫و‬z F‫א‬0B
:‫*א‬jVœ‫وאلوא‬$‫א‬nDJO‫ א‬lWS'
ob'‫א‬
‫א‬$‫وא‬Cbœ‫א‬
Fj7$Q$%$Q$%VND !s‫א‬
Add()
i‫'د‬%'\‫א‬bN‫א‬0B‫אאض‬
AllKeys
i‫'د‬%'\‫א‬bN‫دא‬$D!3
Count
D'F¡‫א‬KQ$vF‫م א‬$D‫אو‬vF‫א‬
Lock(), Unlock()
KP‫א‬fW‫و‬C،Y3‫و‬C،N317U VNDfWL‫م‬$+
RemoveAt()
Remove()
RemoveAll()
:‫א‬KPT$Q$% Application !s‫א‬NP>
C#
Application["Visitors"] = 1;
‫ﻛﻮد‬
VB
Application("Visitors") = 1
‫ﻛﻮد‬
578
:ً ^3‫'אن‬ND03Ug‫ אد‬5P>‫و‬
C#
labelVistor.Text=(string)Application["Visitors"];
‫ﻛﻮد‬
VB
labelVistor.Text = DirectCast(Application("Visitors"), String)
‫ﻛﻮد‬
:ً ^3F. KQ$‫و‬
C#
Application["Visitor"]= ((int)Application["Visitor"])+1;
‫ﻛﻮد‬
VB
Application("Visitor") = CInt(Application("Visitor")) + 1
‫ﻛﻮد‬
‫ﻣﻼﺣﻈﺔ‬
... ً ‫ بل قد تكون مصفوفة من الفئات مثال‬، ‫ قد ال تكون نص فقط‬Application ‫التنس ان محتويات ال‬
Cache .8.6
SzT9 ، k a7! N3 iZ! $Q$ NP> 5P‫ و‬، z F‫ א‬ig%C 0B $ND ˆ1 V† AIC N7
:ً ^3‫א‬3‫مא‬$+
C#
Context.Cache["myCache"] = "hii, my first cache";
‫ﻛﻮد‬
579
VB
Context.Cache("myCache") = "hii, my first cache"
‫ﻛﻮد‬
:i‫و د‬
C#
string myCache = (string)Context.Cache["myCache"];
‫ﻛﻮد‬
VB
Dim myCache As String = DirectCast(Context.Cache("myCache"), String)
‫ﻛﻮد‬
Global.asax .8.7
5P>‫ ودوאل‬Global h‫
א‬q35Q+ Global.asax o3‫אم‬$+‫ א‬S 5Q+‫'عא‬s'3UNQ$j%IŠ
:‫א‬KPTSHI.‫و‬$Q$%VND!s.، ROb‫א‬53g‘‫'ل‬b'‫א‬
:‫ًא'אدא‬s‫א‬Z!‫א‬g$`،ROV‫א‬lWk!s‫ א‬$
580
C#
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
‫ﻛﻮد‬
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
</script>
VB
<%@ Application Language="VB" %>
<script runat="server">
Private Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
End Sub
Private Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application shutdown
End Sub
Private Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
‫ﻛﻮد‬
581
' Code that runs when an unhandled error occurs
End Sub
Private Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a new session is started
End Sub
Private Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a session ends.
' Note: The Session_End event is raised only when the sessionstate mode
' is set to InProc in the Web.config file. If session mode is set to StateServer
' or SQLServer, the event is not raised.
End Sub
</script>
State ‫ ! א'אع אل‬03 K3 bI jH ‫وאل‬$ hOQ nD ROV‫ א‬lWS ' ، €(9 F‫و‬
K3 iH‫ אدא‬U $O ‫ دوאل‬53 S
—‫ و‬Application_Errorz1I‫ א‬E‫و‬$ L !s‫ א‬، Management
O+\‫ א‬State Management bN 3‫א‬$+‫ א‬0B U gN3 i‫د‬O9‫ א‬NP>‫ و‬، ‫وع‬T\‫ א‬hROb
.‫س‬H$‫אא‬WSUgD N!t‫א‬
‫ وﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت‬ASP.net
.9
t‫א‬h3'\‫א‬53^ ‫ج‬50.‫א'א‬U، ASP.net 03h‫א‬$D‫'א‬._DUQ'%‫אšن‬WI]N
.NSg71Nt‫وא‬، ADO.net ‫وس‬H‫د‬UgF
‫م‬$+N ، ‫م‬$+F gD‫ و‬h‫ א‬i$D. 53 zƒC iz‫א‬7 a7! ‫'م‬7Q a 0.'3 KF Q‫א‬$ ‫'م‬7N ‫א‬W
:K.‫א‬9‫^و‬C@‫'د‬P‫' א‬S‫א‬WSa7!،l‫و‬2N\‫אא‬nDًj$3'hi$D.
C#
SqlConnection cn = new SqlConnection(@"Data Source=AHMEDPC\SQLEXPRESS;Initial Catalog=Items;Integrated Security=True;Pooling=False");
cn.Open();
SqlCommand cmd = new SqlCommand("select * from Items",cn);
SqlDataReader dr= cmd.ExecuteReader();
while (dr.Read())
{
Response.Write("<b><font color=blue> Item Number: </font></b>" +
dr.GetInt64(0).ToString() + "<br/>");
Response.Write("<b><font color=blue> Item Name: </font></b>" +
‫ﻛﻮد‬
582
dr.GetString(1) + "<br/>");
Response.Write("<b><font color=blue>Item Price: </font></b>" +
dr.GetInt64(2).ToString() + "<hr/>");
}
VB
Dim cn As New SqlConnection("Data Source=AHMED-PC\SQLEXPRESS;Initial
Catalog=Items;Integrated Security=True;Pooling=False")
cn.Open()
Dim cmd As New SqlCommand("select * from Items", cn)
Dim dr As SqlDataReader = cmd.ExecuteReader()
While dr.Read()
‫ﻛﻮد‬
Response.Write("<b><font color=blue> Item Number: </font></b>" +
dr.GetInt64(0).ToString() + "<br/>")
Response.Write("<b><font color=blue> Item Name: </font></b>" +
dr.GetString(1) + "<br/>")
Response.Write("<b><font color=blue>Item Price: </font></b>" +
dr.GetInt64(2).ToString() + "<hr/>")
End While
:2N‫وא‬
، iH'V‫ א‬a‫א‬H K7 h‫ א‬i$D7 oMN F ‫אول‬$Ž‫م ™ א‬$+N ، ً . ‫ אض‬FD KF`N ‫אšن‬
‫'ن‬P ‫'د‬P‫ א‬− 2N3 KP gsN t‫ وא‬234‫ א‬H3 @O U iamges $ U H'V‫ ™ א‬oMN
:‫א‬KPT
583
‫ﻛﻮد‬
C#
SqlConnection cn = new SqlConnection(@"Data Source=AHMEDPC\SQLEXPRESS;Initial Catalog=Items;Integrated Security=True;Pooling=False");
cn.Open();
SqlCommand cmd = new SqlCommand("select * from Items",cn);
SqlDataReader dr= cmd.ExecuteReader();
Response.Write("<center><table border=1><tr valign=center align=center
bgcolor=#AAAAAA><td><b>Item No.</b></td><td><b>Item
Name</b></td><td><b>Item Price</b></td><td><b>Sample</b></td></tr>");
while (dr.Read())
{
Response.Write("<tr><td><b>" + dr.GetInt64(0).ToString() +
"</b></td>");
Response.Write("<td>" + dr.GetString(1) + "</td>");
Response.Write("<td>" + dr.GetInt64(2).ToString() + "</td>");
Response.Write(@"<td><img src='images/" + dr.GetString(3) +
"'></td></tr>");
}
Response.Write("</table></center>");
‫ﻛﻮد‬
VB
Dim cn As New SqlConnection("Data Source=AHMED-PC\SQLEXPRESS;Initial
Catalog=Items;Integrated Security=True;Pooling=False")
cn.Open()
Dim cmd As New SqlCommand("select * from Items", cn)
Dim dr As SqlDataReader = cmd.ExecuteReader()
Response.Write("<center><table border=1><tr valign=center align=center
bgcolor=#AAAAAA><td><b>Item No.</b></td><td><b>Item
Name</b></td><td><b>Item Price</b></td><td><b>Sample</b></td></tr>")
While dr.Read()
Response.Write("<tr><td><b>" + dr.GetInt64(0).ToString() + "</b></td>")
Response.Write("<td>" + dr.GetString(1) + "</td>")
Response.Write("<td>" + dr.GetInt64(2).ToString() + "</td>")
Response.Write("<td><img src='images/" + dr.GetString(3) + "'></td></tr>")
End While
Response.Write("</table></center>")
:ً ^3‫ א‬KPT‫'ن‬P2N‫وא‬
584
‫ﻣﻼﺣﻈﺔ‬
gRt‫א‬h g‫™ א‬nDfN‫אšن‬، ASP CLassic _DUg71Nt‫א‬7Q1‫@א‬OSlWS
..net~‫א‬N
DataGrid
.9.1
...g3K3‫אšنא‬X`N، ASP.net 03ig,h‫א‬h‫א^אدوא‬i‫دא‬9‫ א‬lWS4
SqlDataSource GR.‹ 53‫و‬،R‫א‬FDK%‫א‬533CH‫*وز‬03.، DataGrid .
:‫א‬KPTN‫و‬$´g1‫'م‬7‫و‬
585
. Next aqs‫א‬، Connection String ‫אل‬ªOً79N3 G1
:K7L‫א‬hQ')!HI.،h‫א‬H$V3$Q$N3 G1^^‫א‬i'1œ‫א‬U
:D'‫د‬$‰‫
ًא و‬q3oMN‫א‬W،a7!Y3€0jM‫א‬Hg&‫א‬UˆL‫مא‬$+F‫طאن‬,ًMQ‫ א‬0MN
:‫א‬KPT*N‫א‬03‫א‬0M‫ و‬Control :]
586
.zg‫א‬aqs‫א‬، Query ‫{אل‬NP> a7!
NF.W‫ א‬SqlDataSource ‫'نאل‬Pk DataSource HI. ، DataGrid ‫‘„אل‬i‫'م'د‬7N‫אšن‬
:‫א‬KPT K.WN3lzT
:‫א‬WkًgT3ًJ, ‫'ن‬P2N‫א‬، Enter H‫ز‬nDaqM‫وא‬O†‫م‬.H‫א‬HI.،234‫`א‬. ،a7!‫و‬
587
: ‫ﺧﺼﺎﺋﺺ اﺿﺎﻓﻴﺔ‬
g(\‫א‬Sk‫אو‬،i‫אدא‬lWg7!\‫! א‬s9‫*א‬jVœ‫™א‬5D‫אšن‬E$RN
:‫א‬KPT‫'د‬%'\‫א‬YHI9‫א‬NP>‫ و‬،‫ص‬I CSS ‫ ل‬I53g(\‫א‬KQ$NP>
، hROV‫'د א‬%' vF‫ א‬NP> ، GridView i‫دא‬C nD O+\‫ א‬hF vF‫ א‬S ، ^‫ א‬17N‫א‬
:ًMQ‫א‬GZ‫وא‬HI9‫وא‬
588
:‫א‬KPTًJ,‫'ن‬P 2N‫א‬
:‫אم‬$+‫د‬$¡‫א‬K`‫א‬iz‫א‬.NP>،HI E$0s‫و‬X`N ‫אšن‬
C#
string something=GridView1.SelectedRow.Cells[0].ToString();
‫ﻛﻮد‬
VB
Dim something As String
something=GridView1.SelectedRow.Cells(0).ToString()
‫ﻛﻮد‬
:‫*אœ'אصא‬jVœ‫א‬5Fs$`N ‫אšن‬
:ً ^3‫א‬KPT،!s9‫وא‬KQ$‫وא‬fWL‫א‬hF*jVœ‫א‬lWSN F
589
.:! I‫ًضو‬MQ‫مא‬$+t‫ وא‬details view ‫ و‬FormView K^3AI‫א‬h‫ًאدوא‬MQ‫ א‬¤NS
:ً ^3‫ א‬KPT$Q3Ggjƒ‫وא‬i$FD‫*א‬jVIUKQ$‫א‬5P>،h‫دوא‬9‫א‬lWSKP
K9‫وس א‬H$‫א‬US${KbO‫א‬.، ASP.net 03h‫א‬$D‫'א‬._DUQ'%lWS €
...ADO.net
590
WAP
.10
ft‫ وא‬Protocol Wireless Application!‫א\و‬N7‫א‬nDQ'ff'،‫س‬H$‫אא‬WSU
‫ ل‬I53N7‫א‬lWS03K3‫א‬O„‘‫س‬H$‫אא‬WS53^‫א‬zŽ‫א‬U‫ق‬1NF، WAPً‫א‬HVI‫א‬
.net.
‫ ؟‬WAP ‫ ﻣﺎ ﻫﻲ‬.10.1
: Mobile Application ‫ﺗﻄﺒﻴﻘﺎت اﻟﻤﻮﺑﺎﻳﻞ‬
3‫א‬H'1‘،lH'g&€.‫و‬:N3f$k‫نא‬F^3Ok‫א‬h\P\‫א‬z‫א‬%91‫ل‬V‫وא‬KQ'\‫א‬$Q_
K h\P\‫ א‬K%C 53 ‫م‬$+Q KQ'\‫ א‬$Q _‫ و‬، ً MQC F‫ و‬g!‫ و‬3$I ‫ و‬KQ'\‫ א‬V ‫אšن‬
. S
—‫ و‬Q$F\‫ وא‬3$7\‫ א‬h71‫אم א‬$+‫€ وא‬Z9‫ א‬nD ‫'ل‬I$‫ א‬U ‫م‬$+Q bC
،:‫אœص‬KqT‫و(א‬:‫وא‬KQ'\‫א‬h71nD‫ل‬$i$Q$%hR1V3hg&l
—‫و‬G‫אא‬Wk‫و‬
aQW‫وא‬V+T‫א‬hL‫א‬nD WEB1V\ً!‫دא‬3 WAP1V3hR1V\‫א‬lWS5Fs53‫ون‬
.:3$I‫€و‬Z–‫_א‬
‫ ؟‬WAP ‫ﻣﺎ ﻫﻮ ال‬
9‫א‬53s‫'وא‬SF‫و‬،Wireless Application ProtocolFPHVI‫א‬SWAPFP!ً7NO‫א‬F
‫ط‬H–Mobiles7N‫א‬o‫'א‬k‫א‬ig%CaH„‘f$gQ\DStanderd‫و‬CH3SWAP‫אن‬cQ‫א‬WS‫!¦ن‬
.
‫م‬VN\‫א‬
‫ن‬7‫א‬
hN
53
^‫א‬
oVN‫א‬
U
lQ'1
”‫و‬
،
€Z–
i‫د‬ON3KFgN3K €t‫وא‬A4P‫'لא‬F[‫א‬h,HP!Ch,$'\‫و''لא‬4‫אא‬WSz%$.‫و‬
.5QIš‫א‬5Do†l{‫א‬U‫و‬
‫ ؟‬WAP ‫ﻛﻴﻒ ﺗﻌﻤﻞ‬
`
qViH‫و‬M‫م‬Q3‫א‬WS‫و‬،'F[‫א‬o‫'א‬k‫א‬hP3‫א‬H‫א‬UKFg] WEB5D WAPF
V+T‫א‬ig%H73'F[‫א‬ig%bœ‫א‬hŽ\‫א‬h‫א‬H$.os‫و‬D‫א‬os03K3‫وא‬h‫א‬
.ًMQCk I53h‫ضא‬DQt‫א‬,T‫`א‬qb‫و‬
591
l{‫א‬Ui$Q!
gN3K€t‫وא‬A4P‫'لא‬F[‫א‬h,h,K‚_”WAP‫אل‬N7‫ ل‬I53‫و‬
.'F[‫א‬gg%CnD€Z9‫א‬h3$I‫ل‬I‫د‬9ًo†
:¦!RObGU‫و‬،:! I‫و‬o\‫و‬C3ROVY3URL‫ل‬KF‫א‬G‫ ل‬I53WAP‫אل‬V.C$‫و‬
WAP ‫و''لאل‬5Fsg3‫א‬$+‫א‬Q HTMLKi&N3‫ض‬D7QS‫ و‬WML „‘ HTML BQ
.‫א‬i7O‫א‬UgTf'‫و‬
...ًMQCHTMLD$€RbC'F[‫א‬o‫'א‬k‫ن™א‬CWQ$Ž‫وא‬
WML
.10.2
U HTML5Do§‫و‬، XML
Q3nDgNP‫ و‬HTML KFD7Q1ً‫א‬$%gT3h‫א‬ob'7QS
:gN3‫ط‬7N‫א‬53‫د‬$D
‫אض‬Kg Cardsh.1„‘$N\‫א‬7NQ − <html>53ً9$ <wml>'Sj‫ א‬Tag'‫א‬−
.</card>~ًMQCgN‫<و‬card>~.1KC$
:−Q$PQ‫و‬53−ً ^3‫א‬KPT‫وذ‬WMLOs'Qً9^3‫ض‬NQ‫א‬$
‫ﻛﻮد‬
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//PHONE.COM//DTD WML 1.1//EN"
"http://www.phone.com/dtd/wml11.dtd" >
<wml>
<card id="main" title="First Card">
<p mode="wrap">This is a sample WML page.</p>
</card>
</wml>
: ‫ﻗﺮاءة اﻟﻘﻴﻢ اﻟﻤﺨﺘﻠﻔﺔ وﺗﺨﺰﻳﻨﻬﺎ وﻋﺮﺿﻬﺎ ﻟﻠﻤﺴﺘﺨﺪم‬
:‫א‬KPTk.‫د‬N‫وא‬h‫
א‬q\‫א‬oQNP>KP
‫ﻛﻮد‬
<setvar name="First_Name" value="Ahmed"/>
<setvar name="Age" value="21"/>
592
:ً ^3‫א‬KPTgsDNP>ً79‫و‬
‫ﻛﻮد‬
<p>First Name: $(First_Name)</p>
.
q\‫אא‬53ً9$i‫אאدא‬0s‫و‬Qً3e7Q1‫@א‬ONSelect‫و‬C*03F.iz‫א‬.ًMQ‫א‬5P>‫و‬
:−‫'ل‬7N3‫^ل‬3–‫م‬$+FgsD‫و‬HI‫א‬i‫دא‬C.iz‫א‬7‫^ل‬3
‫ﻛﻮد‬
<card id="card1" title="Tutorial">
<do type="accept" label="Answer">
<go href="#card2"/>
</do>
<p>
<select name="name">
<option value="HTML">HTML Tutorial</option>
<option value="XML">XML Tutorial</option>
<option value="WAP">WAP Tutorial</option>
</select>
</p>
</card>
<card id="card2" title="Answer">
<p>
You selected: $(name)
</p>
</card> </wml>
WAP + ASP.net .10.3
:‫א‬KPT‫ن‬W‫وא‬−Q$PQ‫و‬53‫'ل‬7N\‫א‬−7\‫ولא‬CUlNsDW‫ˆא‬1‫א‬KQ'RNF.‫‘ذא‬
‫ﻛﻮد‬
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//PHONE.COM//DTD WML 1.1//EN"
"http://www.phone.com/dtd/wml11.dtd" >
<wml>
<card id="main" title="First Card">
<p mode="wrap">This is a sample WML page.</p>
</card> </wml>
593
:‫א‬KPT‫'ن‬PQf'!net.„‘:Q'RNF.‫و‬
‫ﻛﻮد‬
<%@ Page Inherits="System.Mobile.UI.MobilePage" Language="C#" %>
<%@ Register TagPrefix="mobile" Namespace="System.Mobile.UI" %>
<mobile:Form runat="server">
<mobile:Label runat="server">
This is a sample WML page.
</mobile:Label>
</Mobile:Form>
:‫א‬KPTVa7!‫אول‬1‫—
א‬VB.net1‫'א‬K3‫א‬U€—HU
‫ﻛﻮد‬
<%@ Page Inherits="System.Mobile.UI.MobilePage" Language="C#" %>
oS‫ز‬g%53G1‫نא‬Uwml„‘ROV‫א‬KQ'ً9‫و‬CQ،KF‫א‬K.53ROV‫א‬G$ND‫وאšن‬
.O'3'‫و‬CV+,‫ز‬g%530.'\‫א‬GUHTML„‘i,3KQ'R‫א‬Q‫و‬C،‫'ل‬F)
U ‫א א¡ل‬WS U
^P‫ א‬KFD P3 ‫ زאل‬3 5P‫ و‬، NET. ‫ ل‬I 53 WAP ˆ1 ‫^ل‬3 aC ‫א‬WS ‫ن‬
3$7\‫ א‬h‫א‬Hœ‫ א‬53 ‫ و—
ذ‬gP3‫ وא‬ij‫ אא‬ig%‫ א‬nD f‫ א‬U‫ و‬، ً 3'FD 0.'\‫'ع א‬s'3
.ًb'VI
594
Ajax
.11
!‫€ א\و‬Z–‫ א‬N7 h3$I 53 i‫د‬O9‫ א‬O ً Q ‫ض‬N ASP.net ‫
'ل‬I‫س א‬H$‫א א‬WS U
.net .‫ ل‬I53 AJAX AJAX ‫ اﺟﺎﻛﺲ‬.11.1
‫و‬Ci$Q$%q€g!0.‫א'א‬U‫و‬، Asynchronous JavaScript and XML FP HVI‫א‬S
z{ nD @%‫ א‬$F ، ‫ و‬، AIC 7Q1 i‫'د‬%'\‫د א‬H‫'א‬F ‫אم‬$+‫ א‬S 3 H$. i$Q$% N7
‫'ن‬PQ53zŽKF‫א‬G$ND:¦! L‫א‬lWSU‫و‬،i$nD.KŽ3‫م‬.‫א‬i$D„‘ROV‫א‬
.K3PROV‫א‬Q$H(9ً‫א‬1M3
‫و‬ZP–‫א‬$Q4‫א‬53i$Q$Ž‫ א‬+N‫!‘„א‬s‫ א‬Gmail ‫و‬ZP–‫א‬$Q4‫'א‬S AJAX ‫אم‬$+‫^א‬3Cg,CK‫و‬
. Hotmail ‫ و‬Yahoo ~
:N7‫א‬lWS5DQ$PQ‫و‬RObiHQ‫ز‬01 }H$Q\‫\!א‬
‫رابط‬
http://en.wikipedia.org/wiki/Ajax_%28programming%29
‫ ؟‬.net ‫ﻛﻴﻒ أﺑﺪأ ﻣﻦ ﺧﻼل‬
U \‫ א‬h‫א‬F\‫ א‬nD ‫'ل‬VL‫ א‬Kg‫ و‬¤$D t‫ א‬h‫ אدوא‬53 ¢ i$D H‫א‬$b €!'‫و‬PQ3 €3.
Atlas nFQ3‫אم‬$+‫و‬C،ًQ‫و‬$QlH'baCU3‫א א‬Wg‫م‬7‫א‬01‫ل‬Q‫א‬nDNP،AJAX
. AJAX XbI€!'‫و‬PQ3 53+S‫و‬
595
h‫ אدوא‬53 D'F S‫ و‬، Asp.net Ajax ToolKit H‫א‬$b €!'‫و‬PQ3 €3. Kg‫ א‬53 $QF‫و‬
a‫אאא‬WS‫ ل‬I 53gs‫אא‬5P>t‫א‬O+\‫א‬
‫رابط‬
http://ajax.asp.net/ajaxtoolkit/
:a‫ لאא‬I53h‫אدوא‬lWSKF‫ و‬0.'\‫א‬iHQ‫ز‬01
‫رابط‬
http://ajax.asp.net/
4Dg‘‫'ل‬b'‫א‬5P>،ً3'FD Asp.net ‫ول‬h‫אدوא‬lWkF‫ א\'אدא‬53F+sP30.'\‫'!א‬QF
:a‫א אא‬WS
‫رابط‬
http://www.asp.net/learn/default.aspx?tabid=63
:‫ ًא‬$Q$'Q$O‫אא‬WS‫ ل‬I53z$‫ א‬NP>
‫رابط‬
http://download.microsoft.com/downlo...List-Video.zip
. Atlas ‫אم‬$+‫א‬O5DQ‫א‬$‫א‬WN3vT ‫'م‬7‫و‬
:'Q$O‫אא‬WSgN3i,3 Ajax ToolKit ‫אم‬$+z$‫ א‬OvTAIC‫وس‬H‫د‬¤NS‫و‬
‫رابط‬
http://www.asp.net/learn/videos/view...tabid=63&id=75
http://www.asp.net/learn/videos/view...tabid=63&id=76
...‫אول‬N71KFDUC$N ،‫وאšن‬
596
‹53‫و‬،ROV‫א‬Q$Fe01iH'b!s.ًMQ‫ א‬،L‫€א‬.'‫א‬:!‫*ض‬03KFDX%
: 3‫א‬H‫ز‬U ‫'دא‬P‫א‬P.
C#
TextBox1.Text = DateTime.Now.ToString();
‫ﻛﻮد‬
VB
TextBox1.Text = DateTime.Now.ToString()
‫ﻛﻮد‬
Q 9 r z$\‫@ א‬O ˆ1 ‫ول‬RN ‫ אšن‬، K3P ROV‫ א‬Q$ Q KO ، E$d 3 €(9 KS
. :!KQ$‫א‬W‫א‬zŽ‫ א‬nDA'
‹]‫א‬
:‫א‬KPT@%‫ א‬h‫אدوא‬5Fs53 ScriptManager !sQ‫א‬$.‫א‬W
، ‫ج‬Hœ‫ א‬U a7! iH'V‫ א‬¤ 03 gI‫א‬$3‫א‬H‫* وز‬N‫ א‬03 0s' .‫ و‬، UpdatePanel GR . ‫אšن‬
:‫א‬KPTROV‫'ن'دא‬P
‫ﻛﻮد‬
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx.cs"
Inherits="Default6" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
597
<form id="form1" runat="server">
<div>
<img src="images/food.jpg" />
<asp:UpdatePanel runat="server"><ContentTemplate>
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="ShowTime" />
</ContentTemplate></asp:UpdatePanel>
</div>
</form>
</body>
</html>
‫ق! ً؟؟‬HO‫(€א‬9 KS،X%‫وאšن‬
update panel ‫ج אل‬HI39‫א‬H‫ ز‬0s‫ و‬$Q N‫ א‬NsZ!‫ذא 'א‬3IŠ ‫'ع‬s'3 ˆ1 ‫ول‬RN ‫ אšن‬، KB
.5PŸ‫א‬WS،:^Q$Q9r
: update panel ‫ אل‬KI‫'دאدא‬P‫א‬P.‫و‬، update Panel ‫جאل‬HI3‫א‬H‫ز‬GR‫א‬a7!
‫ﻛﻮد‬
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
:‫א‬KPTً 3‫'د‬P‫ א‬V
‫ﻛﻮد‬
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx.cs"
Inherits="Default6" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
598
<img src="images/food.jpg" />
<asp:UpdatePanel runat="server"><ContentTemplate>
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="ShowTime" />
</div>
</form>
</body>
</html>
‫؟‬AIC i3‫ق‬HO‫(€א‬9KS
:‫ﻋﻮدة ﻟﻘﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت‬
‫א‬K7UF.‫א‬0s‫و‬X%‫و‬،ROV‫ א‬UiH'b0s‫و‬X%،h‫א‬$D‫'א‬.‫
'ل‬I‫א‬N71‫'د‬N
. Enter nDaqM.‫و‬nV.‫א‬
‫ل אل‬1Q Q$R‫ א‬K`N ‫ א‬N71 U ، K3P ROV‫ א‬Q$ Q ً MQ‫ א‬، E$d 3 €(9 KS
. :Q').‹]‫ن‬C‫دون‬a7!GridView
os‫‹א‬53‫و‬،3‫א‬H‫ز‬os‫א‬، GridView ‫אل‬g!0s‫و‬، update panel 0s ،lN%Fً‫א‬$%a‫'ع‬s'\‫א‬
:‫א‬KPTK3P‫'دא‬P‫א‬V،s\‫سא‬H$‫א‬U‫ 'د‬F Triggers ‫אل‬
‫ﻛﻮد‬
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs"
Inherits="Default5" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
599
<body>
<form id="form1" runat="server">
<center>
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ItemsConnectionString %>"
SelectCommand="SELECT * FROM [Items] WHERE ([ItemPrice] &lt;
@ItemPrice)">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" DefaultValue="0"
Name="ItemPrice"
PropertyName="Text" Type="Int64" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
&nbsp;<asp:TextBox ID="TextBox1" runat="server">1000</asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="€0jM‫א‬5DR‫א‬
"></asp:Label>
<br />
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePartialRendering="true">
</asp:ScriptManager>
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="SqlDataSource1" AllowPaging="True"
AllowSorting="True"
AutoGenerateDeleteButton="True" AutoGenerateEditButton="True"
AutoGenerateSelectButton="True" BackColor="White" BorderColor="#E7E7FF"
BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID"
InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="ItemName" HeaderText="ItemName"
SortExpression="ItemName" />
<asp:BoundField DataField="ItemPrice" HeaderText="ItemPrice"
600
SortExpression="ItemPrice" />
<asp:BoundField DataField="ItemPicture" HeaderText="ItemPicture"
SortExpression="ItemPicture" />
</Columns>
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C"
HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True"
ForeColor="#F7F7F7" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True"
ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger EventName="Click" ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
<br />
<br />
<br />
</div>
</center>
</form>
</body>
</html>
.‫ق‬HO‫א‬ª9‫و‬،ROV‫` א‬.a7!‫אšن‬
: AJAX Toolkit
‫ אאض‬NP> ، AJAX ¨‫د‬3 ˆ1 nD ¤$D t‫ א‬h‫ אدوא‬53 B D'F €!'‫و‬PQ3 !'
:NS3$7\‫א‬h‫دوא‬9‫א‬
‫رابط‬
http://www.asp.net/ajax/ajaxcontroltoolkit/samples/
:NSS${،F‫א‬hS'Q$O‫ˆא‬Q5Dg!i$‫אوא‬5Dz,K!3 NP>
‫رابط‬
http://www.asp.net/ajax/ajaxcontroltoolkit/
601
‫ﺧﺎﺗﻤﺔ اﻟﻜﺘﺎب‬
602
_DU‫طא‬7N‫א‬nD'dW‫ وא‬.net 2008_D03N'%QgNNb‫و‬$.‫'ن‬P$L‫אא‬WS„‘
.
QzT'‫א\!و‬i‫د‬Q‫ز‬U€FS$.‫'ن‬C‫ن‬C‫אًو‬$O3‫'ن‬PQ‫ن‬C‫א‬53'%HC،.net 2008
:‫و‬ZP–‫א‬t‫و‬$3nDXP‫א‬RObˆQ5DXP‫א‬+IŠnD‫א– ع‬b‫'א‬3NP>
www.AhmedGamal-Technical.blogspot.com
]1In‫و‬C3'\‫א‬U‫و‬C‫'د‬P‫א‬U]1ICh$%‫ ً'و‬M!،QgN‫א‬UHC‫'دو‬DCQ‫א‬$‫א‬Uh‫ذ‬F‫و‬
Q$ ‫ ًא ' ن‬$ ‫ ً ]'ن‬MQ‫ א‬، ‫و‬ZP–‫ א‬$Q nD : c‫א‬H ' i‫ אد‬Q— U ‫ !]'ن‬j 3‘
.XP‫אא‬WS537\‫א‬¢N‫א‬Y‫و‬Q'1h‫א‬Z.‫א‬
.XP‫אא‬WSUcFD‫ود‬C$D‫و‬CS53KPAICi3P,HC
.Y\‫א‬XH$FL‫وא‬
.YBC:Rb‫و‬:ŠnD‫و‬$F)NnD‫א‬nb‫و‬
‫اﻟﻤﺼﺎدر‬
603
.Pro C# 2008X−
Pro C# 2008 and the .NET 3.5 Platform, Exploring the .NET universe using curly
brackets.
Aouther: Andrew Troelsen.
Edition: Fourth Edition
.MSDN−
MSDN – Microsft Developer Network,
http://msdn2.microsoft.com/en-us/default.aspx
.X‫!`'אل‬A$N353.O3h973−
http://www.vb4arab.com
.4‫ˆא‬QO‫א‬A$N353.O3h973−
http://www.arabteam2000-forum.com/
604
605