• Save
Www.kutub.info 9671
Upcoming SlideShare
Loading in...5
×
 

Www.kutub.info 9671

on

  • 5,689 views

 

Statistics

Views

Total Views
5,689
Views on SlideShare
5,689
Embed Views
0

Actions

Likes
1
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Www.kutub.info 9671 Www.kutub.info 9671 Document Transcript

  • OK1
  • 2
  • ‫ﻮة ﻄﻮة ﻣﻊ‬ ‫ﺧﻄﻮ ﺑﺨﻄ ﻊ‬ ‫ﻓﻴ ﻮﺍﻝ ﺳﺘﻮ ﻮ 002‬ ‫‪Mic‬‬ ‫ﻮﺩﻳﻮ 80‬ ‫ ‬ ‫ ‪crosoft‬‬ ‫ﻴﺠﻮ‬ ‫800 ‪Visu tud‬‬ ‫8 02 ‪V ual St dio‬‬ ‫ ‬ ‫ ‬ ‫ ‬ ‫‪  C# And V‬‬ ‫‪VB.net‬‬ ‫ ‬ ‫ ‬‫أ ﻤﺪ ﺟﻤﺎﺎل ﻠﻴﻔﺔ‬ ‫ﺧﻠ‬ ‫ﺣﻤ‬‫3‬
  • 4
  • ‫ﺎب‬ ‫ﻳﻢ اﻟﻜﺘﺎ‬ ‫ﺗﻘﺪﻳ‬‫ﺑﻘﻠﻢ ﺳﺘﺎذ ﻲ اﻟﻌﺴﻴﺮي‬ ‫اﻷﺳ ﺗﺮﻛﻲ‬ ‫استطيع أن أقول ك شخص حظوظ جدا حماتك فعال تحبك، حيث انك‬ ‫ت‬ ‫وح‬ ‫مح‬ ‫انك‬ ‫رمج‬ ‫مج )حقيقي( وليس مبر‬ ‫‪ .NET Framew‬من مبرم‬ ‫ستتعلم برمجة ‪work‬‬ ‫ه ال تتعدى تابة برامج ضعة سطور حل أسئلة ختبار‬ ‫اخ‬ ‫لح‬ ‫ببض‬ ‫كت‬ ‫أكاديمي نطاق انجازاته‬ ‫أو واجب عملي، فانا أتحدث عن حمد جمال وھو من كبار المحترفين عرب‬ ‫الع‬ ‫أح‬‫قع ‪ vb4arab‬والذي يمثل‬ ‫و‬ ‫والذي ه بصماته في مشاريع ي تتحدث عنه، ويكفينا را بأنه المسئو‬ ‫ول األول لموق‬ ‫فخر‬ ‫ھي‬ ‫له‬ ‫ن العرب حول العالم.‬ ‫مع للمبرمجين‬‫اكبر مجتم‬ ‫د جمال دقته في اختيار لكم المعرفي للتحدث ه، خاصة وسط‬‫ط ھذا الكم‬ ‫عنه‬ ‫ال‬ ‫ي كثيرا في أسلوب احمد‬ ‫ما يعجبني‬‫ما ما يحتاجه المبرمج وما ال يحتاجه،‬‫ماتي وكثرة لمستندات، فھو يعرف تمام‬ ‫ف‬ ‫ال‬ ‫العددي الھائل من االنفجار المعلوم‬‫‪(Source Co‬‬‫ويعلم يدا من أين ؤكل الكتف كيف ترمى عظام، إما عن جواھره ) صد شفراته مصدرية ‪odes‬‬ ‫الم‬ ‫اقص‬ ‫الع‬ ‫وك‬ ‫تؤ‬ ‫جي‬‫يقية ‪Real World Cases‬‬ ‫‪d‬‬ ‫ي الكثير من الحاالت الحقي‬ ‫ة التي يع ھا بحيث تغطي‬ ‫رضھ‬ ‫ن ويبدع في اختيار األمثلة‬ ‫فھو يتفنن‬ ‫ي بذكر أمثلة تشرح الفكرة فقط.‬ ‫ت‬ ‫ج عاجال أم جال، وال يكتفي‬ ‫أج‬ ‫والتي ستظھر للمبرمج‬ ‫س‬‫كم الطريفة: "من الصعب ن تجد قطة سوداء.. في قاعة صماء .. وخصوصا إن‬ ‫ق‬ ‫س‬ ‫أن‬ ‫ل إحدى الحك‬‫بخصوص الكتاب، فتقول‬‫ل انه "من صعب أن د أفضل لغة‬ ‫تجد‬ ‫الص‬ ‫ھا بموضوعنا يمكن أن نقول‬ ‫ي‬ ‫لم يكن ھنالك قطة خير شر!" وكمحاولة لربطھ‬ ‫م‬ ‫خ‬ ‫ھ‬‫ة خير شر!"‬‫‪ (.N‬في ظل ھذا الزخم ن اللغات .. خصوصا إن لم يكون ھنالك أي لغة برمجة‬ ‫أ‬ ‫وخ‬ ‫من‬ ‫ھ‬ ‫برمجة )موجھة لـ ‪NET‬‬ ‫م‬‫لھا، أصبح حديث في ذه األيام عن‬ ‫ھذ‬ ‫الح‬ ‫فمن بعد ما كانت ت البرمجة لغات حقيقية ستقلة لھا سماتھا وشمائل‬ ‫س‬ ‫مس‬ ‫لغات‬‫د أن تكون ت البرمجة شبيھة فيما نھا إلى حد‬ ‫بين‬ ‫ش‬ ‫لغات‬ ‫تقنيات )‪ ،(...LIN ،WPF ،DirectX ،COM ،.NET ،Java‬وتكاد‬ ‫‪NQ‬‬ ‫‪a‬‬‫اب –بناء على مقدمته- اعتمد على‬ ‫ى‬ ‫تب ھذا الكتا‬‫كبير، ھذا الكتاب ير دليل ى صحة ما ميت به، فكات‬ ‫رم‬ ‫على‬ ‫خي‬ ‫وھ‬‫ية ‪ ،.NET‬س ھذا فقط‬ ‫ليس‬ ‫ن من كتابة كتاب حول تقني‬ ‫ك‬ ‫فة )#‪... ،VB،C‬الخ( ليتمكن‬ ‫.‬ ‫مجموعة كتب تتحدث بلغات مختلف‬ ‫ت المصدرية بأكثر من لغة!‬ ‫ب‬ ‫بل يقدم شرح الشفرات‬ ‫ومن ھذا المنطلق ن االختيار ) ذكي جدا( ن الكاتب لعنو‬‫وان الكتاب 002 ‪ Visual Studio‬دون حديد اللغة،‬ ‫تح‬ ‫‪l‬‬ ‫80‬ ‫من‬ ‫الذ‬ ‫كان‬‫ن( وأصبحنا‬‫دنا )نحن شر المبرمجين‬ ‫معش‬ ‫‪ B‬أو مبرمج #‪ ،C‬فقد توحد‬ ‫#‬ ‫فال يوجد بعد اليوم صطلح اسمه مبرمج ‪Basic‬‬ ‫مص‬ ‫جي.‪."NET‬‬‫جميعا تمي إلى لة " آل مبرمج‬ ‫عائل‬ ‫ننت‬‫ية.‪ ،NET‬ومن ثم يأخذ بك جولة إلى مواضيع متفرقة مثل برمجة‬ ‫يغطي ھذا الكتاب ز المواضيع األساسية لتنقي‬ ‫ابرز‬ ‫ھ‬‫مجة ويب. كما سيسيل كاتب لعابك‬ ‫الك‬ ‫ما‬ ‫ج ‪ ،Window Forms‬وبرم‬ ‫‪ws‬‬ ‫‪ ،Database Program‬نماذج‬ ‫قواعد بيانات ‪mming‬‬ ‫الب‬‫ديدة )والتي ظھرت مع اإلصدار الثالث من إطار لعمل. ‪NET‬‬ ‫ال‬ ‫ث‬ ‫دما تعلم انه لم يتجاھل التقنيات الجد‬‫أكثر عند‬‫‪ ،Data Entit‬وتقنية ‪ WPF‬والتي تمثل‬ ‫و‬ ‫و‬ ‫ل المتقدم مع البيانات ‪ties‬‬ ‫‪ (Framework‬مثل نية ‪ LINQ‬موجه للتعامل‬ ‫الم‬ ‫تقن‬‫5‬
  • ‫الجيل القادم لبرمجة واجھات االستخدام قابلة للنقل ‪ ،Portable User Interfaces‬وتقنية ‪ WCF‬والتي توفر حلوال‬‫أكثر إنتاجية للتطبيقات الموزعة ‪ .Distributed Applications‬وھذه مواضيع من النادر جدا أن يستطيع شخص‬ ‫دمجھا في كتاب واحد.‬‫أخيرا، قد تكون ارتكبت خطأ في قراءة ھذا التقديم )الذي ال يسمن وال يغني من جوع ولن يوفي حق الكتاب‬‫ثم ابدأ بقلب الصفحة لتدخل عالم‬ ‫ومؤلفه(، لذلك يكفي ما أضعته من وقتك الثمين معي واستعن با‬ ‫برمجة.‪ NET‬من أوسع أبوابھا.‬ ‫-- تركي العسيري‬ ‫‪al-asiri.COM‬‬‫6‬
  • ‫ﻔﻬﺮس‬ ‫اﻟﻔ س‬ ‫‪ al-asiri.C‬ﻣﺔ اﻟﻜﺘﺎب‬ ‫ﻣﻘﺪﻣ‬ ‫‪CO‬‬‫72‬‫2‬ ‫..............................................‬ ‫..............‬ ‫..............‬ ‫ﻧﺒﺬة ﻋﻦ ﺆﻟﻒ .....................‬ ‫اﻟﻤﺆ‬‫........... ..................... 2‬‫92‬ ‫...‬ ‫ﻫﺬا اﻟﻜﺘﺎب ...................................................‬ ‫..............‬‫.................................. 3‬‫03‬ ‫..............‬ ‫ﻣﺤﺘﻮﻳﺎت ﻜﺘﺎب .................................‬ ‫..............‬ ‫اﻟﻜ‬‫ﻚ اﻷوﻟﻰ ﻣﻦ ﻓﻴﺠﻮال ﺳﺘﻮدﻳﻮ 8002 ............................................... 3‬‫53‬ ‫• اﻟﺒﺎب 20 ﺗﺤﻤﻴﻞ ﻧﺴﺨﺘﻚ‬ ‫ﺗ‬ ‫• اﻟﺒﺎب 30 اﻟﺠﺪﻳﺪ ﻣﻊ ال 8002 ‪............................................................... .NET‬‬‫........ 4‬‫24‬‫........ 5‬‫55‬ ‫...........................‬ ‫.‬ ‫• اﻟﺒﺎب 40 ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ‪ .net‬اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ﺔ .....................................‬ ‫‪t‬‬ ‫ﻣ‬‫..................... 7‬‫47‬ ‫........... ..............‬ ‫...‬ ‫‪..... Visual‬‬ ‫• اﻟﺒﺎب 50 اﻟﻮاﺟﻬﺔ اﻷﺳﺎﺳﻴﺔ ﻟﻞ 02 ‪l Studio‬‬ ‫800‬‫68‬‫8‬ ‫• اﻟﺒﺎب 60 ﻣﻜﻮﻧﺎت ﺔ اﻟﺮﺋﻴﺴﻴﺔ ﻲ ‪ .net‬اﻟﺠﺰء اﻷول ....................................................‬ ‫ﻓﻲ‬ ‫اﻟﻠﻐﺔ‬ ‫ﻣ‬ ‫• اﻟﺒﺎب 70 ﻣﻜﻮﻧﺎت ﺔ اﻟﺮﺋﻴﺴﻴﺔ ﻲ ‪ .net‬اﻟﺠﺰء اﻟﺜﺎﻧﻲ .......‬‫.............................................. 011‬ ‫ﻓﻲ‬ ‫اﻟﻠﻐﺔ‬ ‫ﻣ‬‫• اﻟﺒﺎب 80 ﻣﻘﺪﻣﺔ إﻟﻰ ﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ ااﻟﺘﻮﺟﻪ ‪142 .......................................................... OOP‬‬ ‫اﻟﺒﺮ‬ ‫ﻣ‬‫......... ..................... 081‬ ‫.....‬ ‫• اﻟﺒﺎب 90 ‪ – Interfaces‬اﻟﻮاﺟﻬﺎت ..........................‬ ‫..............‬ ‫‪s‬‬‫......... ............ ..................... 691‬ ‫..‬ ‫.....‬ ‫• اﻟﺒﺎب 01 اﻷﺧﻄﺎء واﻗﺘﻨﺎﺎﺻﻬﺎ .................................‬ ‫• اﻟﺒﺎب 11 اﻟﺘﺠﻤﻴﻌﺎت ‪................................................................. Collection‬‬‫........ 012‬ ‫.‬ ‫‪ns‬‬‫........ 422‬ ‫..............‬ ‫2 ‪............................................ .net‬‬‫• اﻟﺒﺎب 21 اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ 8002‬‫........ 292‬ ‫‪.............................. Syst‬‬ ‫..............‬ ‫• اﻟﺒﺎب 31 اﻻدﺧﺎل و ﺧﺮاج ﻓﻲ ‪tem.IO .net‬‬ ‫اﻻﺧ‬ ‫• اﻟﺒﺎب 41 ﺑﺮﻣﺠﺔ اﻟﻨﻮاﻓﺬ ﻓﻲ ال ‪.............. Windows Forms .net‬‬‫.................................. 323‬ ‫....‬ ‫ﺑ‬‫..................... 273‬ ‫..............‬ ‫• اﻟﺒﺎب 51 ‪............................................ +GDI‬‬ ‫..............‬‫.......... ..................... 483‬ ‫....‬ ‫..............‬ ‫‪....... Windows Presentation F‬‬ ‫• اﻟﺒﺎب 61 ‪Foundation‬‬ ‫‪n‬‬‫........ 934‬‫4‬ ‫ت ﺑﺎﺳﺘﺨﺪام ‪......................................... ADO.net‬‬ ‫..............‬ ‫• اﻟﺒﺎب 71 ﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت‬ ‫ﻗ‬‫........ 805‬ ‫..............‬ ‫• اﻟﺒﺎب 81 ‪.......................................................... LINQ‬‬ ‫..............‬ ‫‪Q‬‬‫........ 135‬ ‫.................................................................‬ ‫• اﻟﺒﺎب 91 ‪.......WWF‬‬ ‫..............‬ ‫‪F‬‬‫........ 245‬ ‫.................................................................‬ ‫• اﻟﺒﺎب 02 ‪....... WCF‬‬ ‫..............‬ ‫‪F‬‬‫........ 555‬‫.................................................................‬ ‫• اﻟﺒﺎب 12 ﻧﻘﺎط ﻣﺘﻘﺪﻣﺔ..............‬ ‫ﻧ‬‫............................................... 775‬‫• اﻟﺒﺎب 22 ﺗﻄﻮﻳﺮ اﻟﻤﻮاﻗﻊ ﺑﺎﺳﺘﺨﺪام ‪.............. ASP.ne‬‬ ‫....‬ ‫‪et‬‬ ‫ﺗ‬‫..................... 746‬‫..............‬ ‫ﺗﻤﺔ اﻟﻜﺘﺎب، وﺷﻜﺮ .............................................‬ ‫..............‬ ‫و‬ ‫ﺧﺎﺗ‬‫.............................................. 846‬ ‫ﺼﺎدر .............................. ..............‬ ‫..............‬ ‫...‬ ‫اﻟﻤﺼ‬ ‫7‬
  • 8
  •   9
  • ‫ﻤﺤـﺘ ــﺎت‬ ‫اﻟﻤ ﺘــﻮﻳــ ت‬ ‫ ‬ ‫ ‬‫ب ................................................................................................................... 52‬ ‫5‬ ‫ﻣﻘﺪﻣﺔ اﻟﻜﺘﺎب‬‫ﻧﺒﺬة ﻋﻦ ااﻟﻤﺆﻟﻒ ............................................................................................................. 72‬ ‫7‬‫............. 92‬ ‫9‬ ‫................‬ ‫................‬ ‫................‬ ‫................‬ ‫ب ........ ................‬ ‫................‬ ‫....‬ ‫ﻫﺬا اﻟﻜﺘﺎب‬‫............. 03‬ ‫0‬ ‫................‬ ‫................‬ ‫................‬ ‫................‬ ‫................‬ ‫ﻣﺤﺘﻮﻳﺎت اﻟﻜﺘﺎب ......‬ ‫................‬ ‫ﺗﺤﻤﻴﻞ ﻧﺴﺨﺘﻚ اﻷوﻟﻰ ﻣﻦ ﻓﻴﺠﻮال ﺳﺘﻮدﻳﻮ 002‬ ‫80‬ ‫ﺳ‬ ‫ااﻟﺒﺎب 20‬‫........... 73‬ ‫7‬ ‫..............‬ ‫..............‬ ‫1.اﻟﻨﺴﺨﺔ اﻟﻜﺎﻣﻠﺔ ﻣﻦ 8002 ‪tudio‬‬ ‫‪............................ Visual St‬‬ ‫8‬‫........................ 83‬ ‫8‬ ‫..............‬ ‫..............‬ ‫2.اﻟﻨﺴﺦ ﻟﻤﺠﺎﻧﻴﺔ ﻣﻦ 8002 ‪Studio‬‬ ‫‪................ Visual S‬‬ ‫اﻟ‬ ‫9‬ ‫3.ﺗﺮﻗﻴﺔ ﺸﺮوﻋﻚ اﻟﺬي ﻳﻌﻤﻞ ﻋﻠﻰ ل 5002 ‪ VS‬إﻟﻰ 8002 ‪VS‬‬‫‪39 .............................................. V‬‬ ‫ال‬ ‫ﻣﺸ‬ ‫002 ‪  .NET‬‬ ‫80‬ ‫اﻟﺠﺪﻳﺪ ﻣﻊ ال‬ ‫ااﻟﺒﺎب 30‬‫.............................................................. 44‬ ‫4‬ ‫1.ﺗﻘﻨﻴﺔ ‪.............. Silverligh‬‬ ‫..............‬ ‫.‬ ‫‪ht‬‬‫...................... 64‬ ‫6‬ ‫..............‬ ‫2.ﺗﻘﻨﻴﺔ ‪.............................................. LINQ‬‬ ‫..............‬ ‫‪Q‬‬‫......... 74‬ ‫7‬ ‫..............................................................................‬‫3.ﺗﻘﻨﻴﺔ ‪........ WPF‬‬‫.............................................................. 94‬ ‫9‬ ‫4.ﻣﺠﻤﻮﻋﺔ ‪........... Expression‬‬ ‫..............‬‫......... 15‬ ‫1‬ ‫..............‬ ‫5.ﺗﻘﻨﻴﺔ ‪........ WCF‬‬ ‫.................................................................‬‫.............................................................. 15‬ ‫1‬ ‫..............‬ ‫‪........... C‬‬ ‫6.‪ctoring‬‬ ‫‪Code Refac‬‬ ‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ‪ .net‬ﻟﺮﺋﻴﺴﻴﺔ‬ ‫اﻟ‬ ‫ااﻟﺒﺎب 40‬ ‫7‬ ‫.................................................................‬‫........... 75‬ ‫1.ﻟﻐﺎت ‪......... .ne‬‬ ‫..............‬ ‫‪et‬‬‫........................ 95‬ ‫9‬ ‫..............‬ ‫2.اﻟﻌﻨﺎﺻﺮ اﻷﺳﺎﺳﻴﺔ ﻴﺌﺔ ‪............................. .net‬‬ ‫..............‬ ‫ﻟﺒﻴ‬‫................................................. 06‬ ‫0‬ ‫..............‬ ‫..............‬ ‫‪....... Base‬‬ ‫3.ال ‪rary‬‬ ‫‪e Class Libr‬‬‫.............................................................. 16‬ ‫1‬ ‫..............‬ ‫‪............. .net Assem‬‬‫4.‪mblies‬‬‫.............................................................. 26‬ ‫2‬ ‫..............‬ ‫5.ال ‪............. CIL‬‬ ‫..............‬‫................................................. 36‬ ‫3‬ ‫..............‬ ‫‪.............................. Metad‬‬ ‫6.ال ‪data‬‬‫.................................................. 46‬ ‫4‬ ‫‪............................................ Manif‬‬ ‫7.ال ‪fest‬‬‫........... 46‬ ‫4‬ ‫..............‬ ‫‪........................................... Comm‬‬ ‫..............‬ ‫8.‪mon Type System‬‬‫........... 66‬ ‫6‬ ‫..............‬ ‫..............‬ ‫8.1. ‪TS Membe‬‬ ‫‪................................................. CT‬‬ ‫‪ers‬‬ ‫01‬
  • ‫ ‬ ‫ ‬ ‫ﻣﺤﺘﻮﻳﺎت اﻟﻜﺘﺎب‬‫8.2. ‪66 ................................................................................... CTS Data Types‬‬‫9.‪67 .................................................................. Common Language Specification‬‬‫01.‪68 ....................................................................... Common Language RunTime‬‬‫11.اﺳﺘﺨﺪام ‪69 ...............................................................................Object Browser‬‬‫21.ﻣﺠﺎﻻت اﻷﺳﻤﺎء ‪70 ........................................................................... Name Space‬‬‫21.1. اﺳﺘﻴﺮاد ﻣﺠﺎﻻت اﻷﺳﻤﺎء .............................................................................. 07‬‫31.اﺳﺘﺨﺪام ﺑﺮﻧﺎﻣﺞ ‪71 ................................................................................... ildasm‬‬‫41.ﻫﻞ ﺗﺒﺤﺚ ﻋﻦ ‪72 ....................................................................... open source .net‬‬ ‫اﻟﻮاﺟﻬﺔ اﻷﺳﺎﺳﻴﺔ ﻟﻠﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ 8002‬ ‫اﻟﺒﺎب 50‬‫1.ﻛﻴﻒ اﻛﺘﺐ اﻟﻜﻮد ؟ ....................................................................................... 67‬‫1.1. اﺳﺘﺨﺪام ‪76 ............................................. Visual Studio 2008 Command Prompt‬‬‫1.2. اﺳﺘﺨﺪام ال ‪78 ................................................................................ TextPad‬‬‫1.3. اﺳﺘﺨﺪام ++‪80 ............................................................................... Notepad‬‬‫1.4. ‪81 ..................................................................................... SharpDevelop‬‬‫2.اﻟﺒﺪاﻳﺔ ﻣﻊ 8002 ‪82 ......................................................................... Visual Studio‬‬‫2.1. ﺑﺮﻧﺎﻣﺠﻚ اﻷول ......................................................................................... 38‬ ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ اﻟﺠﺰء اﻷول‬ ‫اﻟﺒﺎب 60‬‫1.ﺧﺼﺎﺋﺺ ‪88 .................................................................................... Console‬‬‫2.ﺗﻌﺮﻳﻒ اﻟﻤﺘﻐﻴﺮات ........................................................................................... 09‬‫2.1. أﻧﻮاع اﻟﻤﺘﻐﻴﺮات ........................................................................................ 19‬‫2.2. اﻟﺜﻮاﺑﺖ ‪91 ................................................................................... Constant‬‬‫2.3. اﻟﻘﻴﻢ ﻟﻠﻘﺮاءة ﻓﻘﻂ ‪92 ................................................................ Read Only Field‬‬‫3.اﻟﻤﺘﻐﻴﺮات اﻟﻨﺼﻴﺔ ‪93 ............................................................................. String‬‬‫3.1. اﻟﺨﺼﺎﺋﺺ واﻟﺪوال اﻷﺳﺎﺳﻴﺔ ﻟﻞ ‪93 ......................................................... String‬‬‫3.2. ﺗﻘﺴﻴﻢ اﻟﻨﺼﻮص ...................................................................................... 49‬‫3.3. دﻣﺞ اﻟﻨﺼﻮص ......................................................................................... 49‬‫3.4. ﻣﻘﺎرﻧﺔ اﻟﻨﺼﻮص ....................................................................................... 49‬‫3.5. ‪ – Escape Characters‬ﺳﻲ ﺷﺎرب ﻓﻘﻂ ........................................................... 59‬ ‫11‬
  • ‫3.6. اﻟﺘﺤﻮﻳﻞ ﻣﻦ وإﻟﻰ ‪95 ......................................................................... String‬‬‫3.7. ‪96 ............................................................................. StringBuilder‬‬‫4.اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﺘﺎرﻳﺦ واﻟﻮﻗﺖ .................................................................................. 89‬‫5.اﻟﺘﺤﻮﻳﻞ ﺑﻴﻦ اﻟﻤﺘﻐﻴﺮات اﻟﻤﺨﺘﻠﻔﺔ ............................................................................ 89‬‫5.1. ‪99 .......................................................................... Widening Conversions‬‬‫5.2. ‪99 ......................................................................... Narrowing Conversions‬‬‫5.3. ﻋﻤﻠﻴﺎت ال ‪100 ...................................................................................... Cast‬‬‫5.4. اﻟﺘﺤﻮﻳﻞ ﺑﺎﺳﺘﺨﺪام ‪101 ...................................................................... Convert‬‬‫6.اﻟﺠﻤﻞ اﻟﺸﺮﻃﻴﺔ ﻓﻲ ‪101 .................................................................................. .net‬‬‫6.1. أﺳﺎﺳﻴﺎت اﻟﺸﺮوط .................................................................................... 101‬‫6.2. دﻣﺞ اﻟﺸﺮوط .......................................................................................... 301‬‫6.3. ‪103 ........................................................................................ AndAlso‬‬‫6.4. ‪105 .......................................................................................... OrElse‬‬‫6.5. اﺳﺘﺨﺪام ال ‪105 ............................................................................... switch‬‬‫7.اﻟﺤﻠﻘﺎت اﻟﺘﻜﺮارﻳﺔ .......................................................................................... 601‬‫7.1. ‪106 ......................................................................... For - Next Loop‬‬‫7.2. ‪107 ................................................................................... While Loop‬‬‫7.3. ‪108 ............................................................................. For Each Loop‬‬ ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ ﻓﻲ ‪ – .net‬اﻟﺠﺰء اﻟﺜﺎﻧﻲ‬ ‫اﻟﺒﺎب 70‬‫1.ﻟﻨﻔﻬﻢ ﺑﺮﻧﺎﻣﺠﻨﺎ اﻷول ........................................................................................ 211‬‫2.اﻟﺪوال ‪116 ......................................................................................... Function‬‬‫3.اﻟﻄﺮق ‪117 ......................................................................................... Methods‬‬‫4.اﻟﻮﻇﻴﻔﺔ ‪117 ............................................................................................. out‬‬‫5.اﻹرﺳﺎل ﺑﺎﻟﻤﺮﺟﻊ ‪ byref‬واﻹرﺳﺎل ﺑﺎﻟﻘﻴﻤﺔ ‪118 ..................................................... byval‬‬‫6.اﻟﻤﺼﻔﻮﻓﺎت ................................................................................................ 021‬‫6.1. ﻣﺎ ﻫﻲ اﻟﻤﺼﻔﻮﻓﺎت ‪121 .......................................................................... Arrays‬‬‫6.2. ﺗﻜﻮﻳﻦ اﻟﻤﺼﻔﻮﻓﺎت ................................................................................... 121‬‫6.3. اﻟﻤﺼﻔﻮﻓﺎت ﻣﺘﻌﺪدة اﻷﺑﻌﺎد ........................................................................... 121‬ ‫21‬
  • ‫6.4. ﻋﻤﻞ ﻣﺼﻔﻮﻓﺔ ﻣﻦ اﻟﻤﺼﻔﻮﻓﺎت ........................................................................ 221‬‫6.5. إرﺳﺎل واﺳﺘﻘﺒﺎل اﻟﻤﺼﻔﻮﻓﺎت ﻣﻦ وإﻟﻰ اﻟﺪوال .......................................................... 321‬‫6.6. ﺧﺼﺎﺋﺺ اﻟﻤﺼﻔﻮﻓﺎت اﻟﺮﺋﻴﺴﻴﺔ ........................................................................ 421‬‫7.ال ‪124 ...................................................................................... Enumeration‬‬‫8.اﻟﺘﺮاﻛﻴﺐ ‪127 ...................................................................................... Structure‬‬‫8.1. إﻧﺸﺎء اﻟﺪوال داﺧﻞ ال ‪129 ................................................................... Struct‬‬‫9.اﻷﻧﻮاع ‪ Value‬واﻷﻧﻮاع ‪131 ....................................................................... Reference‬‬‫01.اﻟﻤﻘﺎرﻧﺎت .................................................................................................. 331‬‫11.‪137 ....................................................................................... Nullable Types‬‬‫11.1. ﺧﺼﺎﺋﺺ ال ‪139 ............................................................................... Nullable‬‬‫11.2. اﻟﻤﻌﺎﻣﻞ ؟؟ ........................................................................................... 041‬ ‫ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ ‪OOP‬‬ ‫اﻟﺒﺎب 80‬‫1.ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﻔﺌﺎت ‪144 ............................................................................... Classes‬‬‫1.1. اﻟﻤﺸﻴﺪات ‪146 .......................................................................... Constructors‬‬‫1.2. اﻟﻤﻬﺪﻣﺎت ‪147 .............................................................................. Destructor‬‬‫2.‪148 ................................................................................................... this‬‬‫3.اﻟﺘﻌﺮف ﻋﻠﻰ ‪149 ................................................................................... Static‬‬‫3.1. ‪153 ........................................................................................ Static Class‬‬‫4.إﻋﺎدة اﻟﺘﺤﻤﻴﻞ ‪154 ............................................................................ OverLoading‬‬‫5.ﻣﻌﺮﻓﺎت اﻟﻮﺻﻮل ‪157 ..................................................................... Access Modifier‬‬‫6.اﻟﻌﻨﺎﺻﺮ اﻷﺳﺎﺳﻴﺔ ﻓﻲ ‪158 ............................................................................... OOP‬‬‫6.1. ‪158 ..................................................................................... Encapsulation‬‬‫6.2. ‪158 ........................................................................................ Inheritance‬‬‫6.3. ‪159 .................................................................................... Polymorphism‬‬‫7.‪160 .......................................................................................... Encapsulation‬‬‫7.1. اﺳﺘﺨﺪام دوال ‪ public‬ﻟﻠﻮﺻﻮل إﻟﻰ ﻣﺘﻐﻴﺮات ‪161 ....................................... private‬‬‫7.2. إرﺳﺎل اﻟﻘﻴﻢ ﻛﺠﺰء ﻣﻦ ال ‪164 .............................................................. Constructor‬‬‫7.3. اﺳﺘﺨﺪام ال ‪165 ........................................................................ Type Property‬‬ ‫31‬
  • 166 ..................................................................................... Inheritance ‫8.اﻟﻮراﺛﺔ‬167 .................................................................................... is‐a ‫8.1. ﺗﻌﺮﻳﻒ ﻋﻼﻗﺔ‬170 ........................................... sealed - NotInheritable ‫8.2. اﻟﻜﻠﻤﺔ اﻟﻤﺤﺠﻮزة‬170 ....................................................................................... ‫8.3. اﻟﻮراﺛﺔ اﻟﻤﺘﻌﺪدة‬171 .......................................................................... ‫8.4. اﻟﺘﻌﺪﻳﻞ ﻓﻲ اﻟﻜﻼس اﻟﻤﺸﺘﻖ‬171 ................................................................................ has‐a ‫8.5. اﻟﻌﻼﻗﺔ ﻣﻦ ﻧﻮع‬172 .................................................................................. Casting ‫8.6. اﻟﺘﺤﻮﻳﻼت‬174 ................................................................................. is ‫8.7. اﻟﻜﻠﻤﺔ اﻟﻤﺤﺠﻮزة‬174 .................................................................... Visual Studio Class Diagram .8.8175 ..................................................................................... Polymorphism ‫9.ال‬177 ............................................................................................. Abstract ‫01.ال‬178 ................................................................................ Abstract method .1.10 ‫ – اﻟﻮاﺟﻬﺎت‬Interfaces 09 ‫اﻟﺒﺎب‬182 ..................................................................................... Interface ‫1.ﺗﻌﺮﻳﻒ ال‬184 ........................................................................................ Names Clashes.2187 .......................................................................... IEnumerable interface.3191 ............................................................................ ICloneable interface.4193 .......................................................................... IComparable interface.5 ‫اﻷﺧﻄﺎء واﻗﺘﻨﺎﺻﻬﺎ‬ 10 ‫اﻟﺒﺎب‬198 .......................................................................... Syntax Errors ‫1.اﻷﺧﻄﺎء اﻟﻨﺤﻮﻳﺔ‬198 ......................................................................... Logical Erros ‫2.اﻷﺧﻄﺎء اﻟﻤﻨﻄﻘﻴﺔ‬200 ....................................................................... System.Exception ‫3.اﻟﻔﺌﺔ‬202 ............................................................. Throwing Exceptions - ‫4.رﻣﻲ اﻻﺳﺘﺜﻨﺎءات‬203 ............................................................... Catching exceptions - ‫5.اﻗﺘﻨﺎص اﻷﺧﻄﺎء‬205 ............................................................................... Finally ‫5.1. اﺳﺘﺨﺪام‬206 ................................................................................... break ‫5.2. اﺳﺘﺨﺪام‬206 ......................................................................... TargetSite ‫5.3. اﺳﺘﺨﺪام‬206 ............................................................................. HelpLink ‫5.4. اﺳﺘﺨﺪام‬ 14
  • 207 .......................................................................................... ‫6.ﻋﻤﻞ أﺧﻄﺎء ﺧﺎﺻﺔ‬ Collections ‫اﻟﺘﺠﻤﻴﻌﺎت‬ 11 ‫اﻟﺒﺎب‬212 .................................................. System.Collections ‫ ﻓﻲ‬Interfaces ‫1.ال‬215 ............................................................. System.Collections ‫2.اﻟﻔﺌﺎت ﻓﻲ‬215 ..................................................................................... ArrayList .1.2218 ..................................................................................... HashTable .2.2219 ............................................................................................ Queue .3.2220 ............................................................................................ Stack .4.2 .net 2008 ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ‬ 12 ‫اﻟﺒﺎب‬226 ............................................................................................. Generics ‫1.ال‬228 .................................................................. Structure and Class Generics .1.1230 ............................................................................... Generic Collection .2.1231 ............................................................................... where T ‫1.3. اﺳﺘﺨﺪام‬233 ........................................................................................... Delegates ‫2.ال‬235 ............................................................................... Delegates ‫2.1. ﺗﻌﺮﻳﻒ ال‬236 ..................................................................................... Events ‫2.2. اﻷﺣﺪاث‬238 ............................................................. C# ‫ - ﻓﻘﻂ ﻓﻲ‬Anonymous Methods ‫3.ال‬239 ..................................................................................... ‫4.اﺳﺘﻨﺘﺎج ﻧﻮع اﻟﻤﺘﻐﻴﺮات‬240 .................................................................... Extension Methods ‫5.اﻟﺪوال اﻟﻤﻤﺘﺪة‬241 ................................................................................ Automatic Properties.6242 ................................................................... Lambda Expressions ‫7.ﺗﻌﺒﻴﺮات ﻻﻣﺪا‬246 ........................................................ Object Initializer Syntax ‫8.ﺻﻴﻎ إﻧﺸﺎء اﻟﻜﺎﺋﻨﺎت‬248 ................................................................... Anonymous Types ‫9.اﻷﻧﻮاع اﻟﻤﺠﻬﻮﻟﺔ‬250 ....................................................................................... Partial Methods.10251 .................................................................................... Garbage Collector.11252 ............................................................................................ GC ‫11.1. اﻟﻔﺌﺔ‬253 ............................................................................... Operator Overloading.12257 ...................................................................................... Pointers ‫31.اﻟـﻤﺆﺷﺮات‬ 15
  • 261 .................................................................................... Query Expressions.14263 ............................................................................. Preprocessor Directives.15264 ................................................................. #region, #endregion .1.15266 ........................................................ #if, #elif, #else, #endif .2.15267 ........................................................................... #define, #undef .3.15269 .................................................................................... XML Commenting.16274 ........................................................................................ .net assemblies.17274 ..................................................................................... namespace ‫71.1. ال‬275 .................................................................... Default Namespace ‫71.2. ﺗﻐﻴﻴﺮ ال‬276 ............................................... Format of a .net Assembly ‫71.3. ﺷﻜﻞ ﻣﻠﻒ اﻻﺳﻤﺒﻠﻲ‬277 ............................................................................... Private Assemblies .4.17277 ............................................................................... Shared Assemblies .5.17278 .................................................................... Multithreading ‫81.اﻟﻤﺴﺎرات اﻟﻤﺘﻌﺪدة‬278 ................................................................................................ ‫81.1. ﻣﻘﺪﻣﺔ‬279 ................................................................ Synchronization ‫81.2. اﻟﺠﻮرﻳﺰﻣﺎت اﻟﺘﺰاﻣﻦ‬280 .......................................................... System.Threading.Thread .3.18284 .............................................................................. Priority ‫81.4. اﻷوﻟﻮﻳﺔ‬286 ........................................................ ParameterizedThreadStart .5.18286 .................................................................. Foreground and Background .6.18287 ....................................................................... Threads Synchronization .7.18288 ................................................................................... ThreadPool .8.18288 ....................................................................... BackgroundWorker .9.18 System.IO .net ‫اﻻدﺧﺎل و اﻻﺧﺮاج ﻓﻲ‬ 13 ‫اﻟﺒﺎب‬294 ................................................................... System.IO ‫1.اﻟﻔﺌﺎت اﻷﺳﺎﺳﻴﺔ ﻓﻲ‬295 .................................................. Directory ‫ و‬DirectoryInfo ‫2.اﻟﻔﻮارق ﺑﻴﻦ‬296 ............................................................................ DirectoryInfo ‫3.اﻟﻔﺌﺔ‬299 ........................................................................ Directory ‫4.اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻔﺌﺔ‬300 ........................................................................ DriveInfo ‫5.اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻔﺌﺔ‬ 16
  • 301 ................................................................................ FileInfo ‫6.اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬303 ............................................................... Open ‫6.1. إﻧﺸﺎء وﻓﺘﺢ اﻟﻤﻠﻔﺎت ﺑﺎﺳﺘﺨﺪام‬304 ................................... OpenWrite ‫ و‬OpenRead ‫6.2. ﻓﺘﺢ وإﻧﺸﺎء اﻟﻤﻠﻔﺎت ﺑﺎﺳﺘﺨﺪام‬304 ............................................................... OpenText ‫6.3. ﻓﺘﺢ اﻟﻤﻠﻔﺎت ﺑﺎﺳﺘﺨﺪام‬305 ............................................. AppendText ‫ و‬CreateText ‫6.4. اﻟﻔﺘﺢ ﺑﺎﺳﺘﺨﺪام‬305 .................................................................................. File ‫7.اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻔﺌﺔ‬307 ............................................................................................... Stream.8308 ............................................................................. FileStream ‫8.1. اﻟﻔﺌﺔ‬309 ........................................................................... ‫8.2. اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻔﺌﺎت اﻟﻤﺸﺘﻘﺔ‬309 ...................................................... StreamWriter, StreamReader .3.8312 ...................................................... StringWriter, StringReader .4.8313 ...................................................... BinaryReader, BinaryWriter .5.8314 .......................................................................... FileSystemWatcher.9317 ................................................................................... Object Serialization.10318 ........................................................................ Serialization ‫01.1. اﻟﺘﻌﺎﻣﻞ ﻣﻊ ال‬320 ............................................................................. XmlSerializer .2.10   Windows Forms .net ‫ﺑﺮﻣﺠﺔ اﻟﻨﻮاﻓﺬ ﻓﻲ ال‬ 14 ‫اﻟﺒﺎب‬325 ..................................................................................................... ‫1.ﻣﻘﺪﻣﺔ‬325 ........................................................................... ‫ ﺑﺎﻟﻜﻮد‬Windows Forms ‫2.ﺑﻨﺎء‬328 .................................................................................. ‫2.1. إﺿﺎﻓﺔ أدوات ﺑﺎﻟﻜﻮد‬329 ......................................................................................... ‫2.2. إﺿﺎﻓﺔ اﻟﻘﻮاﺋﻢ‬333 ............................................................... Viusal Studio .net ‫3.إﻧﺸﺎء ﻓﻮرم ﻋﻦ ﻃﺮﻳﻖ‬341 ................................................................... Windows.Forms ‫4.ﻣﺠﺎل اﻷﺳﻤﺎء‬341 ..................................................... Windows.Forms ‫4.1. اﻟﻔﺌﺎت اﻟﺮﺋﻴﺴﻴﺔ ﻟﻌﻨﺎﺻﺮ‬342 ............................................................................... Form ‫4.2. ﺧﺼﺎﺋﺺ اﻟﻔﺌﺔ‬343 ................................................................................... Form ‫4.3. دوال اﻟﻔﺌﺔ‬343 ................................................................................. Form ‫4.4. أﺣﺪاث اﻟﻔﺌﺔ‬344 ...................................................................................... Controls ‫5.اﻟﻔﺌﺔ‬ 17
  • 344 ........................................................................ Controls ‫5.1. ﺧﺼﺎﺋﺺ اﻟﻔﺌﺔ‬345 ......................................................................... Controls ‫5.2. أﺣﺪاث اﻟﻔﺌﺔ‬346 .............................................. System.Windows.Forms.Control ‫6.أدوات‬346 .......................................................................................... Button .1.6347 ....................................................................................... CheckBox .2.6347 ................................................................................. RadioButton .3.6348 ...................................................................... ListBox ‫ و‬ComboBox .4.6348 ........................................................................................ Textbox .5.6350 ............................................................................................ Label .6.6350 .......................................................................... Panel ‫ و‬GroupBox .7.6351 ................................................................................. RichTextBox .8.6353 ............................................................................................ Timer .9.6354 ....................................................................................... TreeView .10.6355 ................................................................................. ProgressBar .11.6355 ....................................................................................... TrackBar .12.6356 ........................................................................... DateTimePicker .13.6356 .................................................................................................. Dialogs.7358 ................................................................................... MessageBox .1.7360 .................................................................................. Dialogs Controls .2.7360 ................................................................................. ColorDialog .3.7362 ................................................................................... FontDialog .4.7364 ......................................................................... Open And Save Dialogs .5.7367 ................................................................................. PrintDialog .6.7367 ............................................................................................. ‫8.أﺣﺪاث اﻟﻤﺎوس‬369 ............................................................................................ ‫9.أﺣﺪاث اﻟﻜﻴﺒﻮرد‬ +GDI 15 ‫اﻟﺒﺎب‬374 ......................................................................................... +GDI ‫1.ﻣﻘﺪﻣﺔ إﻟﻰ‬374 ........................................................ System.Drawing ‫2.ﻣﺤﺘﻮﻳﺎت ﻣﺠﺎل اﻷﺳﻤﺎء‬ 18
  • ‫3.اﻟﻔﺌﺔ ‪375 ...................................................................................... Graphics‬‬‫4.اﻟﻔﺌﺔ ‪378 .............................................................................................. Pen‬‬‫5.اﻟﻘﺌﺔ ‪378 .......................................................................................... Brush‬‬‫6.اﻟﺮﺳﻢ ...................................................................................................... 973‬‫7.رﺳﻢ اﻟﻨﺼﻮص ............................................................................................. 183‬ ‫‪  Windows Presentation Foundation‬‬ ‫اﻟﺒﺎب 61‬‫1.ﻣﻘﺪﻣﺎت أﺳﺎﺳﻴﺔ .......................................................................................... 683‬‫1.1. ‪386 ................................................................................................. WPF‬‬‫1.2. ‪386 ............................................................................................... XAML‬‬‫1.3. ‪386 ............................................................................ Microsoft Expression‬‬‫2.أﻧﻮاع ﺗﻄﺒﻴﻘﺎت ‪387 ...................................................................................... WPF‬‬‫3.ﻣﺤﺘﻮﻳﺎت ‪388 ............................................................................................ WPF‬‬‫4.ﺗﻄﺒﻴﻘﻚ اﻷول ﻓﻲ ﻋﺎﻟﻢ ‪388 ............................................................................. WPF‬‬‫5.اﻟﺒﺪء ﻣﻦ ﺧﻼل ﻓﻴﺠﻮال ﺳﺘﻮدﻳﻮ ............................................................................ 093‬‫6.أدوات ‪396 .............................................................................................. WPF‬‬‫7.رﺑﻂ اﻟﺒﻴﺎﻧﺎت ‪399 .............................................................................. Data‐Binding‬‬‫8.‪400 ................................................................................................. WPF 2D‬‬‫8.1. اﻟﺮﺳﻢ ﺑﺎﺳﺘﺨﺪام ‪400 ............................................................................. Shapes‬‬‫8.2. ﺧﺼﺎﺋﺺ اﻟﻘﻠﻢ ‪403 ................................................................................. Pen‬‬‫8.3. ﺧﺼﺎﺋﺺ اﻟﻔﺮﺷﺎة ‪403 .......................................................................... Brush‬‬‫8.4. ال ‪405 .............................................................................. Transformations‬‬‫9.ال ‪ Animation‬ﻓﻲ ‪406 ................................................................................ WPF‬‬‫01.اﻟﺤﺮﻛﺔ ﺑﺎﺳﺘﺨﺪام ‪409 .................................................................................. XAML‬‬‫11.ﺗﻌﺮﻳﻒ ‪409 ............................................................................................. Styles‬‬‫11.1. ﺗﻐﻴﻴﺮ ﻃﺒﻴﻌﺔ ال ‪411 ................................................................................ Style‬‬‫11.2. اﺷﺘﻘﺎق ‪ Style‬ﻣﻦ آﺧﺮ ................................................................................ 114‬‫11.3. ﺗﺼﻤﻴﻢ ‪ Style‬ﺑﺎﺳﺘﺨﺪام ‪411 ................................................................... Triggers‬‬‫21.ال ‪414 ........................................................................................... Templates‬‬ ‫91‬
  • 416 ................................................................................................. 3D WPF.13423 ................................................................................................. XNA ‫41.ﻋﺎﻟﻢ‬424 ........................................................................ Microsoft Expression Studio.15424 ..................................................................... Microsoft Expression Web .1.15425 .................................................................. Microsoft Expression Design .2.15426  ................................................................... Microsoft Expression Media .3.15427 ................................................................. Microsoft Expression Encoder .4.15428 ................................................................................. Expression Blend .5.15 ADO.net ‫ﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت ﺑﺎﺳﺘﺨﺪام‬ 17 ‫اﻟﺒﺎب‬441 ................................................................................. ADO.net ‫1.اﻟﺒﺪء ﺑﺎﺳﺘﺨﺪام‬441 ..................................................................... ADO.net Data Provider ‫2.ﻣﻜﻮﻧﺎت‬441 .............................................. ‫ اﻟﻤﺪﻋﻮﻣﺔ ﻣﻦ ﻗﺒﻞ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ‬Data Providers ‫2.1. ال‬442 .......................... Third‐Party ADO.net Data Providers ‫2.2. اﻟﺘﻌﺎﻣﻞ ﻣﻊ ﻣﺰودات ﺧﺪﻣﺔ أﺧﺮى‬443 .............................................................. System.Data ‫3.ﻣﻜﻮﻧﺎت ﻣﺠﺎل اﻷﺳﻤﺎء‬448 ................................................................................... SQL Server ‫4.اﻟﺒﺪاﻳﺔ ﻣﻊ‬448 .................................................................................. ‫4.1. إﻧﺸﺎء ﻗﺎﻋﺪة اﻟﺒﻴﺎﻧﺎت‬457 .................................................................................. SQL Statements .2.4468 ................................................................................ Stored Prcoedure .3.4471 ...................................................................................... SQL Injection .4.4472 .............................................................................................. ‫4.5. اﻟﻌﻼﻗﺎت‬473 ............................................................................................. ‫5.اﻟﻮﺿﻊ اﻟﻤﺘﺼﻞ‬473 ............................................... ConnectionStringBuilder ‫5.1. اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬474 ....................................................................... Command ‫5.2. اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻔﺌﺔ‬478 ........................................................................... DataReaders ‫5.3. اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬480 .................................................................................... Data Access Layer.6487 ......................................................................... Asynchronous Data Access.7489 ........................................................................................... Transactions.8493 ........................................................................................... ‫9.اﻟﻮﺿﻊ اﻟﻤﻨﻔﺼﻞ‬ 20
  • 493 ...................................................................................... DataSet ‫9.1. ال‬495 ......................................................................... DataTable ‫9.2. اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬496 .............................................................................. DataTable ‫9.3. إﻧﺸﺎء‬496 ....................................................................... DataColumn ‫9.4. اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬498 .............................................................................. DataRow ‫9.5. اﻟﻌﻤﻞ ﻣﻊ‬502 ........................... DataTable ‫ ﻟﻘﺮاءة اﻟﺒﻴﺎﻧﺎت ﻣﻦ‬DataTableReader ‫9.6. اﺳﺘﺨﺪام‬502 ............................................................................... XML ‫ إﻟﻰ‬Serializing ‫01.ﻋﻤﻞ‬503 ................................................................................... DataGrid ‫11.اﺳﺘﺨﺪام ال‬506 ............................................................................. DataAdapter ‫21.اﺳﺘﺨﺪام‬ LINQ 18 ‫اﻟﺒﺎب‬510 ..................................................................................................... ‫1.ﻣﻘﺪﻣﺔ‬513 ............................................................................................... LINQ ‫2.دوال‬518 ...................................................................................... LINQ To DataSet.3519 ........................................................................................... LINQ To XML.4521 ............................................................................................ LINQ To SQL.5526 ................................................................................... SubmitChanges.6527 ................................................... ‫ ﻣﻦ ﺧﻼل اﻟﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ‬LINQ To SQL ‫7.إﻧﺸﺎء ﻓﺌﺎت‬   WWF 19 ‫اﻟﺒﺎب‬533 .................................................................................. WF ‫1.ﻣﻜﻮﻧﺎت واﺳﺎﺳﻴﺎت‬534 .......................................................................................... WF ‫1.1. اﻟﺒﺪأ ﻣﻊ‬535 ............................................................................ Sequential Workflow .2.1535 ....................................................................... State Machine Workflow .3.1537 ............................................................................................. WWF ‫2.ﺗﻄﺒﻴﻖ‬541 ..................................................................................... WF Code Liabrary.3 WCF 20 ‫اﻟﺒﺎب‬544 ........................................................................................... Web Service.1545 ....................................................... .net ‫ ﺧﺎﺻﺔ ﺑﻚ ﻣﻦ ﺧﻼل‬Web Service ‫1.1. ﻋﻤﻞ‬546 ........................................... ‫ ﺧﺎﺻﺔ ﺑﻚ ﻓﻲ ﻣﺸﺮوﻋﺎﺗﻚ اﻟﻔﻌﻠﻴﺔ‬WebService ‫1.2. اﺳﺘﺨﺪام‬ 21
  • ‫1.3. اﺳﺘﺨﺪام ﺧﺪﻣﺎت اﻹﻧﺘﺮﻧﺖ اﻟﺠﺎﻫﺰة ..................................................................... 745‬‫2.ﻣﻘﺪﻣﺔ إﻟﻰ ‪550 .......................................................................................... WCF‬‬‫2.1. اﻟﺒﺪاﻳﺔ ﻣﻊ ‪551 ...................................................................................... WCF‬‬‫2.2. ﺷﻜﻞ وﻣﺤﺘﻮﻳﺎت ال ‪552 ....................................................................... Address‬‬ ‫ﻧﻘﺎط ﻣﺘﻘﺪﻣﺔ‬ ‫اﻟﺒﺎب 12‬‫1.اﻟﺘﻨﻘﻴﺢ – ‪557 ......................................................................................... Debug‬‬‫2.ﺗﺠﻬﻴﺰ اﻟﺒﺮاﻣﺞ ﻟﻠﺘﻮزﻳﻊ ........................................................................................ 265‬‫3.‪564 ........................................................................................... C# vs VB.net‬‬‫4.ﻣﻘﺪﻣﺔ إﻟﻰ ‪569 ......................................................................................... Mono‬‬‫5.ﺑﺮﻣﺠﺔ اﻷﺟﻬﺰة اﻟﻜﻔﻴﺔ ﻣﻦ ﺧﻼل ‪571 ...................................................................... .net‬‬ ‫ﺗﻄﻮﻳﺮ اﻟﻤﻮاﻗﻊ ﺑﺎﺳﺘﺨﺪام ‪ASP.net‬‬ ‫اﻟﺒﺎب 22‬‫1.ﻣﻘﺪﻣﺔ إﻟﻰ ﺗﻄﻮﻳﺮ اﻟﻤﻮاﻗﻊ ................................................................................... 975‬‫2.ﻣﻘﺪﻣﺔ إﻟﻰ ‪586 ...................................................................................... ASP.net‬‬‫3.اﻟﻔﺌﺔ ‪593 ................................................................... System.Web.UI.Page‬‬‫3.1. اﻟﺘﻌﺎﻣﻞ ﻣﻊ ‪593 ............................................................................. Request‬‬‫3.2. اﻟﺘﻌﺎﻣﻞ ﻣﻊ ‪596 ........................................................................... Response‬‬‫4.أدوات ‪598 .......................................................................................... ASP.net‬‬‫4.1. اﻟﺨﺼﺎﺋﺺ اﻷﺳﺎﺳﻴﺔ ﻷدوات اﻟﻮﻳﺐ ................................................................... 895‬‫5.‪602 ........................................................................................... MasterPages‬‬‫6.اﻟﺘﻌﺎﻣﻞ ﻣﻊ ‪606 ..................................................................................... Sitemap‬‬‫7.أدوات اﻟﺘﺤﻘﻖ ‪608 ..................................................................... Validation Control‬‬‫8.‪615 ................................................................................... State Management‬‬‫8.1. ‪615 ...................................................................................... Control state‬‬‫8.2. ‪617 ...................................................................................... ViewState‬‬‫8.3. ‪617 ......................................................................................... Session‬‬‫8.4. ‪618 ........................................................................................ Cookies‬‬‫8.5. ‪621 .................................................................................. Application‬‬‫8.6. ‪622 ............................................................................................. Cache‬‬ ‫22‬
  • 623 ........................................................................................ Global.asax .7.8625 ................................................................................. ‫ وﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت‬ASP.net.9628 ........................................................................................... DataGrid .1.9635 ..................................................................................................... WAP.10635 ....................................................................................... ‫ ؟‬WAP ‫01.1. ﻣﺎ ﻫﻲ‬636 ................................................................................................ WML .2.10637 ................................................................................... WAP + ASP.net .3.10638 ..................................................................................................... AJAX.11638 ........................................................................................ AJAX ‫11.1. اﺟﺎﻛﺲ‬647 ......................................................................................... ‫ﺧﺎﺗﻤﺔ اﻟﻜﺘﺎب ،،، وﺷﻜﺮ‬648 ......................................................................................................... ‫اﻟﻤﺼﺎدر‬ 23
  • 24
  • ‫ﺘــﺎب‬ ‫ﻣـ ﻣـــﺔ اﻟﻜـﺘ ب‬ ‫ـﻘﺪﻣ‬‫ﻼم ﻋﻠﻰ ﺮف اﻷﻧﺒﻴﺎء واﻟﻤﺮﺳﻠﻴﻦ، ﻧﺒﻴﻨﺎ ﻣﺤﻤﺪ وﻋﻠﻰ آﻟﻪ‬ ‫أﺷﺮ‬ ‫ﺑﺴﻢ ﷲ اﻟﺮﺣﻤﻦ ﻟﺮﺣﻴﻢ، ﺼﻼة واﻟـﺴﻼ‬ ‫واﻟـﺼ‬ ‫اﻟ‬ ‫اﷲ‬ ‫وﺻﺤﺒﻪ أﺟﻤﻌﻴﻦ.‬ ‫ﻪ ﺳﻬ ً ﻧﺖ ﺗﺠﻌﻞ اﻟﺤﺰن ﻬ ً .‬ ‫ﺳﻬﻼ‬ ‫ﻼ وأﻧ‬ ‫اﻟﻠﻬﻢ ﻻ ﺳﻬﻞ ﻻ ﻣﺎ ﺟﻌﻠﺘﻪ‬ ‫إﻻ‬ ‫أﻣﺎ ﺑﻌﺪ ...‬‫س اﺳﺘﻤﺮت ﻋﻠﻰ ﻣﺪار ﺳﺘﺔ أﺷﻬﺮ‬ ‫ﺳ‬ ‫ﻊ ﻟﺴﻠﺴﻠﺔ ﻣﻦ اﻟﺪروس‬ ‫ب ﻫﻮ ة ﻋﻦ ﺗﺠﻤﻴﻊ‬ ‫ﻋﺒﺎرة‬ ‫ﻓﻬﺬا اﻟﻜﺘﺎب‬ ‫ﻓ‬‫ﻋﻠﻰ ﺘﺪى ﻓﻴﺠﻮال ﺑﻴﺴﻚ ﻌﺮب ﺣﻮل ﺗﻘﻨﻴﺎت . 002 ‪ net‬ااﻟﺠﺪﻳﺪة ، ﺗﻢ اﻻﻧﺘﻬﺎء ﻣﻨﻬﺎ ﺑﺤﻤﺪ‬ ‫ﺗ‬ ‫80‬ ‫ﺗ‬ ‫ﻟﻠﻌ‬ ‫ﻣﻨﺘﺪ‬ ‫ﺒﺮ 8002 ، وﻣﻦ ﺛﻢ ﺗﻢ ﺗﺠﻤﻴﻌﻬﺎ ﻊ وﺿﻊ ﺿﺎﻓﺎت ﺟﺪﻳﺪ‬‫ﺪة ﻋﻠﻴﻬﺎ ﺿﻤﻦ ﻛﺘﺎب‬ ‫ﺿ‬ ‫إﺿ‬ ‫ﻣﻊ‬ ‫اﷲ ﻓﻲ أول ﺳﺒﺘﻤﺒ‬ ‫ﻣﻨﺴﻖ ﻫﻮ اﻟﻜﺘﺎب اﻟﺬي ﺗﺠﺪه ﺑﻴﻦ ﻳﺪﻳﻚ اﻟﻴﻮم .‬ ‫ﻫ‬‫5.3 ‪Pro C# 2008 and the .net‬‬ ‫#‬ ‫‪a‬‬ ‫5‬ ‫ب ﺟﺎءت ﺑﻌﺪ ﻗﺮاءة ﻛﺘﺎب‬ ‫ﻓﻜﺮة اﻟﻜﺘﺎب‬ ‫ﻓ‬ ‫‪ ،Andrew Tro‬ﺣﻴﺚ وﺟﺪت ﻌً ﻛﺎﻣ ً ﻠﻐﺔ اﻹﻧﺠﻠﻴﺰﻳ‬‫ﻳﺔ ﻟﻜﻞ ﻣﺎ‬ ‫ﻣﺮﺟﻌﺎ ﻼ ﺑﺎﻟﻠ‬ ‫ﻒ ‪oelsen‬‬ ‫‪ Platform‬ﻟﻠﻤﺆﻟﻒ‬ ‫ﺖ‬ ‫أد‬ ‫وﻣ‬ ‫ﻳﺨﺘﺺ ﺑﻨﺴﺨﺔ ‪ C‬اﻟﺠﺪﻳﺪة ﻣﻦ ﻣﺎﻳﻜﺮوﺳ‬‫ﺳﻮﻓﺖ ، ﻣﻊ أﻧﻲ ﻻ دﻋﻲ أﻧﻲ ﻗﻤﺖ ﺑﻌﻤﻞ ﺮﺟﻊ ﺑﺎﻟﻠﻐﺔ‬ ‫ﻣﺮ‬ ‫ﻣ‬ ‫#‪C‬‬‫اﻟﻌﺮﺑﻴﺔ إﻻ أﻧﻨﻲ ﺳﺘﻄﻴﻊ أن ﻋﻢ أﻧﻲ ﻴﺖ ﺑﺼﻮرة ﻣﻮﺟﺰة ﺐ اﻟﻨﻘﺎط ﻟﺮﺋﻴﺴﻴﺔ ﻲ ﻣﺠﺎل ال‬ ‫ﻓﻲ‬ ‫اﻟ‬ ‫أﻏﻠﺐ‬ ‫ﻏﻄﻴ‬ ‫أزﻋ‬ ‫أﺳﺘ‬ ‫‪ ، V‬وﻟﻠﻤﺰﻳﺪ ﺣﻠﺘﻚ إﻟﻰ واﺑﻂ ﻣﻦ ‪ MSDN‬ﺴﺘﻄﻴﻊ اﻟﺘﻌﻤﻖ‬‫ﻖ ﻓﻲ ﻛﻞ‬ ‫ﻟﺘﺴ‬ ‫رو‬ ‫أﺣ‬ ‫.‪ net‬ﻠﻐﺘﻴﻪ #‪ C‬و ‪VB.net‬‬ ‫ﺑﻠ‬ ‫ﻣﺠﺎل ﻠﻰ ﺣﺪة .‬ ‫ﻋﻠ‬‫52‬
  • ‫ﻓﻲ ﻫﺬا اﻟﻜﺘﺎب رﺑﻤﺎ ﻟﻦ ﺗﺠﺪ ﺗﻔﺼﻴ ً ﺷﺎﻣ ً ﻟﻨﻘﻄﺔ ﻣﺎ ، ﻓﻼ ﺗﻨﺘﻈﺮ ﻣﻨﻲ ﻣﺜ ً أن ﺗﻌﺮف ﺑﻌﺪ‬ ‫ﻼ‬ ‫ﻼ‬ ‫ﻼ‬‫ﻧﻬﺎﻳﺔ ﻓﺼﻞ ﻣﺎ ﻛﻞ ﻣﺎ ﻳﺘﻌﻠﻖ ﺑﺄﺣﺪ اﻷدوات، وﻟﻜﻨﻚ ﺗﺴﺘﻄﻴﻊ اﻟﺘﻌﺮف ﻋﻠﻰ أﻛﺒﺮ ﻗﺪر ﻣﻦ‬‫اﻟﻤﻌﻠﻮﻣﺎت ﺣﻮل ﺑﻨﻴﺔ ﻫﺬه اﻷداة وﻃﺮﻳﻘﺔ ﺗﻌﺎﻣﻠﻬﺎ وﺳﻠﻮﻛﻬﺎ داﺧﻞ ﺑﺮﻧﺎﻣﺠﻚ ، ﻓﻬﺬا اﻟﻜﺘﺎب‬‫ﻳﻬﺪف ﻷن ﺗﺴﺘﻄﻴﻊ ﻣﻦ ﺧﻼﻟﻪ ﻓﻬﻢ ﺑﻨﻴﺔ .‪ net‬أﻛﺜﺮ ﻣﻦ دﻋﻤﻚ ﻟﺘﻄﻮر ﺗﻄﺒﻴﻘﺎت ﺑﺴﺮﻋﺔ دون أن‬ ‫ﺗﻔﻬﻢ ﺑﻨﻴﺘﻬﺎ اﻟﺪاﺧﻠﻴﺔ وﻛﻴﻔﻴﺔ ﺗﻌﺎﻣﻠﻬﺎ ﻣﻊ ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﻤﺨﺘﻠﻔﺔ .‬‫وﺑﺎﻟﺮﻏﻢ ﻣﻦ ذﻟﻚ ﺳﺘﺠﺪ ﺑﻴﻦ اﻟﻔﺘﺮة واﻷﺧﺮى ﺗﻄﺒﻴﻖ ﻋﻤﻠﻲ ﻧﻘﻮم ﺑﻌﻤﻠﻪ ﺳﻮﻳﺔ ﻟﺘﻄﺒﻴﻖ ﺑﻌﺾ‬‫اﻟﻤﻔﺎﻫﻴﻢ اﻟﺘﻲ ﺗﻌﻠﻤﻨﺎﻫﺎ ﻟﺮﺑﻂ اﻟﺘﻌﻠﻴﻢ اﻟﻨﻈﺮي ﺑﺎﻟﺘﻄﺒﻴﻖ اﻟﻌﻤﻠﻲ ﻟﺘﺤﺼﻴﻞ أﻛﺒﺮ ﻛﻢ ﻣﻦ اﻟﻔﺎﺋﺪة ﻣﻦ ﻫﺬا‬‫اﻟﻜﺘﺎب ... ﻟﺬا ﺳﺘﺠﺪ ﺑﻴﻦ ﻃﻴﺎت اﻷﻛﻮاد اﻟﻤﻮﺟﻮدة ﻓﻲ ﻫﺬا اﻟﻜﺘﺎب ﻋﺪد ﻛﺒﻴﺮ ﻣﻦ اﻷﻣﺜﻠﺔ‬ ‫واﻟﺘﻄﺒﻴﻘﺎت اﻟﺼﻐﻴﺮة ﻟﻜﻦ ﻻ ﺗﻨﺘﻈﺮ ﻣﻨﻲ أن أﻗﻮل ﻟﻚ ﺟﺮب ﻫﺬا اﻟﺘﻄﺒﻴﻖ ﻣﺜ ً ﺧﻄﻮة ﺑﺨﻄﻮة .‬ ‫ﻼ‬‫أﺳﺄل اﷲ أن ﻳﻜﻮن ﻫﺬا اﻟﻜﺘﺎب ﻣﻔﻴﺪً، ﻓﻤﺎ ﻛﺎن ﻓﻴﻪ ﻣﻦ ﺻﻮاب ﻓﻤﻦ اﷲ، وﻣﺎ ﻛﺎن ﻣﻦ‬ ‫ا‬ ‫ﺧﻄﺄ ﻓﻤﻦ ﻧﻔﺴﻲ واﻟﺸﻴﻄﺎن، واﷲ اﻟﻬﺎدي إﻟﻰ ﺳﻮاء اﻟﺴﺒﻴﻞ.‬‫أﺣﻤﺪ ﺟﻤﺎل ﺧﻠﻴﻔﺔ‬‫62‬
  • ‫ﻧـ ة ﻦ ﻤـﺆﻟــــﻒ‬ ‫ـﺒــﺬة ﻋـﻦ اﻟﻤ‬ ‫أﺣﻤﺪ ل ﺧﻠﻴﻔﺔ ﻋﺒﺪ اﻟﻌﺎل .‬ ‫ﺟﻤﺎل‬ ‫ﺧﺮﻳﺞ ﻴﺔ اﻟﺤﺎﺳﺒﺎت واﻟﻤﻌﻠﻮﻣﺎت – ﺣﻠﻮان – 7002‬ ‫7‬ ‫ﻛﻠﻴ‬ ‫ﺟﻤﻬﻮرﻳﺔ ﻣﺼﺮ اﻟﻌﺮﺑﻴﺔ – اﻟﻘﺎﻫﺮة .‬ ‫‪A-Gamal@win‬‬ ‫‪ndowslive.co‬‬ ‫‪om‬‬ ‫اﻟﺒﺮﻳﺪ ﻟﻜﺘﺮوﻧﻲ :‬ ‫اﻹﻟ‬ ‫00‬ ‫0801020‬ ‫اﻟﻤﻮﺑﺎﻳﻞ : 297110‬ ‫‪http://hammada2091.g‬‬ ‫‪googlepages‬‬ ‫‪s.com/cv.pdf‬‬ ‫‪f‬‬ ‫ﻞ ﺗﺠﺪﻫﺎ ﻫﻨﺎ‬ ‫اﻟﺴﻴﺮة ﻟﺬاﺗﻴﺔ ﺑﺎﻟﻜﺎﻣﻞ‬ ‫اﻟ‬ ‫ل ﺑﻴﺴﻚ ﻌﺮب‬ ‫ﻟﻠﻌ‬ ‫ﻣﺸﺮف ﻋﺎم ﻨﺘﺪﻳﺎت ﻓﻴﺠﻮال‬ ‫ﻣﻨﺘ‬ ‫ﻣ‬ ‫‪www‬‬ ‫‪w.vb4arab.co‬‬ ‫‪om‬‬ ‫ﺼﻴﺔ‬ ‫ﻣﺪوﻧﺔ ﺷﺨﺼ‬ ‫‪www‬‬ ‫‪w.AhmedGamal-Space.b‬‬ ‫‪blogspot.com‬‬ ‫‪m‬‬ ‫ﻣﺪوﻧﺔ ﺗﻘﻨﻴﺔ‬ ‫ﺔ‬ ‫‪www.AhmedGam -Technical.blogspot.co‬‬ ‫‪mal‬‬ ‫‪om‬‬ ‫ﺔ‬ ‫ﻛﺘﺐ ﺳﺎﺑﻘﺔ‬‫72‬
  • ‫ﻓــﺎن‬ ‫ﺷ ﻜـﺮ و ﻋـﺮﻓ ن‬ ‫ﺷـﻜ‬ ‫ﺗﺠﺪﻫﺎ ﻤﻴﻌً ﻓﻲ وﻧﺔ اﻟﺘﻘﻨﻴﺔ‬ ‫اﻟﻤﺪو‬ ‫ﺟﻤ ﺎ‬‫ﻻ ﻳﺸﻜﺮ اﷲ ﻣﻦ ﻻ ﻳﺸﻜﺮ اﻟﻨﺎس ، وﻣﺆﻟﻒ ﻫﺬا اﻟﻜﺘﺎﺎب ﻟﺪﻳﻪ ﻓﻲ اﻟﻮاﻗﻊ ﻗﺎﺋﻤﺔ ﻃﻮﻳﻠﺔ ﺑﺄﺷﺨﺎﺎص ﻛﺜﻴﺮﻳﻦ‬‫ء ، ﻟﺬا اﺳﻤﺢ ﻟﻲ أن أﺳﺮد أﺳﻤﺎءﻫﻢ ﻨﺎ ، ﺣﻴﺚ ﺪف ﻣﻦ ﻚ ﻷن أﺗﺬﻛﺮ‬ ‫ذﻟﻚ‬ ‫أﻫﺪ‬ ‫ﻫﻨ‬ ‫ن اﻟﻜﺜﻴﺮ ﻣﻦ اﻟﺜﻨﺎء واﻟﺪﻋﺎء‬ ‫ﻳﺴﺘﺤﻘﻮن‬‫دوﻣً أن ﻫﺬا اﻟﻜﺘﺎب ﻟﻢ ﻳﻜﻦ ﻜﻮن ﻛﺬﻟﻚ ﻟﻮﻻ ﻓﻀﻞ ﷲ ﻋﻠﻲ أو ً وآﺧﺮً ﺑﺎﻟﺘﻌﺮف واﻻﺳﺘﻔﺎدة ﻣﻦ ﻫﺆﻻء‬ ‫ف‬ ‫ا‬ ‫ﻻ‬ ‫اﷲ‬ ‫ﻟ‬ ‫ﻟﻴﻜ‬ ‫ﺎ‬‫ت اﻟﺜﻤﺮة ﻮاﺿﻌﺔ اﻟﺘﻲ ﺗﺮاﻫﺎ ﺑﻴﻦ ﺪﻳﻚ اﻵن ، ﻟﺬا أﻗﺪم ﻜﺮً ﺧﺎﺻً ﺳﺘﺎذ ﺗﺮﻛﻲ‬ ‫ﺎ ﻟﻸﺳ‬ ‫ﺷﻜ ا‬ ‫ﻟ‬ ‫ﻳﺪ‬ ‫اﻟﻤﺘﻮ‬ ‫ص ﺣﺘﻰ ﺟﺎءت‬ ‫اﻷﺷﺨﺎص‬‫ﺔ ﻛﺎﺋﻨﻴﺔ ﻮﺟﻪ( ﺛﻢ ) ﺠﺔ إﻃﺎر ﻞ ﺷﻴﺌﻲ ﻣﻦ ﺧﻼل ‪ (.net‬ﺣﻴﺚ ﻛﺎن‬ ‫ﺧ‬ ‫ﻋﻤﻞ‬ ‫ﺑﺮﻣﺠ‬ ‫اﻟﺘﻮ‬ ‫اﻟﻌﺴﻴﺮي ﺻﺎﺣﺐ ﺑﻲ )ﻧﺤﻮ ﺑﺮﻣﺠﺔ‬ ‫ﻛﺘﺎﺑ‬‫ﻳﻤﻪ ﻟﻬﺬا ﻜﺘﺎب ﺑﻜﻠﻤﺔ‬ ‫اﻟﻜ‬ ‫ي ﻓﻲ ﻋﺎﻟﻢ ﺒﺮﻣﺠﺔ ، زاد ﻋﻠﻰ ذﻟﻚ أن ﺷﺮﻓﻨﻲ ﺑﺘﻘﺪﻳ‬ ‫ﻋ‬ ‫اﻟﺒ‬ ‫ﻟﻜﺘﺒﻪ ﺒﻴﺮ اﻷﺛﺮ ﻓﻲ ﺗﻮﺟﻴﻪ ﻣﺴﺎري‬ ‫ﻛﺒ‬‫ذي ﺑﻲ ، وأﻻ أأﺧﻴﺐ رﺟﺎﺋﻪ‬‫ﻦ ﻇﻦ أﺳﺘﺎذ‬‫أﻋﻄﺎﻧﻲ ﻓﻴﻬﺎ أﻛﺜﺮ ﻣﻦ ﺣﺠﻤﻲ ﻛﺜﻴﺮً ، ﻟﺬا أرﺟﻮ ﻦ اﷲ أن ﻛﻮن ﻋﻨﺪ ﺣﺴﻦ‬ ‫أﻛﻮ‬ ‫ﻣﻦ‬ ‫ا‬ ‫ﻓ‬ ‫ﻓﻴﻤﺎ ﻗﻌﻪ ﻣﻨﻲ .‬ ‫ﻳﺘﻮﻗ‬‫ﻔﺪت ﻛﺜﻴﺮً ﻣﻦ وﻣﻘﺎﻻﺗﻪ ﻓﻲ ﺗﺠﻬﻴﺰ ﺬا اﻟﻜﺘﺎب .‬ ‫ﻫﺬ‬ ‫ﻓ‬ ‫اﻣ‬ ‫اﻟﺸﻜﺮ ﻳﻀً ﻣﻮﺻﻮل ﻟﻠﻤﻬﻨﺪس ﺤﻤﺪ ﺳﺎﻣﺮ ﻠﻮ ﺣﻴﺚ اﺳﺘﻔ‬ ‫ﺳﻠ‬ ‫ﻣﺤ‬ ‫أﻳﻀﺎ‬‫ب ﻓﻲ ﻫﺬا‬ ‫ﻚ ﻟﻠﻌﺮب ﺸﺮﻓﻴﻪ ﻋﻠﻰ ﺗﺸﺠﻴﻌﻬﻢ ﻟﻲ ﻟﺘﻘﺪﻳﻢ ﻛﺘﺎب‬ ‫ﺗ‬ ‫وﻣﺸ‬ ‫ﻛﻤﺎ د اﻟﺸﻜﺮ ﻹداارة ﻣﻨﺘﺪى ﻴﺠﻮال ﺑﻴﺴﻚ‬ ‫ﻓﻴ‬ ‫أﺟﺪد‬ ‫م ...‬ ‫ذ ﻋﺒﺪ اﷲ ﺘﻴﻖ ﻣﺪﻳﺮ ﻗﻊ واﻷخ ﺪ ﺑﺪر ، وﺑﺎﻗﻲ اﻹﺧﻮة اﻟﻜﺮام‬ ‫أﺣﻤﺪ‬ ‫اﻟﻤﻮﻗ‬ ‫اﻟﻌﺘ‬ ‫اﻟﻤﺠﺎل ، أﺧﺺ ﺑﺎﻟﺬﻛﺮ ﻣﻨﻬﻢ اﻷﺳﺘﺎذ‬‫اﻟﺸﻜﺮ ﻀً ﻟﻜﻞ ﻣﻦ اﻟﻤﻬﻨﺪس ﻤﺪ ﻋﻴﺴﻮي، ﻟﻤﻬﻨﺪس ﺪ اﻟﻨﺒﻬﺎﻧﻲ ﻰ ﻣﺴﺎﻋﺪﺗﻬﻢ ﻟﻲ ﻟﺘﻨﻘﻴﺢ ﺬا اﻟﻜﺘﺎب ،‬ ‫ﻫﺬ‬ ‫ﻋﻠﻰ‬ ‫ﻣﺤﻤﺪ‬ ‫اﻟ‬ ‫أﺣﻤ‬ ‫أﻳﻀﺎ‬‫ء ، أﺷﻜﺮ ﻟﻬﻢ ﺗﻔﺮﻳﻎ ﺟﺰء ﻣﻦ وﻗﺘﻬﻢ ﺮاءة اﻟﻜﺘﺎب‬ ‫ﻟﻘﺮ‬ ‫ﻣ‬ ‫ﻓﺎﻟﻨﺴﺦ ااﻷوﻟﻰ ﻣﻦ ﻜﺘﺎب ﻛﺎﻧﺖ ﺗﺰﺧﺮ – وﻻ ﺗﺰال - ﺑﺎﻷﺧﻄﺎء‬ ‫ل‬ ‫ﺗ‬ ‫اﻟﻜ‬ ‫ﻲ وﻣﺴﺎﻋﺪﺗﻲ ﻋﻠﻰ ﺗﺪارك ﺬه اﻟﻤﺸﻜﻞ ﻗﺒﻞ إﺧﺮاج ﺴﺨﺔ اﻷﺧﻴﺮة .‬ ‫اﻟﻨﺴ‬ ‫ﻫﺬ‬ ‫ﻋ‬ ‫وﺗﻮﺟﻴﻬﻲ‬ ‫ﺷﻜﺮ ص ﺟﺪً ...‬ ‫ﺧﺎص ا‬‫ﻢ ﻓﻲ ﺗﻨﻘﻴﺢ‬ ‫ﺳﺔ ﻧﻮرﻫﺎن ﻋﺎﺎدل ﻟﻴﺲ ﻓﻘﻂ ﻟﻤﺴﺎﻋﺪﺗﻬﻢ‬ ‫ﻂ‬ ‫ﻴﻦ ، واﻟﻤﻬﻨﺪﺳ‬ ‫ﺪس اﻟﻄﺒﻴﺐ وﻟﻴﺪ ﺑﻮاﻟﻄﻤﻴ‬ ‫ﺷﻜﺮ ص ﺟﺪً ﻟﻠﻤﻬﻨﺪ‬ ‫ﺧﺎص ا‬‫ﻞ ﺑﺪءً ﻣﻦ‬ ‫ا‬ ‫ﻣﺤﺘﻮﻳﺎت اﻟﻜﺘﺎب ، ﻜﻦ ﻷن ﺘﺎب اﻟﺬي ه أﻣﺎﻣﻚ ﻫﻢ ﻣﻦ ﻗﺎﻣﻮا ﺑﺎﺎﺧﺮاﺟﻪ ﻟﻴﻜﻮن ﺑﻬﺬا اﻟﺸﻜﻞ‬ ‫ن‬ ‫ﺗﺮاه‬ ‫اﻟﻜﺘ‬ ‫ﻟﻜ‬‫ء ﺑﺘﺼﻤﻴﻢ ﻐﻼف ، أﻛﺮر ﺷﻜﺮي ﻟﻬﻢ‬ ‫اﻟﻐ‬ ‫ﺗﺼﻤﻴﻢ اﻟﺼﻔﺤﺎت ﺳﻠﻮب ض واﻟﻜﺘﺎﺑﺔ واﻷﻣﺜﻠﺔ واﻟﺘﻨﺴ‬ ‫ﺴﻴﻖ ، واﻧﺘﻬﺎء‬ ‫اﻟﻌﺮض‬ ‫وأﺳ‬ ‫وأﻗﺪر ﻢ ﻛﺜﻴﺮً ﻣﺎ ﻟﻮه ﻣﻦ ﺟﻬﺪ ﻹﺧﺮاج ﻫﺬا ﻜﺘﺎب ﻓﻲ ﻬﻰ ﺣﻠﺔ .‬ ‫أﺑﻬ‬ ‫اﻟﻜ‬ ‫ا ﺑﺬﻟ‬ ‫ﻟﻬﻢ‬‫ت ﻣﻨﻬﻢ ﻓﻲ إﻋﺪاد وإﻧﺘﺎج ﻫﺬا اﻟﻜﺘﺎب ، واﻋﺘﺬر ﻟﻤﻦ ﻟﻢ ﺧﺎﻧﺘﻨﻲ ااﻟﺬاﻛﺮة ﻓﻠﻢ‬ ‫ﻦ‬ ‫اﻟﺸﻜﺮ ﻋﺎﺎم أﻳﻀً ﻞ ﻣﻦ اﺳﺘﻔﺪت‬ ‫ﺎ ﻟﻜﻞ‬‫أذﻛﺮه ﻫﻨﺎ ، اﻟﺸﻜﺮ ﻳﻀﺎ ﻟﺠﻤﻴﻊ ﻦ اﺳﺘﻔﺪت ﻣﻨﻬﻢ ﻓﻲ ﺣﻴﺎﺎﺗﻲ اﻟﻌﺎﻣﺔ و ﻓﻲ دراﺳﺘﻲ ، ﻷﻫﻠﻲ ﻄﺒﻊ وﻟﺠﻤﻴﻊ‬ ‫ﺑﺎﻟﻄ‬ ‫أو‬ ‫ﻣﻦ‬ ‫أﻳ‬ ‫ﻫﻨ‬ ‫ﻪ ﻟﻲ ﻹﺗﻤﺎم ﺬا اﻟﻜﺘﺎب .‬ ‫ﻫﺬ‬ ‫أﺻﺪﻗﺎﺋﻲ ﺑﻼ اﺳﺘﺜﻨﺎء ، وﻗﺒﻞ ذﻟﻚ اﻟﺤﻤﺪ ﷲ أو ً وآﺧﺮً ﻋﻠﻰ ﻮﻓﻴﻘﻪ وإﻋﺎﻧﺘﻪ‬ ‫ﺗﻮ‬ ‫ا‬ ‫ﻻ‬‫82‬
  • ‫ـﺘـﺎب‬ ‫ﻫـﺬا اﻟﻜـ ب‬ ‫ﻫ‬‫ء اﻟﺒﺮاﻣﺞ ﻤﺬﻛﻮرة ﻲ ﻫﺬا اﻟﻜﺘﺎب ﻣﺜﻞ ‪ Office، Window‬وﻏﻴﺮﻫﺎ ﻲ ﻋﻼﻣﺎت‬ ‫ﻫﻲ‬ ‫‪ws‬‬ ‫ﻓﻲ‬ ‫اﻟﻤ‬ ‫- أﺳﻤﺎء‬‫ﺗﺠﺎرﻳﺔ ﻣﺴﺠﻠﺔ ﺻﺤﺎﺑﻬﺎ و ااﻟﻜﺎﺗﺐ ﻖ ﺑﻤﻠﻜﻴﺘﻬﺎ ﻷﺻﺤﺎﺑﻬﺎ وان ﻟﻢ ﺸﺮ إﻟﻰ ﻚ ﻣﺒﺎﺷﺮة‬ ‫ذﻟﻚ‬ ‫ﻳﺸ‬ ‫ﻳﺤﻖ‬ ‫ﻷﺻ‬ ‫ﻟﻼﺧﺘﺼﺎﺎر.‬‫ﺔ ﻟﻠﻤﻠﺨﺺ ، إﻻ أن ﻜﺎﺗﺐ ﻏﻴﺮ ﻣﺴﺆول ي ﺣﺎل ﻋﻦ‬ ‫ﺑﺄي‬ ‫ﻣ‬ ‫اﻟﻜ‬ ‫- ﺗﻢ ﺧﺘﺒﺎر اﻏﻠﺐ ﻣﺤﺘﻮﻳﺎت ﻤﺎدة اﻟﻌﻠﻤﻴﺔ‬ ‫اﻟﻤ‬ ‫اﺧ‬ ‫ﻬﺎ أو ﺳﻮء اﺳﺘﺨﺪاﻣﻬﺎ.‬ ‫ﻣﺤﺘﻮﻳﺎﺗﻬ‬‫ﺪاﻣﻪ ﻷي ﺮض ﺗﺠﺎري‬ ‫ﻏﺮ‬ ‫ﻪ أو اﺳﺘﺨﺪ‬ ‫ق اﻟﻜﺘﺎب ﻣﺤﻔﻮﻇﺔ ﺆﻟﻒ ، وﻻ ﻳﺤﻖ ﻃﺒﺎﻋﺘﻪ أو ﺗﻮزﻳﻌﻪ‬ ‫ﺘﻪ‬ ‫ﻟﻠﻤﺆ‬ ‫ﻣﺤ‬ ‫- ﺣﻘﻮق‬ ‫ﻒ.‬ ‫ﺑﺪون ذن ﻣﻦ اﻟﻤﺆﻟﻒ‬ ‫أذ‬‫ب ، وﻟﻜﻦ ﻫﺬا ﻻ ﻳﻤﻨﻊ وﺟﻮد أﻛﻮاد ﻏﻴﺮ ﻣﺠﺮﺑﺔ أو ﻣﺠﺮب‬ ‫د‬ ‫ﻫ‬ ‫- أﻏﻠﺐ اﻷﻛﻮاد ﻢ ﺗﺠﺮﻳﺒﻬﺎ دااﺧﻞ اﻟﻜﺘﺎب‬ ‫ﺗﻢ‬ ‫ا‬ ‫اﺗﺠﺎه وااﺣﺪ ﻣﻨﻬﺎ ﻘﻂ #‪ C‬أو ‪ ، VB.net‬ﻟﺬا ﺳﺄﻛﻮن‬‫ن ﺳﻌﻴﺪً ﻟﻮ ارﺳﻠﺖ ﻧﺘﺎﺎﺋﺞ ﺗﺠﺎرﺑﻚ ﻋﻠﻰ ﺑﺮﻳﺪي‬ ‫ﻓﻘ‬ ‫ﻧﻲ.‬ ‫اﻹﻟﻜﺘﺮوﻧ‬ ‫ﻨﻲ ﻟﺘﺨﺒﺮﻧﻲ ﺑﻪ.‬ ‫ﺑ‬ ‫ﺲ اﻟﻄﺮﻳﻘﺔ ﻟﻮ وﺟﺪت ﺧﻄﺌً إﻣﻼﺋﻴً أو ﺗﻌﺒﻴﺮﻳً ﺳﺄﻛﻮن ﻌﺪ ﻟﻮ راﺳﻠﺘﻨ‬ ‫أﺳﻌ‬ ‫ﺎﺳ‬ ‫ﺎ‬ ‫ﺧ ﺎ‬ ‫- وﺑﻨﻔﺲ‬‫- ﺑﻌﺾ اﻷﻛﻮاد ﻮﺟﻮدة ﺴﺖ ﻣﻦ ﻒ اﻟﻜﺎﺗﺐ ، ﺑﻞ ﻣﻨﻬﺎ ﻣﻨﻘﻮل وﺗﻤﺖ اﻹﺷﺎرة ﻟﻰ ﻋﻤﻠﻴﺎت‬ ‫إﻟ‬ ‫ﺖ‬ ‫ﻣ‬ ‫ﺗﺄﻟﻴﻒ‬ ‫ﻟﻴﺴ‬ ‫اﻟﻤﻮ‬‫ة ﻟﻤﺼﺪره‬ ‫اﻟﻨﻘﻞ ﺣﺎل وﺟﻮدﻫﺎ ، وﻣﻊ ﻚ ﻓﺎﻟﻤﺆﻟﻒ ﻳﻌﺘﺬر ﻋﻦ ي ﻧﻘﻞ ﻏﻴﺮ واﺿﺢ أو ﻟﻢ ﺗﺘﻢ اﻹﺷﺎرة‬ ‫و‬ ‫أي‬ ‫ﻳ‬ ‫ذﻟﻚ‬ ‫ﺣ‬ ‫ﺑﺼﻮرة ﺻﺤﻴﺤﺔ.‬‫- ﻂ اﻟﻤﻮاﻗﻊ ﻤﻮﺟﻮدة ﻲ اﻟﻜﺘﺎب ﻢ اﻟﺘﺤﻘﻖ ﻦ ﺳﻼﻣﺘﻬﺎ وﻗﺖ إﻧﺘﺎج ﻫﺬا اﻟﻜﺘﺎﺎب إﻻ أن‬ ‫ج‬ ‫ﻣﻦ‬ ‫ﺗﻢ‬ ‫ﻓﻲ‬ ‫اﻟﻤ‬ ‫رواﺑﻂ‬ ‫اﻟﻜﺎﺗﺐ ﻻ ﻳﻀﻤﻦ ﻋﻤﻠﻬﺎ أﺛﻨﺎء ﻗﺮاءﺗﻚ ﺘﻮﻳﺎﺗﻪ.‬ ‫ﻟﻤﺤﺘ‬ ‫ﻗ‬ ‫ﻋ‬‫إﻧﺘﺎﺎج و ﺗﺼﻤﻴﻢ ﻗﻊ ﻓﻴﺠﻮال ﺴﻚ ﻟﻠﻌﺮب ‪vb4arab.co‬‬ ‫‪om‬‬ ‫ﺑﻴﺴ‬ ‫ﻣﻮﻗ‬‫92‬
  • ‫ﺘــﺎب‬ ‫ﻣـﺤـﺘـــﻮﻳـﺎﺎت اﻟﻜﺘ ب‬ ‫ﻣ‬‫ﻳﻀﻢ ﺬا اﻟﻜﺘﺎب ﻣﺠﻤﻮﻋﺔ ﻣﻦ أﺳﺎﺳﻴﺎت ﻋﺎﻟﻢ ‪ .net‬وﺗﺤﺪﻳﺪً .8002 ‪ net‬ﻋﺒﺮ ﻋﺪد ﻦ اﻟﻔﺼﻮل‬ ‫ﻣﻦ‬ ‫ا 8‬ ‫ﻣ‬ ‫ﻫﺬ‬ ‫ب ، ﻫﺬا ﺟﺰﻫﺎ:‬ ‫ﻣﻮﺟ‬ ‫واﻷﺑﻮاب‬‫ت اﻟﻜﺘﺎب واﻟﻔﻬﺮس ﺑﻴﺎﻧﺎت ﻋﻦ‬ ‫وﺑ‬ ‫و‬ ‫اﻟﺒﺎب ﻷول: ﻫﺬا ﻟﺒﺎب ﻟﻴﺲ أﻛﺜﺮ ﻣﻦ ﻮﻧﻪ ﻣﻘﺪﻣﺔ ﻋﻦ ﻣﺤﺘﻮﻳﺎت‬ ‫ﻛﻮ‬ ‫اﻟ‬ ‫اﻷ‬ ‫ﻛﺎﺗﺐ ﻟﻜﺘﺎب ﺗﻔﺎﻗﻴﺔ.‬ ‫واﻻﺗ‬ ‫اﻟ‬ ‫ق ﻓﻲ ﻋﺎﻟﻢ .8002 ‪ net‬ﺣﻴﺚ ﻮدك ﻫﺬا اﻟﺠﺰء ﻟﺘﺤﻤﻴﻞ‬‫ﻞ ﻧﺴﺨﺘﻚ‬ ‫ﻳﻘﻮ‬ ‫اﻟﺒﺎب ﺜﺎﻧﻲ: ﻫﻨﺎ ﺒﺪأ اﻹﻧﻄﻼق‬ ‫ﺗﺒ‬ ‫اﻟﺜ‬ ‫دﻳﻮ وﺑﺮﻣﺠﺔ ﺑﺮﻧﺎﻣﺠﻚ ول وﻛﻴﻔﻴﺔ اﻟﺘﺮﻗﻴﺔ ﻦ اﻹﺻﺪارات اﻟﻤﺨﺘﻠﻔﺔ.‬ ‫ت‬ ‫ﺑﻴﻦ‬ ‫اﻷو‬ ‫ﺑ‬ ‫ﻣﻦ ﺠﻮال ﺳﺘﻮد‬ ‫اﻟﻔﻴﺠ‬‫ﺰك ﻋﻠﻰ ﻻﻧﻄﻼق ﻓﻲ ﻋﺎﻟﻢ . ‪ ،ne‬ﺣﻴﺚ ﻳﺴﺮد ﻟﻚ‬ ‫‪et‬‬ ‫اﻻ‬ ‫اﻟﺒﺎب ﻟﺜﺎﻟﺚ: ﻫﺬا اﻟﺒﺎب ﺼﺺ ﻟﺘﺤﻔﻴﺰ‬ ‫ﻣﺨﺼ‬ ‫اﻟ‬ ‫‪et‬‬‫ﺪة اﻟﺘﻲ رﺑﻤﺎﺎ ﺗﻘﻨﻌﻚ ﻀﺮورة اﻗﺘﺤﺎم ﻋﺎﻟﻢ . ‪ ،ne‬إذا ﻟﻢ‬ ‫ﺑﻀ‬ ‫ﺑﺼﻮرة ﻣﺨﺘﺼﺮة ﺬة ﻋﻦ ﻨﻴﺎت اﻟﺠﺪﻳﺪ‬ ‫اﻟﺘﻘﻨ‬ ‫ﻧﺒﺬ‬ ‫ﻌﺮاض اﻟﺠﺪﻳﺪ ﻓﻘﻂ.‬ ‫ﺪ‬ ‫ﺗﻜﻦ ﺮﻣﺠً ﻣﻦ ﻞ ﻓﻬﺬا ب ﻟﻴﺲ ﺼﺼً ﻟﻚ ﺳﻮى ﻻﺳﺘﻌ‬ ‫ﺳ‬ ‫ﻣﺨﺼ ﺎ‬ ‫اﻟﺒﺎب‬ ‫ﻗﺒﻞ‬ ‫ﻣﺒﺮ ﺎ‬ ‫اﻟﺒﺎب ﺮاﺑﻊ: ﻫﻨﺎ ﺠﺪ وﺻﻔً ﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ.‪ net‬ﺴﻴﺔ وﻋﻨﺎﺻﺮﻫ‬ ‫ﻫﺎ اﻟﻤﺨﺘﻠﻔﺔ.‬ ‫اﻟﺮﺋﻴﺴ‬ ‫ﺎ ﻟﻤﻔ‬ ‫ﺗﺠ‬ ‫اﻟﺮ‬‫ﻚ، ﺣﻴﺚ ﻌﺮض ﻟﻚ ﻫﺬا اﻟﺒﺎب‬ ‫ﻫ‬ ‫ﻳﻌ‬ ‫ﻼق ﻓﻲ ﺼﻤﻴﻢ ﺑﺮاﻣﺠﻚ‬ ‫ﺗﺼ‬ ‫ﻄﻴﻊ اﻻﻧﻄﻼ‬ ‫اﻟﺒﺎب ﻟﺨﺎﻣﺲ: ﻦ ﻫﻨﺎ ﺗﺴﺘﻄ‬ ‫ﻣﻦ‬ ‫اﻟ‬ ‫‪ Visual S‬ﻛﺒﻴﺌﺔ اﻟﺒﺮﻣﺠ‬‫ﺠﺔ اﻟﺨﺎﺻﺔ‬ ‫ﻛ‬ ‫ﺠﺔ وﻣﻦ ﺛﻢ ﻛﻴﻔﻴﺔ ﻄﻼق ﻓﻲ ﻋﺎﻟﻢ ‪Studio‬‬ ‫اﻻﻧﻄ‬ ‫ﻛﻴﻔﻴﺔ اﻟﺒﺪء ﺑﺎﻟﺒﺮﻣﺠ‬ ‫ﺑﻚ.‬‫اﻟﺒﺎب ﺴﺎدس: ﻨﺎ ﺳﻨﺒﺪأ ﺳﺘﻌﺮاض ﻋﻨﺎﺎﺻﺮ اﻟﻠﻐﺔ اﻷﺳﺎﺳﻴﺔ وﻛﻴﻔﻴﺔ ﺑﺘﻬﺎ، ﻫﺬا ﺒﺎب ﻣﻮﺟﻪ‬ ‫اﻟﺒ‬ ‫ﻛﺘﺎﺑ‬ ‫و‬ ‫ﺑﺎﺳ‬ ‫ﻫﻨ‬ ‫اﻟﺴ‬ ‫ﺑﺼﻮرة أﺳﺎﺳﻴﺔ ﻤﺒﺘﺪﺋﻴﻦ ﻮ ﻓﻘﻂ ﻛﻴﺮ ﺑﺄﺳﺎﻟﻴﺐ ﻛﺘﺎﺑﺔ ﺔ ﻟﻠﻤﺤﺘﺮﻓﻴﻦ.‬ ‫ﻦ‬ ‫اﻟﻠﻐﺔ‬ ‫ﺗﺬﻛ‬ ‫وﻫﻮ‬ ‫ﻟﻠﻤ‬ ‫ﻤﺮار ﻟﻠﺒﺎب ﻟﺴﺎﺑﻖ ﻦ ﺑﺼﻮرة ﻘﺪﻣﺔ ﻧﺴﺒﻴً.‬ ‫ﺎ‬ ‫ﻣﺘﻘ‬ ‫اﻟﺴ وﻟﻜﻦ‬ ‫اﻟﺒﺎب ﺴﺎﺑﻊ: اﺳﺘﻤ‬ ‫اﻟﺴ‬‫ﻚ ﻟﻠﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ ﺟﻪ ‪ OOP‬ﺣﻴﺚ ﻳﻤﻜﻨﻚ اﻟﺘﻌﺮف ﻠﻰ اﻟﻔﺌﺎت‬ ‫ﻋﻠ‬ ‫ﻚ‬ ‫ﺣ‬ ‫اﻟﺘﻮﺟ‬ ‫ﻛ‬ ‫اﻟﺒﺎب ﻟﺜﺎﻣﻦ: ﻫﺬه ﻫﻮ ﻣﺪﺧﻠﻚ‬ ‫اﻟﺜ‬ ‫ﺔ اﻟﻌﻤﻞ ﻣﻦ ﺧﻼﻟﻬﺎ .‬ ‫ﺗﻬﺎ وﻛﻴﻔﻴﺔ‬ ‫وﻣﺤﺘﻮﻳﺎﺗ‬ ‫ﻬﺎ ﻓﻲ اﻟﺒﺮﻣﺠﺔ.‬ ‫ﺔ‬ ‫و‬ ‫وﺧ‬ ‫اﻟﺒﺎب ﺘﺎﺳﻊ: ﺟﻬﺎت ‪aces‬‬ ‫‪ Interfa‬ﺧﺼﺎﺋﺼﻬﺎ واﺳﺘﺨﺪاﻣﺎﺗﻬ‬ ‫اﻟﻮاﺟ‬ ‫اﻟﺘ‬ ‫د وﻛﻴﻔﻴﺔ ﻣﻌﺎﻟﺠﺘﻬﺎ ﻘﻴﺤﻬﺎ.‬ ‫وﺗﻨﻘ‬ ‫ﻣ‬ ‫ك ﻓﻲ اﻟﻜﻮد‬ ‫اﻟﺒﺎب ﻌﺎﺷﺮ: ﻫﺬا اﻟﺒﺎب ﻟﻚ ﻣﻦ أﺟﻞ ﻨﺎص أﺧﻄﺎءك‬ ‫اﻗﺘﻨ‬ ‫ﻣ‬ ‫اﻟﻌ‬‫03‬
  • ‫اﻟﺒﺎب اﻟﺤﺎدي ﻋﺸﺮ: ﻳﺴﺮد ﻫﺬا اﻟﺒﺎب ﺑﺎﻟﺘﻔﺼﻴﻞ أﻧﻮاع ال ‪ Collections‬واﺳﺘﺨﺪاﻣﺎﺗﻬﺎ اﻟﻤﺘﻜﺮرة‬ ‫ﻓﻲ ﺑﺮاﻣﺠﻨﺎ اﻟﻤﺨﺘﻠﻔﺔ .‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ: اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻫﺬه اﻟﻤﺮة ، ﺣﻴﺚ ﺳﺘﺘﻌﺮف ﻋﻠﻰ ﻋﻨﺎﺻﺮ أﻛﺜﺮ ﺗﻘﺪﻣً ﻓﻲ ﻟﻐﺔ‬ ‫ﺎ‬ ‫اﻟﺒﺮﻣﺠﺔ وﻓﻲ ﻋﺎﻟﻢ .‪net‬‬ ‫اﻟﺒﺎب اﻟﺜﺎﻟﺚ ﻋﺸﺮ: ﻃﺮق اﻹدﺧﺎل واﻹﺧﺮاج اﻟﻤﺨﺘﻠﻔﺔ وﻛﻴﻔﻴﺔ اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻤﻠﻔﺎت .‬‫اﻟﺒﺎب اﻟﺮاﺑﻊ ﻋﺸﺮ: اﻻﻧﻄﻼق ﻓﻲ ﻋﺎﻟﻢ ﺑﺮﻣﺠﺔ ال‪ Windows Forms‬واﻷدوات اﻟﺘﻲ ﺗﺤﺘﻮﻳﻬﺎ‬ ‫واﻟﺨﺼﺎﺋﺺ واﻟﺮﺳﻢ وﺧﻼﻓﻪ .‬‫اﻟﺒﺎب اﻟﺨﺎﻣﺲ ﻋﺸﺮ: ﻳﺄﺧﺬك ﻓﻲ رﺣﻠﺔ ﺳﺮﻳﻌﺔ ﻓﻲ ﻋﺎﻟﻢ اﻟﺮﺳﻮﻣﻴﺎت ﺛﻨﺎﺋﻴﺔ اﻷﺑﻌﺎد ﻣﻦ ﺧﻼل‬ ‫‪. +GDI‬‬‫اﻟﺒﺎب اﻟﺴﺎدس ﻋﺸﺮ: ﺑﺪاﻳﺔ ﻟﺘﻘﻨﻴﺔ ‪ WPF‬اﻟﻤﺨﺘﺼﺔ ﺑﺎﻟﺮﺳﻮﻣﻴﺎت ﺛﻨﺎﺋﻴﺔ وﺛﻼﺛﻴﺔ اﻷﺑﻌﺎد وأدواﺗﻬﺎ‬ ‫وﺑﺮاﻣﺠﻬﺎ اﻟﻤﺨﺘﻠﻔﺔ .‬‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ ﻋﺸﺮ: ﻓﻲ ﻫﺬا اﻟﺒﺎب ﻳﻤﻜﻨﻚ اﻻﻧﻄﻼق ﻓﻲ ﻋﺎﻟﻢ ﺑﺮﻣﺠﺔ ﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت ﻣﻦ ﺧﻼل‬ ‫‪ ADO.net‬وﻣﺎ ﻳﺴﺘﻠﺰم ذﻟﻚ ﻣﻦ ﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت ‪ SQL Server‬وﺧﻼﻓﻪ .‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ ﻋﺸﺮ: اﻟﺘﻘﻨﻴﺔ اﻟﺠﺪﻳﺪة ﻣﻦ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ ﻟﻼﺳﺘﻌﻼم ‪ LINQ‬ﻳﻤﻜﻨﻚ اﻟﺒﺪء ﺑﻬﺎ ﻫﻨﺎ.‬ ‫اﻟﺒﺎب اﻟﺘﺎﺳﻊ ﻋﺸﺮ: ﻫﻨﺎ ﻧﺒﺪأ ﻓﻲ ﻋﺎﻟﻢ ﺗﻘﻨﻴﺔ ‪ WWF‬اﻟﺠﺪﻳﺪة ﻣﻦ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ ﻹدارة اﻟﻤﺸﺎرﻳﻊ.‬ ‫اﻟﺒﺎب اﻟﻌﺸﺮون: أﻳﻀً ﻣﻊ ﻋﺎﻟﻢ ‪ WCF‬ﻟﻤﺸﺎرﻛﺔ اﻟﺒﺮاﻣﺞ واﻟﺘﻄﺒﻴﻘﺎت ﻣﻦ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ.‬ ‫ﺎ‬‫اﻟﺒﺎب اﻟﺤﺎدي واﻟﻌﺸﺮون : ﻣﺠﻤﻮﻋﺔ ﻣﻦ اﻟﻤﻮاﺿﻴﻊ اﻟﻬﺎﻣﺔ ﺗﺘﻌﻠﻖ ﺑﺘﺸﻐﻴﻞ ﺑﺮﻧﺎﻣﺠﻚ ﻋﻠﻰ اﻷﺟﻬﺰة‬ ‫اﻟﻤﺨﺘﻠﻔﺔ ﻗﺒﻞ اﻻﻧﻄﻼق ﻓﻲ ﻋﺎﻟﻢ اﻟﻮﻳﺐ ﻓﻲ اﻟﺒﺎب اﻟﻼﺣﻖ .‬‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ واﻟﻌﺸﺮون : اﻟﺒﺎب اﻷﺧﻴﺮ ، ﻳﻤﻜﻨﻚ ﻫﺬا اﻟﺒﺎب ﻣﻦ ﺗﻄﻮﻳﺮ ﺗﻄﺒﻴﻘﺎت وﻳﺐ ﺗﻔﺎﻋﻠﻴﺔ ﻣﻦ‬ ‫ﺧﻼل ‪. ASP.net‬‬ ‫أرﺟﻮ ﻣﻦ اﷲ أن ﻳﻜﻮن ﻓﻲ ﺑﻌﺾ ﻣﺤﺘﻮﻳﺎﺗﻬﺎ اﻟﻔﺎﺋﺪة واﻟﻨﻔﻊ...‬‫13‬
  • ‫ﻟﻤﻦ ﺬا اﻟﻜ ب؟‬ ‫ﻫـﺬ ﻜـﺘـﺎب‬‫ﺐ ﺑﺎﻟﻨﺴﺒﺔ ﻲ ﻃﻮال ﺸﻮاري ﻓﻲ ﻤﻞ ﻫﺬا ﻜﺘﺎب، ﻓﻬﺬا اﻟﻜﺘﺎب ﻻ‬ ‫اﻟﻜﺘ‬ ‫ﻋﻤ‬ ‫ﻣﺸ‬ ‫ﻟﻲ‬ ‫إﺟﺎﺑﺔ ﺬا اﻟﺴﺆال ﻫﻲ اﻷﺻﻌﺐ‬ ‫ﻫ‬ ‫ﻫﺬ‬‫ﺔ، ﻓﻬﻮ ﻳﺤﺎﺎول أن ﺘﺒﺲ ﻣﻦ ﻛﻞ ﺑﺴﺘﺎن‬ ‫ﻛ‬ ‫ﻳﻘﺘ‬ ‫ف ﻣﺴﺘﻮى ﻣﻌﻴﻦ ﺲ ﻣﺨﺼﺼً ﻟﻔﺌﺔ ﻣﻌﻴﻨﺔ‬ ‫ﺎ‬ ‫وﻟﻴﺲ‬ ‫ﻳﺴﺘﻬﺪف‬ ‫ﻖ أﻳً ﻛﺎن ﻣﺴﺘﻮاك.‬ ‫ﻣ‬ ‫زﻫﺮة، ﻳﻀﻌﻚ ﻰ أول اﻟﻄﺮﻳﻖ ﺎ‬ ‫ﻋﻠﻰ‬ ‫وﻳ‬‫ﺎ‬‫ﻓﺈذا ﺖ ﻣﺒﺘﺪءً ﻓﺄﺑﻮاب ﺘﺎب اﻷوﻟﻰ ﺗﻮﺿﺢ ﻟﻚ رﺑﻤﺎ أﺳﺎﺳﻴﺎﺎت اﻟﺒﺮﻣﺠﺔ ، أﻣﺎ ﻟﻮ ﻨﺖ ﻣﺤﺘﺮﻓً‬ ‫ﻛﻨ‬ ‫ﺗ‬ ‫اﻟﻜﺘ‬ ‫اﻓ‬ ‫ﻛﻨﺖ‬‫ﺎ‬‫ﻚ ﻣﻌﺮﻓﺔ ﺠﺪﻳﺪ ﻓﻘﻂ واﻻﻧﻄﻼق ﻓﻲ اﻷﺑﻮاب اﻟﺘﻲ ﺗﺨﺘﺎرﻫﺎﺎ ﻟﻨﻔﺴﻚ ، أﻣﺎ ﻟﻮ ﺖ ﻣﺘﻮﺳﻄً‬ ‫ﻛﻨﺖ‬ ‫ﻓ‬ ‫و‬ ‫اﻟﺠ‬ ‫ﻓﻴﻜﻔﻴﻚ‬ ‫ﻓﻬﺬا ﻜﺘﺎب ﻜﻮن ﻧﻘﻄﺔ ﻧﻄﻼق ة ﻟﻚ ﻓﻲ ﺪة ﻓﺮوع ﻦ ﻋﺎﻟﻢ . 02 ‪. net‬‬ ‫800‬ ‫ﻣﻦ‬ ‫ﻋﺪ‬ ‫ﺟﻴﺪة‬ ‫اﻧ‬ ‫ﺳﻴﻜﻮ‬ ‫اﻟﻜ‬‫ﻟﺬا ﻮ أن ﻻ ﻞ اﻟﻤﺤﺘﺮف ﻣﻦ ﻛﺜﺮة ﺘﻜﺮارات ﻲ اﻟﻜﺘﺎب ، أو ﺗﻮﺿﻴﺢ اﻟﻮاﺿﺢ ﺼﻮﺻً ﻓﻲ‬ ‫ﺧﺼ ﺎ‬ ‫ﻓﻲ‬ ‫اﻟﺘ‬ ‫ﻣ‬ ‫ﻳﻤﻞ‬ ‫أرﺟﻮ‬‫ﺳﻴﺎت ، ﺚ ﻳﻤﻜﻨﻪ ﺠﺎوز اﻟﻨﻘﺎط اﻷﺳﺎﺳﻴﺔ واﻟﺪﺧﻮل ﻓﻮرً ﻓﻲ ﻘﺎط اﻟﺘﻲ ﻳﺮاﻫﺎ ﻫﺎﻣﺔ‬ ‫ﻳ‬ ‫اﻟﻨﻘ‬ ‫ﻓ ا‬ ‫ﺗﺠ‬ ‫ﺣﻴﺚ‬ ‫اﻷﺳﺎﺳﻴ‬‫ﺑﺎﻟﻨﺴﺒﺔ ﻟﻪ ، أﻣﺎ إذا ﻛﺎﻧﺖ ﺬه ﻫﻲ ة اﻷوﻟﻰ ﻟﻚ ﻟﻼﻧﻄﻼق ﻓﻲ ﻋﺎﻟﻢ ﻣﺠﺔ ﻓﺤﺎول أﻻ ﺗﻔﻮت‬ ‫اﻟﺒﺮﻣ‬ ‫ﻓ‬ ‫اﻟﻤﺮة‬ ‫ﻫﺬ‬ ‫ﺷﻴﺌً ﻦ ﻣﺤﺘﻮﻳﺎت اﻟﻜﺘﺎب ، ﻔﺼﻮل ﻟﻰ ﺑﺎﻟﻨﺴﺒﺔ ﻟﻚ ﻫﻲ ﺳﺎس ﻛﻞ ﺷﻲء ﺑﻌﺪ ﻚ .‬ ‫ذﻟﻚ‬ ‫ﺷ‬ ‫أﺳ‬ ‫اﻷوﻟ‬ ‫اﻟﻔ‬ ‫ﺎ ﻣﻦ‬‫ﺤﺔ اﻟﺴﺎﺑﻘﺔ ، ﻓﻬﻲ ﺿﺢ ﻟﻚ ﺾ اﻷﺑﻮاب‬ ‫ﺑﻌﺾ‬ ‫ﺗﻮﺿ‬ ‫ب ﻓﻲ اﻟﺼﻔﺤ‬ ‫ﻳﺎت اﻟﻜﺘﺎب‬ ‫ﻊ ﻋﻠﻰ ﻣﺤﺘﻮﻳ‬ ‫ﻳﻬﻤﻨﻲ ﺟﺪً أن ﺗﻄﻠﻊ‬ ‫ﺟ ا‬‫اﻟﺘﻲ ﻴﻜﻮن ﻣﻦ ﻟﻤﻔﻀﻞ وزﻫﺎ ﻟﻚ ﻤﺒﺘﺪئ ، أو ﻛﻤﺤﺘﺮف ﻀً . ﻟﺬا ﻓﻀ ً ﻟﻮ ﺖ ﺗﺠﺎوزت‬ ‫ﻀﻼ ﻛﻨﺖ‬ ‫اﻳﻀﺎ‬ ‫ﻛ‬ ‫ﻛﻤ‬ ‫ﺗﺠﺎو‬ ‫اﻟ‬ ‫ﺳﻴ‬ ‫ﺔ اﻟﺴﺎﺑﻘﺔ ن ﺗﻌﻴﺪ اﻟﻨﻈﺮ ﻓﻴﻬﺎ ﻣﺮة أﺧﺮى.‬ ‫ﻈ‬ ‫أن‬ ‫اﻟﺼﻔﺤﺔ‬‫23‬
  • ‫ﻌﺮﻳــﺐ‬ ‫اﻟﺘﻌ ﺐ‬‫ﻓﻲ ﻛﻞ اﻟﻜﺘﺐ ﻲ ﻗﺮأﺗﻬﺎ ﻠﻐﺔ اﻟﻌﺮﺑﻴﺔ – أو ﻬﺎ – ﻛﻨﺖ أﺟﺪ ﻧﻮﻋً ﻣﻊ ﻋﺪم اﻟﺮاﺣﺔ ﻣﻊ ﻗﺮاءة‬ ‫ﺎ‬ ‫أﻏﻠﺒﻬﺎ‬ ‫ﺑﺎﻟﻠ‬ ‫اﻟﺘﻲ‬‫ﻠﻴﺔ ﺑﺎﻟﻠﻐﺔ اﻹﻧﺠﻠﻴﺰﻳﺔ،‬ ‫اﻟﺘﺮﺟﻤﺔ ، وﻓﻲ ﻞ ﻫﺬه ﻻت ﻛﻨﺖ أﻓﻀﻞ ﻃﻼع ﻋﻠﻰ ﻟﻜﻠﻤﺔ اﻷﺻﻠ‬ ‫اﻟ‬ ‫اﻹﻃ‬ ‫اﻟﺤﺎﻻ‬ ‫ﻣﺜﻞ‬ ‫ﺟﻪ ﺿﻤﻦ ﺬا اﻟﻜﺘﺎب .‬ ‫ﻫﺬ‬ ‫ﺘﻄﺎع اﻧﺘﻬﺎﺟ‬ ‫ﺖ ﻗﺪر اﻟﻤﺴﺘ‬ ‫وﻫﺬا ﻮ اﻷﺳﻠﻮب اﻟﺬي ﺣﺎوﻟﺖ‬ ‫ﻫﻮ‬‫ﻤﺔ ﻟﻜﻠﻤﺘﻲ‬ ‫ﻤﺎت ﻻ و ﺳﻴﺌﺔ ، ﻣﺜﻞ اﻟﺠﻤﻞ اﻟﺸﺮﻃﻴﺔ وﺣﻠﻘﺎت ﺘﻜﺮار ﻛﺘﺮﺟﻤ‬ ‫اﻟﺘ‬ ‫ﺗﺒﺪو‬ ‫ﻫﻨﺎك ﺑﻌﺾ اﻟﺘﺮﺟﻤ‬ ‫ﺑ‬‫‪ Cond‬و ‪ ، Loop‬ﻫﻨﺎﺎك ﺗﺮﺟﻤﺎت رﺑﻤﺎ ﺗﺒﺪو أﻗﻞ ﺟﻮدة وﻟﻜﻨﻬﺎ ﻻ ﻌﺪ ﺳﻴﺌﺔ ﺜﻞ ﺗﻌﺮﻳﻒ‬ ‫ﻣﺜ‬ ‫ﺗﻌ‬ ‫و‬ ‫‪ps‬‬ ‫‪ditions‬‬‫ال ‪ Cla‬ﻋﻠﻰ ﻧﻪ )ﻓﺌﺔ( وﺗﻌﺮﻳﻒ ال ‪ Interface‬ﻋﻠﻰ ﻬﺎ )واﺟﻬﺔ( ، اﻟﻤﺘﻐﻴﺮ ﺑﺪﻳ ً ل‬ ‫ﻼ‬ ‫أﻧﻬ‬ ‫ل‬ ‫و‬ ‫أﻧ‬ ‫‪ass‬‬‫‪ Va‬وﻫﻜﺬا ، ﻓﻲ ه اﻟﺤﺎﻟﺔ ﺘﺠﺪ ﻓﻲ ﻌﺎدة ﺗﻢ ﻛﺮ اﻟﺘﺮﺟﻤﺔ ﻣﺮة واﺣﺪة ﺑﺪﻳ ً ﻋﻦ‬ ‫ﻼ‬ ‫ذﻛ‬ ‫اﻟﻌ‬ ‫ﺳﺘ‬ ‫ﻫﺬه‬ ‫‪ariable‬‬‫ﺔ ﻣﺜﻞ ) ﺸﻴﺪات ، ﻤﻬﺪﻣﺎت ... اﻟﺦ ( ﻼﻓﻪ ﻓﻠﻢ ﺮﻛﻬﺎ ﻛﻠﻬﺎ‬ ‫اﺗﺮ‬ ‫وﺧﻼ‬ ‫اﻟﻤ‬ ‫اﻟﻤﺸ‬ ‫ذﻛﺮﻫﺎ ﻓﻲ ﻛﻞ ة ، أﻣﺎ ﺗﺮﺟﻤﺔ‬ ‫ﻣﺮة‬ ‫ﻓ‬ ‫ﺖ ﻓﻘﻂ ﻣﺎ رأﻳﺘﻪ ﻣﻨﺎﺳﺒً إﻟﻰ ﺣﺪ ﻣﺎ وﺗﺮﻛﺖ ﻘﻴﺔ.‬ ‫اﻟﺒﻘ‬ ‫ﺎ‬ ‫ر‬ ‫وﻟﻢ ﺘﺨﺪﻣﻬﺎ ﻬﺎ، اﺳﺘﺨﺪﻣﺖ‬ ‫ﻛﻠﻬ‬ ‫اﺳﺘ‬‫وﻋﻠﻰ ﻛﻞ ﺛﻖ ﻚ ﻟﻦ ﺗﺠﺪ ﻛﻠﻤﺔ ﻋﺮﺑﻴﺔ ﻟﻢ ﻳﺘﻢ ذﻛﺮ اﻟﻜﻠﻤﺔ ﺻﻠﻴﺔ ﻟﻬﺎ ﻓﻲ أي ﻣﻜﺎن ، أﻳﻀً ﻻ‬ ‫ﺎ‬ ‫ﻲ‬ ‫اﻷﺻ‬ ‫ﻟ‬ ‫ﻛ‬ ‫ﺑﺄﻧﻚ‬ ‫ﻛ‬‫ﺗﺤﺎول اﻻﻋﺘﻤﺎد ﻋﻠﻰ ﺗﺮﺟﻤﺘﻲ ﻲ ﻗﺮاءة ب ﻋﺮﺑﻲ آﺧﺮ ، ﻓﺤﺘﻰ ﺤﻈﺔ ﻻ ﺟﺪ إي ﻧﻮع ﻣﻦ اﻻﺗﻔﺎق‬ ‫ﻣ‬ ‫ﻳﻮﺟ‬ ‫اﻟﻠﺤ‬ ‫ﻛﺘﺎب‬ ‫ﻓﻲ‬‫ت اﻟﻜﻮﻣﺒﻴﻮﺗﺮ ﻓﻀ ً ﻋﻦ أن ﻧﺘﺤﺪث ﻓﻲ اﺗﻔﺎق ﻋﻦ ﺗﺮﺟﻤﺔ‬ ‫ﻼ‬ ‫ﺑﻴﻦ ﻜﺘﺎب ﻋﻠﻰ ﺮﺟﻤﺔ أﻏﻠﺐ ﻣﺼﻄﻠﺤﺎت‬ ‫ﺗﺮ‬ ‫اﻟﻜﺘ‬ ‫ﺤﺎت اﻟﺒﺮﻣﺠﺔ .‬ ‫ﻣﺼﻄﻠﺤ‬‫33‬
  • 34
  • ‫اﻟﺒﺎب‬ ‫2‬ ‫ﺗﺤﻤﻴﻞ ﻧﺴﺨﺘﻚ ﻣﻦ‬ ‫ﻓﻴﺠﻮال ﺳﺘﻮدﻳﻮ 8002‬‫53‬
  • 36
  • ‫ﻮال ﺳﺘﻮدﻳﻮ‬ ‫ﺘﻚ ﻣﻦ اﻟﻔﻴﺠﻮ‬ ‫ﺗﺤﻤﻴﻞ ﻧﺴﺨﺘ‬ ‫ ‬ ‫اﻟﺒﺎب ﻧﻲ‬ ‫اﻟﺜﺎﻧ‬ ‫‪Visual‬‬ ‫‪V‬‬ ‫1. ااﻟﻨﺴﺨﺔ اﻟﻜﺎﻣ ﻦ 02 ‪dio‬‬ ‫ﺔ ﻣﻠﺔ ﻣﻦ 800 ‪l Stud‬‬‫ﺖ، اﻟﻨﺴﺨﺔ‬ ‫‪ Visual  S‬ﻋﻠﻰ ﻣﻮﻗﻊ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ‬ ‫ﻣ‬ ‫ﻋ‬ ‫ﻳﻮﺟﺪ ﻋﺪة ﻧﺴﺨﺔ ﻣﺘﺎﺣﺔ ﺤﻤﻴﻞ ﻣﻦ 002  ‪Studio‬‬ ‫80‬ ‫ﻟﻠﺘﺤ‬ ‫ﻣ‬ ‫ﻋ‬‫ﻬﺎ ﻣﻮﺟﻮدة ﺑﺼﻮرة ﺮﻳﺒﻴﺔ ﻟﻤﺪة‬ ‫ﺗﺠﺮ‬ ‫ﺑ‬ ‫ﺔ ﺑﺼﻮرة ﺠﺎﻧﻴﺔ وﻟﻜﻨﻬ‬ ‫ﻣﺠ‬ ‫‪ Profession‬ﻏﻴﺮ ﻣﺘﺎﺣﺔ‬ ‫اﻟﻜﺎﻣﻠﺔ ‪nal Edition‬‬ ‫ﻫﺎ ﻋﻠﻰ ﻫﺬا اﻟﺮاﺑﻂ:‬ ‫09 ﻳﻮم ﻓﻘﻂ، ﺗﺠﺪﻫ‬ ‫راﺑﻂ‬ ‫‪http://ms‬‬ ‫‪sdn.microsof‬‬ ‫‪ft.com/en-us‬‬ ‫‪s/vs2008/pro‬‬ ‫862‪oducts/cc‬‬ ‫‪8305.aspx‬‬‫ﺎﻣﺞ  ‪ Powe ISO‬ﻫﻮ‬ ‫ ‪er‬‬ ‫اﻟﻨﺴﺨﺔ اﻟﺘﻲ ﻳﺘﻢ ﺤﻤﻴﻠﻬﺎ ﻣﻦ ﻫﺬا اﻟﺮاﺑﻂ ﺗﻜﻮن ﻋﻠﻰ ﺷﻜﻞ ﻣﻠﻒ ‪ *.iso‬ﺑﺮﻧﺎ‬ ‫ﺗﺤ‬‫ﻠﻬﺎ وﻻ ﺑﺪ ﻣﻦ وﺟﻮد‬ ‫ﺑﺮﻧﺎﻣﺞ ﻳﺴﺘﺨﺪم ﻤﺤﺎﻛﺎة ﺟﻮد ‪  CD‬أو ‪ DVD‬ﻓﻲ ﻟﻤﻠﻔﺎت ﻲ ﻳﺘﻢ ﺗﺤﻤﻴﻠ‬ ‫اﻟﺘﻲ‬ ‫اﻟ‬ ‫وﺟ‬ ‫ﻟﻤ‬ ‫اﻟﻘﺮص اﻟﺨﺎص ﺑﻬﺎ .‬ ‫ﻣﺞ ‪wer ISO‬‬ ‫‪ Pow‬ﻣﻦ ﻫﻨﺎ:‬ ‫ﻳﻤﻜﻨﻚ ﺗﻨﺰﻳﻞ ﺑﺮﻧﺎﻣ‬ ‫راﺑﻂ‬ ‫‪http://ww‬‬ ‫‪ww.freedown‬‬ ‫‪nloadscenter‬‬ ‫‪r.com/Utilitie‬‬ ‫‪es/Backup_a‬‬ ‫‪and_Copy_Ut‬‬ ‫‪tilities/Powe‬‬ ‫‪erISO.html‬‬‫ﻓﺖ ﻣﻦ ﻫﺬا‬ ‫‪ Produc‬ﻣﻦ ﻣﺎﻳﻜﺮوﺳﻮﻓ‬ ‫ﺐ ال ‪ct Key‬‬ ‫ﺔ ، ﻗﻢ ﺑﻄﻠﺐ‬ ‫ﺖ ﺗﺮﻏﺐ ﻓﻲ اﻟﺘﺮﻗﻴﺔ ﺴﺨﺔ اﻟﻜﺎﻣﻠﺔ‬ ‫ﻟﻠﻨﺴ‬ ‫إذا ﻛﻨﺖ‬ ‫اﻟﺮاﺑﻂ :‬ ‫راﺑﻂ‬ ‫‪http://ms‬‬ ‫‪sdn.microsof‬‬ ‫‪ft.com/en-us‬‬ ‫‪s/vs2008/pro‬‬ ‫362‪oducts/cc‬‬ ‫‪3903.aspx‬‬‫‪ Add or  Remove P‬ﻢ ﺑﺎﺧﺘﻴﺎر 8002 ‪ ،Visual Studio‬وﻣﻦ ﺛﻢ ﻗﻢ‬ ‫و‬ ‫8‬ ‫وﻗﻢ‬ ‫وﻣﻦ ﺛﻢ ﻗﻢ ﺑﺎﺧﺘﻴﺎر‬ ‫ر ‪Programs‬‬‫ﺖ ﺑﺈرﺳﺎﻟﻪ‬ ‫ﺑﺎﺧﺘﻴﺎر ‪ ... Change/Remove‬ﻗﻢ ﺑﺈدﺧﺎل‬ ‫ل ال ‪ Product  Key‬ﻟﺬي ﻗﺎﻣﺖ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ‬ ‫اﻟ‬ ‫ﻟﻚ.‬‫73‬
  • ‫ﺗﺤﻤﻴﻞ ﻧﺴﺨﺘﻚ ﻣﻦ اﻟﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ‬ ‫2. اﻟﻨﺴﺦ اﻟﻤﺠﺎﻧﻴﺔ ﻣﻦ 8002 ‪Visual Studio‬‬‫إﺿﺎﻓﺔ ﻟﻠﻨﺴﺦ اﻟﻜﺎﻣﻠﺔ اﻟﺘﻲ ﺗﻮﻓﺮﻫﺎ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ، ﺗﻮﻓﺮ أﻳﻀﺎ ﺣﻠﻮل ﻣﺠﺎﻧﻴﺔ ﻟﻠﻤﻄﻮرﻳﻦ، ﺗﺠﺪﻫﺎ ﺟﻤﻴﻌﺎ‬‫ً‬ ‫ﻋﻠﻰ اﻟﺮاﺑﻂ اﻟﺘﺎﻟﻲ:‬ ‫راﺑﻂ‬ ‫‪http://www.microsoft.com/express/product/default.aspx‬‬‫ﻫﺬه اﻟﻨﺴﺦ ال ‪ Express‬اﻗﻞ ﻓﻲ اﻹﻣﻜﺎﻧﻴﺎت ﻣﻦ اﻟﻨﺴﺦ اﻟﻜﺎﻣﻠﺔ ‪ Professional  Edition‬وﻟﻜﻨﻬﺎ ﺗﻌﺪ‬ ‫اﻟﺤﻞ اﻷﻛﺜﺮ اﺳﺘﺨﺪاﻣﺎ ﻣﻦ ﻗﺒﻞ ﻣﻄﻮري اﻟﺪوت ﻧﺖ ، ﺗﺠﺪ اﻟﻨﺴﺦ اﻟﺘﺎﻟﻴﺔ ﻓﻲ اﻟﺮاﺑﻂ اﻟﺴﺎﺑﻖ :‬ ‫ً‬ ‫اﻟﺒﺮﻧﺎﻣﺞ‬ ‫اﻟﻨﺴﺨﺔ‬ ‫ﻧﺴﺨﺔ ﻣﻦ ال .8002 ‪ net‬ﺑﺄﺳﻠﻮب ﻛﺘﺎﺑﺔ ال ‪ Basic‬ﻋﻠﻰ ﺑﻴﺌﺔ‬ ‫ﺗﻄﻮﻳﺮ .‪net Framework‬‬ ‫7153567=‪http://go.microsoft.com/?linkid‬‬ ‫ﻧﺴﺨﺔ ﻣﻦ ال .8002 ‪ net‬ﺑﺄﺳﻠﻮب ﻛﺘﺎﺑﺔ ال #‪ C‬ﻋﻠﻰ ﺑﻴﺌﺔ ﺗﻄﻮﻳﺮ‬ ‫.‪  net Framework‬‬ ‫8153567=‪http://go.microsoft.com/?linkid‬‬ ‫ﻧﺴﺨﺔ ﻣﻦ ال .8002 ‪ net‬ﺑﺄﺳﻠﻮب ﻛﺘﺎﺑﺔ ال ++‪ C‬ﻋﻠﻰ ﺑﻴﺌﺔ‬ ‫ﺗﻄﻮﻳﺮ .‪ net Framework‬ﺗﺴﺘﺨﺪم ﻹﻧﺘﺎج اﻟﺘﻄﺒﻴﻘﺎت اﻟﻤﺨﺘﻠﻔﺔ‬ ‫0253567=‪http://go.microsoft.com/?linkid‬‬ ‫ﺑﻴﺌﺔ ﺗﻄﻮﻳﺮ ﻣﺒﻨﻴﺔ ﻋﻠﻰ‪ .net  Framework‬ﺗﻮﻓﺮ ﻟﻚ أدوات‬ ‫ﻣﺘﻄﻮرة ﻹﻧﺸﺎء ﺗﻄﺒﻴﻘﺎت وﻳﺐ ﻣﺘﻘﺪﻣﺔ‬ ‫9153567=‪http://go.microsoft.com/?linkid‬‬‫83‬
  • ‫ﺗﺤﻤﻴﻞ ﻧﺴﺨﺘﻚ ﻣﻦ اﻟﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ‬ ‫ﻧﻈﺎم ﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت اﻟﻤﺸﻬﻮر، ﻳﻮﻓﺮ ﻟﻚ ﻧﺴﺨﺔ ﻣﺠﺎﻧﻴﺔ ﻹﻧﺸﺎء‬ ‫ﻗﻮاﻋﺪ ﺑﻴﺎﻧﺎت ﺳﻬﻠﺔ اﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺑﺮاﻣﺠﻚ ﻣﻦ  ‪Net‬‬ ‫‪http://www.microsoft.com/express/sql/default.aspx‬‬ ‫أﺣﺪ أدوات ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ اﻟﺠﺪﻳﺪة اﻟﺘﻲ ﺗﺴﻬﻞ ﻋﻤﻠﻴﺔ ﺑﻨﺎء ال‬ ‫ ‪ gadgets‬وال ‪mash‐ups‬‬ ‫‪http://www.microsoft.com/express/popfly/default.aspx‬‬ ‫اﻟﺠﺪول 2. 1. اﻟﻨﺴﺦ ‪ Express‬اﻟﻤﻜﻮﻧﺔ ﻟﺒﻴﺌﺔ اﻟﺘﻄﻮﻳﺮ ‪.net Framework‬‬ ‫3. ﺗﺮﻗﻴﺔ ﻣﺸﺮوﻋﻚ اﻟﺬي ﻳﻌﻤﻞ ﻋﻠﻰ 5002 ‪ VS‬إﻟﻰ‬ ‫8002 ‪VS‬‬‫ﻳﻤﻜﻨﻚ ﻓﺘﺢ ﻧﺴﺨﺔ ﻣﻦ ﻣﺸﺮوﻋﻚ اﻟﻤﺒﻨﻲ ﻣﻦ ﺧﻼل .5002 ‪ net‬ﻟﻴﻌﻤﻞ ﻋﻠﻰ .8002 ‪ net‬ﻟﻼﺳﺘﻔﺎدة‬ ‫ﻣﻦ ﺧﺼﺎﺋﺼﻪ .‬ ‫ﻗﻢ ﺑﻔﺘﺢ اﻟﻤﺸﺮوع ﻣﻦ ﺧﻼل 8002 ‪ VS‬وﺳﻴﻈﻬﺮ ﻟﻚ ﻣﻌﺎﻟﺞ اﻟﺘﺮﻗﻴﺔ ﻣﺒﺎﺷﺮة .‬ ‫•‬ ‫ﻗﻢ ﺑﺎﺧﺘﻴﺎر ‪. Next‬‬ ‫•‬‫ﻗﻢ ﺑﺎﺧﺘﻴﺎر ﻋﻤﻞ ﻧﺴﺨﺔ اﺣﺘﻴﺎﻃﻴﺔ ﻣﻦ اﻟﻤﻠﻔﺎت، ﻗﻢ ﺑﺎﺧﺘﻴﺎر اﻟﻤﻜﺎن اﻟﺬي ﺗﻮد ﺣﻔﻆ اﻟﻨﺴﺨﺔ‬ ‫•‬ ‫اﻟﻘﺪﻳﻤﺔ اﺣﺘﻴﺎﻃﻴﺎ ﻓﻴﻪ.‬ ‫ً‬ ‫ﻗﻢ ﺑﺎﺧﺘﻴﺎر ‪. Finish‬‬ ‫•‬ ‫ﺳﻴﺘﻢ إﻧﻬﺎء اﻟﺘﺮﻗﻴﺔ ، وﺳﺘﺤﺼﻞ ﻋﻠﻰ ﺗﻘﺮﻳﺮ ﺑﺎﻻﻧﺘﻬﺎء ﺑﻌﺪ اﻧﺘﻬﺎء اﻟﻌﻤﻞ .‬ ‫•‬‫ﺣﺘﻰ اﻟﻠﺤﻈﺔ ﻓﺈن ﻣﺸﺮوﻋﻚ ﻳﻌﻤﻞ ﻣﻦ ﺧﻼل 8002 وﻟﻜﻨﻪ ﻻ زال ﻣﺘﻮاﻓﻘﺎ ﻣﻊ 5002، ﻟﺘﻌﺪﻳﻞ‬ ‫ً‬ ‫•‬ ‫اﻟﺨﺼﺎﺋﺺ ﻟﺘﺼﺒﺢ ﻣﺘﻮاﻓﻘﺔ ﻣﻊ 8002 ﻓﻘﻂ ﻗﻢ ﺑﺎﻟﺨﻄﻮات اﻟﺘﺎﻟﻴﺔ:‬ ‫ﻣﻦ ‪ Solution Explorer‬ﻗﻢ ﺑﺎﺧﺘﻴﺎر ﺧﺼﺎﺋﺺ اﻟﻤﺸﺮوع.‬ ‫•‬ ‫ﻣﻦ اﻟﺘﺒﻮﻳﺐ ‪ Compile‬ﻗﻢ ﺑﺎﺧﺘﻴﺎر ‪ Option Infer‬إﻟﻰ ‪.ON‬‬ ‫•‬ ‫وﻣﻦ ‪ Advanced  Compile  Options‬ﻗﻢ ﺑﺎﺧﺘﻴﺎر ‪ Target  framework‬ﻟﻴﺼﺒﺢ  ‪.net‬‬ ‫•‬ ‫5.3 ‪ Framework‬ﺑﺪﻻ ﻣﻦ .0.2 ‪net Framework‬‬ ‫ً‬‫93‬
  • ‫ﺗﺤﻤﻴﻞ ﻧﺴﺨﺘﻚ ﻣﻦ اﻟﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ‬ ‫• اﻵن ﺳﻴﻜﻮن ﻋﻠﻴﻚ إﺿﺎﻓﺔ ﺑﻌﺾ اﻟﻤﺮاﺟﻊ اﻟﺘﻲ ﺗﻮﺟﺪ ﺗﻠﻘﺎﺋﻴﺎ ﻣﻊ 8002، ﻓﻲ أي ﻣﺸﺮوع ﻗﻢ‬ ‫ً‬ ‫ﺑﻤﻌﺮﻓﺔ اﻟﺨﻴﺎرات اﻟﺘﻲ ﺗﺮﻳﺪﻫﺎ، ﻗﻢ ﺑﺎﻻﻧﺘﻘﺎل إﻟﻰ ‪ References‬وﻗﻢ ﺑﺈﺿﺎﻓﺔ اﻟﻤﺮاﺟﻊ‬ ‫اﻟﻤﻄﻠﻮﺑﺔ.‬ ‫04‬
  • 41
  • ‫اﻟﺒﺎب‬ ‫3‬ ‫اﻟﺠﺪﻳﺪ ﻣﻊ ال  ‪.net‬‬ ‫8002  ‬‫ ‬ ‫ ‬‫24‬
  •  43
  • ‫اﻟﺠﺪﻳﺪ ﻣﻊ ال 8002 ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻟﺚ‬‫ﻓﻲ ﻫﺬا اﻟﺠﺰء ﻣﻦ اﻟﻜﺘﺎب ﺳﺘﺴﺎﻋﺪﻧﻲ ﻋﻠﻰ اﻓﺘﺮاض ﻧﻘﻄﺘﻴﻦ ﻫﺎﻣﺘﻴﻦ، اﻟﻨﻘﻄﺔ اﻷوﻟﻰ ﻫﻲ اﻧﻚ ﺗﻮد‬‫اﻟﺒﺪء ﺣﻘﺎ ﺑﺘﻌﻠﻢ8002 ‪ ، .net‬اﻟﻨﻘﻄﺔ اﻟﺜﺎﻧﻴﺔ أﻧﻚ ﻟﻢ ﺗﺒﺮﻣﺞ ﻟﻠﻤﺮة اﻷوﻟﻰ ، ﺳﻨﺘﺤﺪث ﻓﻲ ﻫﺬا اﻟﺒﺎب‬ ‫ً‬‫ﻟﺒﻌﺾ اﻟﻮﻗﺖ ﻋﻦ اﻟﺘﻘﻨﻴﺎت اﻟﺠﺪﻳﺪة اﻟﺘﻲ ﻇﻬﺮت ﻓﻲ .8002 ‪ ، net‬ﻓﻠﻮ ﻟﻢ ﺗﻜﻦ ﻣﺒﺮﻣﺠﺎ ﻓﻲ اﻷﺳﺎس‬ ‫ً‬ ‫ﻓﻠﻦ ﻳﻀﻴﺮك أن ﺗﻘﻠﺐ ﺻﻔﺤﺎت ﻫﺬا اﻟﺒﺎب ﻟﺘﻨﻄﻠﻖ ﻣﺒﺎﺷﺮة ﻟﻠﺒﺎب اﻟﺘﺎﻟﻲ .‬‫اﻟﻤﻘﺼﻮد ﺑﻬﺬا اﻟﺒﺎب ﻟﻴﺲ ﻓﻘﻂ اﻟﺘﻘﻨﻴﺎت اﻟﻌﺎﻣﺔ اﻟﺠﺪﻳﺪة اﻟﺘﻲ ﻇﻬﺮت ﻣﻊ.  8002  ‪ net‬ﺑﻞ ﻛﻞ‬‫اﻟﺘﻘﻨﻴﺎت اﻟﺘﻲ أﺻﺒﺤﺖ ﺗﻠﻘﻰ اﻟﺪﻋﻢ اﻟﻜﺎﻣﻞ داﺧﻞ إﻃﺎر ﻋﻤﻞ .‪ net  Framework‬ﻣﻦ ﺗﻘﻨﻴﺎت ﻓﻘﻂ‬‫واﻟﺘﻲ ﺳﻴﺘﻢ ﺷﺮﺣﻬﺎ ﺑﺪورﻫﺎ ﻓﻲ دروس ﻣﻨﻔﺼﻠﺔ ﻻﺣﻘﺎ ، أﻣﺎ اﻟﺠﺪﻳﺪ ﻓﻲ ﻋﺎﻟﻢ اﻟﺒﺮﻣﺠﺔ ﻓﺴﻴﺘﻢ اﻟﺘﻌﺮف‬ ‫ً‬ ‫ﻋﻠﻴﻪ ﻓﻲ دروس ﻗﺎدﻣﺔ .‬ ‫ ‬ ‫1. ﺗﻘﻨﻴﺔ ‪Silverlight‬‬‫ﻛﺠﺰء ﻣﻦ ﺳﻴﺎﺳﺎت ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ اﻟﺮاﻣﻴﺔ إﻟﻰ ﻣﺤﺎوﻟﺔ ﺗﻤﻠﻚ أﻏﻠﺐ اﻟﻤﻔﺎﺗﻴﺢ اﻟﺮﺋﻴﺴﻴﺔ ﻓﻲ‬‫ﻣﺠﺎل اﻟﺘﻘﻨﻴﺔ واﻟﺘﻜﻨﻮﻟﻮﺟﻴﺎ ﻛﺎﻧﺖ ﺗﻘﻨﻴﺔ ‪ Silverlight‬ﻛﻤﺤﺎوﻟﺔ ﻟﺰﻋﺰﻋﺔ اﺳﺘﻘﺮار ﻣﺤﺮﻛﺎت ‪Flash‬‬‫ﻋﻠﻰ ﻋﺮش اﻟﻮﻳﺐ ﻛﺤﻞ أﻣﺜﻞ ﻟﻠﺘﻄﺒﻴﻘﺎت اﻟﺘﻲ ﺗﺴﺘﺨﺪم اﻟﻤﻠﺘﻴﻤﻴﺪﻳﺎ اﻟﻤﺘﺤﺮﻛﺔ أو اﻻﻋﺘﻤﺎد ﻋﻠﻰ‬ ‫ﻃﺮق اﻹدﺧﺎل واﻹﺧﺮاج .‬‫ورﺑﻤﺎ ﺑﻌﺪ أن أﺣﺴﺖ ﺷﺮﻛﺔ ‪ Adobe‬اﻟﻤﺎﻟﻜﺔ ﻟﻤﺤﺮك ‪ Flash‬ﺑﺎﻟﺨﻄﺮ - أو رﺑﻤﺎ ﻓﻲ ﺳﻴﺎق‬‫ﺗﻄﻮﻳﺮﻫﺎ ﻟﻤﺤﺮﻛﻬﺎ، ﻣﻦ ﻳﺪري ! - ﺑﺪأت ﺗﺤﺮﻛﻬﺎ ﻓﻲ اﻟﺘﻄﻮﻳﺮ اﻟﺴﺮﻳﻊ ﻟﻤﺤﺮك ﻓﻼش اﻟﺬي ﻟﻢ‬‫ﻳﺸﻬﺪ ﺗﻐﻴﻴﺮات ﺟﺬرﻳﺔ ﻣﻨﺬ اﺷﺘﺮت ﺷﺮﻛﺔ ‪ Adobe‬ﺣﻘﻮﻗﻪ ﻣﻦ ﺷﺮﻛﺔ ‪ ، Macromedia‬ﻓﺄﺻﺒﺢ‬‫ﻟﺸﺮﻛﺔ ‪ Adobe‬اﻵن ﺛﻼث ﻣﺤﺮﻛﺎت ﺗﻌﺘﻤﺪ ﻋﻠﻰ ‪ ، Action Script‬أوﻟﻬﺎ وأﺷﻬﺮﻫﺎ ﻫﻮ ‪ Flash‬وﻣﻦ‬‫ﺛﻢ ﺗﻘﻨﻴﺔ ‪ Flex‬وأﺧﻴﺮًا ﺗﻘﻨﻴﺔ ‪ ، Apollo‬ﻓﻴﻤﺎ دﺧﻠﺖ ﺷﺮﻛﺔ ‪ Sun‬ﻋﻠﻰ ﺧﻂ اﻟﻤﻨﺎﻓﺴﺔ ﻣﻦ ﺧﻼل‬‫ﻣﻨﺘﺠﻬﺎ ‪ JavaFX  Script‬وﻫﺬا ﺑﺎﻟﺘﺄﻛﻴﺪ ﺳﻴﻨﺼﺐ ﻓﻲ ﻣﺼﻠﺤﺘﻨﺎ ﻓﻲ اﻟﻨﻬﺎﻳﺔ ، ورﺑﻤﺎ ﺗﻜﻮن اﻟﻨﻘﻄﺔ‬‫ﻳﺘﻤﻴﺰ ال ‪ Silverlight‬ﻋﻦ ﺑﺎﻗﻲ ﻣﺤﺮﻛﺎت اﻟﻔﻼش ﺑﺪﻋﻤﻪ ﻟﺘﺸﻐﻴﻞ ﻓﻴﺪﻳﻮ ﻋﺎﻟﻲ اﻟﺪﻗﺔ ‪HD  Video‬‬ ‫واﻟﺘﻲ ﻋﻠﻰ ﺣﺪ ﻋﻠﻤﻲ ﻟﻢ ﺗﺤﺎول ﺷﺮﻛﺔ ﻣﻨﻬﻢ دﺧﻮل ﻫﺬا اﻟﻤﺠﺎل ﺑﻌﺪ - ﻋﻠﻰ ﺣﺴﺐ ﻣﻌﻠﻮﻣﺎﺗﻲ - .‬‫44‬
  • ‫اﻟﺠﺪﻳﺪ ﻣﻊ ال 8002 ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻟﺚ‬ ‫ﻟﺘﺘﻌﺮف ﻋﻦ اﻟﻤﺰﻳﺪ ﻋﻦ ﻫﺬه اﻟﺘﻘﻨﻴﺔ ﺑﺮﺟﺎء زﻳﺎرة ﻣﻮﻗﻊ ‪: Silverlight‬‬ ‫راﺑﻂ‬ ‫‪http://www.microsoft.com/silverlight/default_ns.aspx‬‬‫ﺑﺪاﻳﺔ ﻗﻢ ﺑﺘﺤﻤﻴﻞ ‪ Silverlight‬ﻣﻦ اﻟﺮاﺑﻂ اﻟﻤﻮﺿﻮع ‪ ،Get Silverlight‬ﻟﺘﺒﺪأ ﺑﻌﺪﻫﺎ ﺑﺘﺠﺮﺑﺔ اﻣﻜﺎﻧﻴﺎت‬ ‫وﻗﺪرات ‪. Silverlight‬‬‫ﻗﻢ ﺑﺘﺤﻤﻴﻞ اﻟﺒﺮﻧﺎﻣﺞ وﻋﻤﻞ ‪ Setup‬ﻟﻪ ، وﻣﻦ ﺛﻢ ﻗﻢ ﺑﺘﺠﺮﺑﺔ اﻟﻤﻮﻗﻊ ﻣﺮة أﺧﺮى ، واﺳﺘﻤﺘﻊ ﺑﺈﻣﻜﺎﻧﻴﺎت‬ ‫‪ ... Silverlight‬وﻻﺣﻆ اﻟﻔﺮق .‬ ‫ﺟﺮب اﻟﻤﻮاﻗﻊ اﻟﺘﺎﻟﻴﺔ واﻟﺘﻲ ﺗﻌﺘﻤﺪ اﻳﻀﺎ ﻋﻠﻰ ﺗﻘﻨﻴﺔ ‪: Silverlight‬‬ ‫ً‬ ‫اﻟﻤﻮﻗﻊ‬ ‫ﺻﻮرة‬ ‫‪http://silverlight.net/samples/1.0/Page-Turn/default.html‬‬ ‫/‪http://www.yeejie.com/silverlight_magazine‬‬ ‫اﻟﺠﺪول 3. 1. ﺑﻌﺾ اﻟﻤﻮاﻗﻊ اﻟﺘﻲ ﺗﻌﺘﻤﺪ ﻋﻠﻰ ﺗﻘﻨﻴﺔ ال ‪.Silverlight‬‬‫54‬
  • ‫اﻟﺠﺪﻳﺪ ﻣﻊ ال 8002 ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻟﺚ‬ ‫2. ﺗﻘﻨﻴﺔ ‪LINQ‬‬‫ﺗﻘﻨﻴﺔ ﺟﺪﻳﺪة ﻣﻦ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ ﻓﻲ ﻣﺠﺎل ﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت ، ﺣﻴﺚ ﺗﺘﻴﺢ ﻟﻚ ﻫﺬه اﻟﺘﻘﻨﻴﺔ‬‫ﺗﺤﻮﻳﻞ اﻻﺳﺘﻌﻼم إﻟﻰ ﺟﺰء ﻣﻦ ﻟﻐﺔ اﻟﺒﺮﻣﺠﺔ ﺑﻤﺎ ﻳﺘﻴﺢ ﻟﻚ اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﺠﺪاول واﻟﺤﻘﻮل واﻟﻜﺎﺋﻨﺎت‬ ‫ﺑﺼﻮرة ﻣﺒﺎﺷﺮة ﻣﻦ ﺧﻼل ﻟﻐﺔ اﻟﺒﺮﻣﺠﺔ .‬ ‫ﻛﻤﺜﺎل ﺳﺮﻳﻊ ﻳﻤﻜﻦ اﻓﺘﺮاض ﺟﻤﻠﺔ اﻻﺳﺘﻌﻼم ﻫﺬه:‬ ‫‪SQL‬‬ ‫ﻛﻮد‬ ‫‪Select companyname from customers‬‬‫ﻳﺘﻢ ﺗﻨﻔﻴﺬﻫﺎ ﺑﺎﺳﺘﺨﺪام أي ﻃﺮﻳﻘﺔ ... ﻟﻴﺲ ﻫﺬا ﻣﺎ ﻳﻌﻨﻴﻨﺎ ، وﻟﻜﻦ ﺗﺠﺪ ﻧﺎﺗﺞ اﻻﺳﺘﻌﻼم ﻓﻲ‬‫ﻣﺜﻼ ﺣﺴﺐ ﻃﺮﻳﻘﺔ اﻟﻘﺮاءة ، ﺣﻴﺚ ﺗﺴﺘﻄﻴﻊ ﻗﺮاءﺗﻬﺎ ، ﻟﻌﻤﻞ اﺳﺘﻌﻼم آﺧﺮ‬ ‫ً‬ ‫)"‪RS.Fields("FieldName‬‬‫ﻳﻤﻜﻨﻚ اﻟﻘﺮاءة ﻣﻦ ﺟﺪﻳﺪ ، ﻳﻤﻜﻨﻚ ﻋﻤﻞ ‪ Loop‬ﻋﺎدﻳﺔ ﻟﻠﻘﺮاءة وﻣﻦ ﺛﻢ اﻟﺒﺤﺚ ﻓﻲ اﻟﻜﺎﺋﻦ ﺑﺎﻟﻄﺮﻳﻘﺔ‬ ‫اﻟﻌﺎدﻳﺔ:‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫))(‪Do While (Rs.Read‬‬ ‫))"‪Console.WriteLine(Rs.Fields("CompanyName‬‬ ‫‪Loop‬‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪do‬‬ ‫{‬ ‫;))"‪Console.WriteLine( Rs.Fields("CompanyName‬‬ ‫}‬ ‫;))(‪while(Rs.Read‬‬‫ﻛﺎن ﻫﺬا ﻫﻮ اﻻﺧﺘﻴﺎر اﻟﻤﺘﺎح ﻟﻚ ﻟﻠﺘﻌﺎﻣﻞ ﻣﻊ ﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت ، أﻣﺎ اﻵن ﻓﻘﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت ﻳﺘﻢ‬‫اﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﻋﻠﻰ ﺷﻜﻞ ‪ Classes‬ﻟﻬﺎ ‪ Members‬و ‪ Methods‬و‪ Functions‬وﻟﻬﺎ ‪ Operators‬ﺧﺎﺻﺔ‬ ‫ﺑﻬﺎ ، ﻟﻨﻔﺘﺮض ﻫﺬا اﻷﻣﺮ ﻣﻦ داﺧﻞ ال ‪ .net‬ﻣﺒﺎﺷﺮة.‬‫64‬
  • ‫اﻟﺠﺪﻳﺪ ﻣﻊ ال 8002 ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻟﺚ‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫_ ‪Dim queryResults = From cust In customers‬‬ ‫‪Select cust.CompanyName‬‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪var queryResults = from cust in customers‬‬ ‫;‪select cust.CompanyName‬‬‫واﻵن أﺻﺒﺢ ﺑﺈﻣﻜﺎﻧﻚ اﻟﺘﻌﺎﻣﻞ ﻣﻊ ‪ queryResults‬ﻛﻔﺌﺔ ﻣﺒﺎﺷﺮة ﻟﻬﺎ ﺧﺼﺎﺋﺼﻬﺎ‬ ‫وﺣﻘﻮﻟﻬﺎ اﻟﺘﻲ أﺻﺒﺢ ﺑﺈﻣﻜﺎﻧﻚ ﻗﺮاءﺗﻬﺎ ﻣﺒﺎﺷﺮة ، ﺳﻨﺘﻌﺮف ﻓﻲ ﺑﺎب ﻻﺣﻖ ﻋﻦ ﻫﺬه اﻟﺘﻘﻨﻴﺔ ﺑﺎﻟﺘﻔﺼﻴﻞ .‬ ‫3. ﺗﻘﻨﻴﺔ ‪WPF‬‬‫واﺣﺪة ﻣﻦ اﻟﺘﻘﻨﻴﺎت اﻟﺠﺪﻳﺪة اﻟﺘﻲ ﺷﻬﺪ ‪ WinFx‬ﻇﻬﻮرﻫﺎ إﻟﻰ اﻟﻨﻮر وﻫﻲ اﺧﺘﺼﺎر ل‬‫‪ Windows  Presentation  Foundation‬ﺗﻌﺘﻤﺪ ﻋﻠﻰ ﺗﻘﻨﻴﺔ أﺧﺮى ﻫﻲ ‪ XAML‬وﻫﻲ ﻟﻐﺔ ﺗﺴﺘﺨﺪم‬‫ﻟﻮﺻﻒ اﻟﻮاﺟﻬﺎت ﺛﻨﺎﺋﻴﺔ أو ﺣﺘﻰ ﺛﻼﺛﻴﺔ اﻷﺑﻌﺎد، أﺛﻨﺎء ﻋﻤﻠﻚ ﻋﻠﻰ ‪ WPF‬ﻣﻦ ﺧﻼل8002  ‪ .net‬ﻳﺘﻢ‬‫ﺗﻮﻟﻴﺪ ﻛﻮد ‪ XAML‬ﺑﺼﻮرة ﻓﻮرﻳﺔ ،ﻓﻴﻤﺎ ﻳﻈﻞ ﺑﺈﻣﻜﺎﻧﻚ اﻳﻀﺎ اﻟﻜﺘﺎﺑﺔ ب ‪ XAML‬إن أردت . ﻳﺘﻢ اﻟﻔﺼﻞ‬ ‫ً‬ ‫اﻟﻜﺎﻣﻞ ﺑﻴﻦ ال ‪ XAML‬واﻟﻜﻮد اﻟﻌﺎدي ﻛﻤﺎ ﻛﺎن ﻳﺤﺪث ﻓﻲ ﺻﻔﺤﺎت اﻟﻮﻳﺐ .‬ ‫ﻟﻤﺎذا اﺳﺘﺨﺪام ‪ WPF‬؟‬‫اﻟﻔﺼﻞ اﻟﻜﺎﻣﻞ ﺑﻴﻦ ﻟﻐﺔ اﻟﺒﺮﻣﺠﺔ وﺑﻴﻦ اﻟﺘﺼﻤﻴﻢ ﺑﺎﺳﺘﺨﺪام ‪ XAML‬ﻗﺎدﻧﺎ إﻟﻰ ﻇﻬﻮر ﺣﺰﻣﺔ ﻣﻦ‬‫ﺑﺮاﻣﺞ اﻟﺘﺼﻤﻴﻢ اﻟﻤﺘﺨﺼﺼﺔ اﻟﺘﻲ ﺗﻮﻟﺪ ﻛﻮد ‪ ، XAML‬ﺗﺨﻴﻞ ﻧﻔﺴﻚ ﺗﺼﻤﻢ ﺑﺮﻧﺎﻣﺠﻚ ﻋﻠﻰ‬‫ﻓﻮﺗﻮﺷﻮب ، أو ﻋﻠﻰ ﻓﻼش وﺗﻜﺘﺐ اﻟﻜﻮد ﻓﻲ ‪ ، .net‬أﻟﻴﺲ ﻫﺬا ﺳﻴﻤﻨﺤﻚ ﻣﺰﻳﺪًا ﻣﻦ اﻟﺘﺤﻜﻢ وﻗﻮة‬‫اﻟﺘﺼﻤﻴﻢ اﻟﺘﻲ ﻟﻢ ﺗﻜﻦ ﻟﺘﺘﺎح ﻟﻚ ﻟﻮ ﻛﻨﺖ أﻛﻤﻠﺖ اﻟﺘﺼﻤﻴﻢ ﻋﻠﻰ ‪ Visual  Studio‬اﻟﻤﺼﻤﻢ أﺻﻼ‬‫ﻟﺨﺪﻣﺔ اﻟﻜﻮد وﻟﻴﺲ اﻟﺘﺼﻤﻴﻢ ، اﻳﻀﺎ ﺳﺘﺠﺪ ﻣﺠﻤﻮﻋﺔ ﻣﻦ اﻟﺤﺰم اﻟﺠﺎﻫﺰة اﻟﺘﻲ ﺳﺘﺴﺎﻋﺪك ﻋﻠﻰ ﺗﺠﻤﻴﻞ‬ ‫ً‬ ‫وﺗﺤﺴﻴﻦ ﻣﻈﻬﺮ اﻟﺒﺮﻧﺎﻣﺞ.‬‫ﻗﺒﻞ اﻟﻨﻬﺎﻳﺔ، إذا ﻛﻨﺖ ﻣﺘﺎﺑﻌﺎ ﻣﻌﻨﺎ ﻓﺄﻧﺖ ﺑﺎﻟﺘﺄﻛﻴﺪ ﻗﻤﺖ ﺑﺘﺤﻤﻴﻞ8002  ‪ .net‬أو ﻋﻠﻰ اﻷﻗﻞ‬ ‫ً‬‫.5.3  ‪ ،net Framework‬ﻟﺬا ﻓﺄﻧﺖ ﻣﺆﻫﻞ ﻟﻼﻃﻼع ﻋﻠﻰ ﻫﺬه اﻷﻣﺜﻠﺔ، وﺷﺎﻫﺪ اﻟﻔﺮق ﺑﻴﻨﻬﺎ وﺑﻴﻦ‬‫74‬
  • .net 2008 ‫اﻟﺠﺪﻳﺪ ﻣﻊ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻟﺚ‬‫اﻟﻮاﺟﻬﺎت اﻟﺘﻘﻠﻴﺪﻳﺔ ، رﺑﻤﺎ ﻻ ﺗﺤﺘﺎج إﻟﻰ ﺗﺤﻤﻴﻞ اﻟﺒﺮﻧﺎﻣﺞ ﻓﻘﻂ اﻃﻠﻊ ﻋﻠﻰ اﻟﻔﻴﺪﻳﻮﻫﺎت اﻟﻤﻮﺟﻮدة أو‬ : ‫ﻧﻤﺎذج اﻟﺼﻮر ، وﻛﻠﻲ ﺛﻘﺔ اﻧﻚ ﺳﺘﻐﻴﺮ ﻣﻔﻬﻮﻣﻚ ﺣﻮل ﺟﻤﺎل اﻟﻮاﺟﻬﺎت إﻟﻰ اﻷﺑﺪ‬ ‫اﻟﻤﻮﻗﻊ‬ ‫ﺻﻮرة‬ 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 http://blogs.msdn.com/tims/archive/2007/02/09/great- wpf-applications-8-notescraps.aspx .WPF ‫اﻟﺠﺪول 3. 2. ﺑﻌﺾ اﻟﻔﻴﺪﻳﻮﻫﺎت ﻟﺘﻘﻨﻴﺔ ال‬48
  • ‫اﻟﺠﺪﻳﺪ ﻣﻊ ال 8002 ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻟﺚ‬ ‫4. ﻣﺠﻤﻮﻋﺔ ‪Expression‬‬‫ﻟﻨﻌﺪ إﻟﻰ اﻟﻮراء ﻗﻠﻴﻼ ﻓﻲ ﻋﻤﻠﻴﺔ اﻟﺘﺼﻤﻴﻢ ، ﺣﻴﺚ ﻳﻘﻮم اﻟﻤﺼﻤﻢ ﺑﺮﺳﻢ اﻟﻮاﺟﻬﺔ ﻋﻠﻰ‬ ‫ً‬‫اﻟﻔﻮﺗﻮﺷﻮب أو اﻟﻔﻼش أو ﻏﻴﺮه ﻣﻦ ﺑﺮاﻣﺞ اﻟﺘﺼﻤﻴﻢ ، ﻳﺘﻢ ﻻﺣﻘﺎ ﺗﻘﻄﻴﻊ اﻟﺼﻮر ووﺿﻌﻬﺎ ﻓﻲ‬ ‫ً‬‫اﻟﺼﻔﺤﺔ، أو ﺑﺮﻣﺠﺔ ﺑﻌﺾ اﻷواﻣﺮ واﻟﺤﺮﻛﺎت ﻣﻦ ﺧﻼل ‪ Flash‬وﻣﻦ ﺛﻢ ﻧﻘﻠﻬﺎ ﻟﻤﻮﻗﻌﻚ أو‬ ‫ﻟﺒﺮﻧﺎﻣﺠﻚ ... وﻫﻜﺬا ، ﺗﺠﺪ ﻓﺼﻼ ﺗﺎﻣﺎ ﺑﻴﻦ ﻋﻤﻠﻴﺔ اﻟﺘﺼﻤﻴﻢ وﺑﺎﻟﺒﺮﻣﺠﺔ.‬ ‫ً ً‬‫أﻣﺎ اﻵن وﻣﻊ ﺳﺘﻮدﻳﻮ ‪ Expression‬ﻛﺎﺳﺘﺪﻳﻮ اﻋﻠﻨﺖ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ ﻋﻦ ﺗﻄﻮﻳﺮه ﻻﺣﺘﻴﺎﺟﺎت ﻣﺼﻤﻤﻲ‬‫اﻟﺘﻄﺒﻴﻘﺎت ، ﺣﻴﺚ أﺻﺒﺢ اﻵن ﺑﺈﻣﻜﺎﻧﻚ اﺳﺘﺨﺪام ﺑﺮﻧﺎﻣﺞ ﺗﺼﻤﻴﻢ ﻣﻦ اﻧﺘﺎج ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ ﻳﻘﻮم ﺑﺈﻧﺘﺎج‬‫ﻛﻮد ‪ XAML‬ﻳﻤﻜﻨﻚ اﺳﺘﺨﺪاﻣﻪ ﻓﻲ ﺗﻄﺒﻴﻘﺎﺗﻚ ﻣﺒﺎﺷﺮة ، ﻛﻤﺎ ﻳﻤﻜﻨﻚ اﻟﺒﺮﻣﺠﺔ ﻣﻦ‬ ‫ﺧﻼل ‪ Expression Blend‬أﻳﻀﺎ.‬ ‫ً‬‫ﻳﺼﺪر ‪ MS Expression‬ﻣﻊ أرﺑﻊ ﺗﻄﺒﻴﻘﺎت رﺋﻴﺴﻴﺔ ، ‪ Blend‬ﻟﺘﻄﻮﻳﺮ اﻟﻤﻠﺘﻴﻤﻴﺪﻳﺎ واﻟﺼﻮر واﻟﻤﺆﺛﺮات‬‫اﻟﺤﺮﻛﻴﺔ - ﺷﺪﻳﺪ اﻟﺸﺒﻪ ﺑﺒﺮﻧﺎﻣﺞ ﻓﻼش - ، اﻟﺘﻄﺒﻴﻖ اﻟﺜﺎﻧﻲ ﻫﻮ ‪ Design‬وﻫﻮ ﻣﻮﺟﻪ ﺑﺎﻷﺳﺎس ﻟﺨﺪﻣﺔ‬‫ﺗﻄﺒﻴﻘﺎت اﻟﻮﻳﻨﺪوز - ﺷﺪﻳﺪ اﻟﺸﺒﻪ ﺑﻔﻮﺗﻮﺷﻮب - ، اﻟﺜﺎﻟﺚ ﻫﻮ ﻷﺟﻞ ال ‪ WEB‬ﺣﻴﺚ أﺻﺒﺢ ﺗﺼﻤﻴﻢ ﻣﻮاﻗﻊ‬‫اﻹﻧﺘﺮﻧﺖ ﺑﻤﺴﺘﻮى ﻋﺎﻟﻲ ﺟﺪًا ، وﻫﻮ اﻟﺘﻄﻮر ل ‪ Microsoft FrontPage‬وﻟﻜﻦ ﺑﺈﻣﻜﺎﻧﻴﺎت ﻣﺘﻘﺪﻣﺔ ﺟﺪًا‬ ‫ﻣﻦ اﺟﻞ دﻋﻢ ‪ AJAX‬و ‪، XAML‬اﻷﺧﻴﺮ ﻣﺨﺼﺺ ﻟﻠﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻤﻴﺪﻳﺎ واﻟﻔﻴﺪﻳﻮ وﺧﻼﻓﻪ ﺑﺎﺳﻢ‬ ‫‪. Expression Media‬‬‫اﻟﺘﻄﺒﻴﻖ اﻷﻛﺜﺮ ﺷﻬﺮة ﺑﻴﻨﻬﻢ ﻫﻮ ‪ Blend‬ﺣﻴﺚ أﺻﺒﺢ ﺗﺤﻮﻳﻞ ﻣﻮﻗﻌﻚ أو ﺑﺮﻧﺎﻣﺠﻚ إﻟﻰ ﻣﻮﻗﻊ ﻏﻨﻲ‬ ‫ﺑﺎﻟﺤﺮﻛﺔ وﺑﺎﻟﻤﺆﺛﺮات وﺧﻼﻓﻪ اﻣﺮًا ﻓﻲ ﻏﺎﻳﺔ اﻟﺴﻬﻮﻟﺔ ، ﻫﺬه ﻫﻲ اﻟﺸﺎﺷﺔ اﻟﺮﺋﻴﺴﻴﺔ ﻟﻠﺒﺮﻧﺎﻣﺞ:‬‫94‬
  • ‫ﺠﺪﻳﺪ ﻣﻊ ال 8002 ‪.net‬‬ ‫8‬ ‫اﻟﺠ‬ ‫ ‬ ‫اﻟﺜﺎﻟﺚ‬ ‫اﻟﺒﺎب ﻟﺚ‬ ‫ة 3. 1. ﺪﻳﻮ ال ‪pression Ble‬‬ ‫‪Exp‬‬ ‫‪end‬‬ ‫اﺳﺘﺪ‬ ‫اﻟﺼﻮرة‬‫ﻴﺔ ﻟﻤﺪة 12 ﻳﻮم ﻣﻦ ﻣﻮﻗﻊ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ ﺮﺳﻤﻲ - أو ﻣﻦ ﻣﻮﻗﻊ‬ ‫اﻟﺮ‬ ‫ﻣ‬ ‫ﻳﻤﻜﻨﻚ ﺗﺤﻤﻴﻞ ﺴﺨﺔ ﺗﺠﺮﻳﺒﻴ‬ ‫ﻧﺴ‬ ‫ﻜﺮوﺳﻮﻓﺖ‬ ‫ﻛﺎت ال ‪ners‬‬ ‫‪ Partn‬ﻟﻤﺎﻳﻜ‬ ‫اﻟﺘﻘﻨﻴﺔ - ﺣﻴﺚ ﺖ ﻣﺎﻳﻜﺮوﺳﻮ‬ ‫ﻮﻓﺖ ﺑﺸﺮاء ﻟﺘﻘﻨﻴﺔ ﻣﻦ إﺣﺪى اﻟﺸﺮﻛ‬ ‫اﻟ‬ ‫ﻗﺎﻣﺖ‬ ‫ﺔ ﻓﻲ ﻫﺬا ﻜﺘﺎب.‬ ‫اﻟﻜ‬ ‫ﻛﻤﺎ ﻨﺘﻌﺮف ﻋﻠﻰ ﻫﺬه اﻟﺘﻘﻨﻴﺔ ﺑﺼﻮرة ﺼﻠﺔ ﺿﻤﻦ دروس ﻻﺣﻘﺔ‬ ‫د‬ ‫ﻣﻔﺼ‬ ‫ﺳﻨ‬‫05‬
  • ‫اﻟﺠﺪﻳﺪ ﻣﻊ ال 8002 ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻟﺚ‬ ‫5. ﺗﻘﻨﻴﺔ ‪WCF‬‬‫ﻫﻲ إﺣﺪى ﺗﻘﻨﻴﺎت ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ اﻟﺠﺪﻳﺪة اﻟﺘﻲ ﺗﺨﺪم اﻟﺒﺮاﻣﺞ اﻟﺘﻲ ﺗﻌﻤﻞ ﻓﻲ وﺿﻊ اﺗﺼﺎل ،‬‫ﺳﻮاء ﻋﻠﻰ اﻟﺸﺒﻜﺎت أو ﺑﺮاﻣﺞ ﻣﺜﻞ اﻟﻤﺎﺳﻨﺠﺮ وﺧﺪﻣﺎت اﻟﺒﺮﻳﺪ اﻻﻟﻜﺘﺮوﻧﻲ وﺧﻼﻓﻪ ... ﺑﺎﺧﺘﺼﺎر أي‬ ‫ﺑﺮﻧﺎﻣﺞ ﻳﺘﻢ ﻓﻴﻪ رﺑﻂ ﺟﻬﺎزﻳﻦ ﺑﺒﻌﻀﻬﻤﺎ ﻓﻬﺬه اﻟﺘﻘﻨﻴﺔ ﻣﻮﺟﻬﺔ ﻟﻬﺬا اﻟﻐﺮض.‬‫ﺑﻌﺪ ‪ Winsock‬ﻓﻲ ﻓﻴﺠﻮال ﺑﻴﺴﻚ 6 وﻓﺌﺔ ‪ Sockets‬ﻣﻊ ‪ ، .net‬ﺟﺎءت ﻟﻨﺎ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ ﺑﺘﻘﻨﻴﺔ‬‫ﺟﺪﻳﺪة ﻣﻦ اﺟﻞ ﻋﻤﻠﻴﺎت اﻻﺗﺼﺎل ﺗﺤﺖ اﺳﻢ ‪ WCF‬وﻫﻲ اﺧﺘﺼﺎر ل  ‪Windows  Communication‬‬ ‫‪.Foundation‬‬‫أﻣﺎ ﻟﻤﺎذا ﻫﺬه اﻟﺘﻘﻨﻴﺔ ، ﻓﺒﺎﺧﺘﺼﺎر ﻷﻧﻚ ﺳﺘﺴﺘﻄﻴﻊ ﻋﻤﻞ ﺗﻄﺒﻴﻖ ﻋﻤﻴﻞ وﺧﺎدم  ‪Server And‬‬ ‫‪ Client‬آﻣﻦ وﻣﺘﻜﺎﻣﻞ ﻣﻦ ﺧﻼل اﻗﻞ ﻣﻦ ﻋﺸﺮة اﺳﻄﺮ ﻓﻘﻂ ﻣﻦ اﻟﻜﻮد!!!‬‫ﻛﻤﺎ أﻧﻬﺎ أﺳﺮع ﻣﻦ اﻟﺘﻘﻨﻴﺎت اﻟﺴﺎﺑﻘﺔ، ﻓﻲ درﺳﻨﺎ اﻟﻤﻔﺼﻞ ﻋﻦ ‪ WCF‬ﺳﻮف ﻧﺘﻄﺮق ﻟﻠﻤﻘﺎرﻧﺎت ﺑﻴﻨﻬﺎ‬ ‫وﺑﻴﻦ ﺑﺎﻗﻲ اﻟﺘﻘﻨﻴﺎت.‬ ‫6. ‪Code Refactoring‬‬‫إﺣﺪى اﻟﻤﻤﻴﺰات اﻟﺠﺪﻳﺪة اﻟﺘﻲ ﺟﺎء ﺑﻬﺎ ال ‪ IDE‬اﻟﺨﺎص ﺑﺎﻟﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ ، اﻟﻔﻜﺮة ﺑﺎﺧﺘﺼﺎر‬ ‫ﻫﻲ ﻣﺠﻤﻮﻋﺔ ﻣﻦ اﻟﻮﺳﺎﺋﻞ اﻟﻤﺴﺎﻋﺪة ﻋﻠﻰ ﺗﻨﻈﻴﻢ اﻟﻜﻮد وﺗﺴﻬﻴﻞ اﻟﺘﻌﺎﻣﻞ ﻣﻌﻪ.‬‫ﻓﻲ اﻟﻌﺎدة ﻳﺘﻢ ﺗﻮﻓﻴﺮ ﻣﺜﻞ ﻫﺬه اﻟﺒﺮاﻣﺞ ﻋﻠﻰ ﺷﻜﻞ ﺑﺮاﻣﺞ ﻣﺴﺎﻋﺪة، وﻣﻊ 8002 ‪.net‬أﺻﺒﺢ واﺣﺪ ﻣﻨﻬﺎ‬‫ﻣﻀﻤﻦ ﺑﺼﻮرة اﻓﺘﺮاﺿﻴﺔ ، ﺗﻤﻜﻨﻚ ﻫﺬه اﻹﺿﺎﻓﺔ ﻣﻦ إﻧﺸﺎء ﺧﺼﺎﺋﺺ ﻟﻤﺘﻐﻴﺮ ﺑﻀﻐﻄﺔ زر ، ﻟﺪﻣﺞ‬ ‫اﻟﻤﺘﻐﻴﺮات ﻓﻲ ﻓﺌﺎت ، اﻟﺘﻌﺪﻳﻞ واﻟﺘﻐﻴﻴﺮ ﻓﻲ اﻟﻔﺌﺎت واﻟﺒﺎرﻣﻴﺘﺮات وﺧﻼﻓﻪ ﻛﻞ ﻫﺬا ﺑﻮاﺟﻬﺔ ﻣﺮﺋﻴﺔ.‬ ‫اﻳﻀﺎ ﻫﻨﺎك ﺑﺮاﻣﺞ أﺧﺮى ﻣﺜﻞ ﻫﺬا اﻟﺒﺮﻧﺎﻣﺞ ﻷﺟﻞ ﻓﻴﺠﻮال ﺑﻴﺴﻚ  ‪Refactor!  for  Visual‬‬ ‫ً‬ ‫8002 ‪ .Basic‬اﻟﺒﺮﻧﺎﻣﺞ ﻣﻮﺟﻮد ﻋﻠﻰ ﻫﺬا اﻟﺮاﺑﻂ:‬ ‫راﺑﻂ‬‫‪http://msdn.microsoft.com/en-us/vbasic/bb693327.aspx‬‬‫15‬
  • ‫اﻟﺠﺪﻳﺪ ﻣﻊ ال 8002 ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻟﺚ‬ ‫وﻫﺬه ﺻﻮرة ﻟﺒﻌﺾ اﻟﺘﻌﺪﻳﻼت اﻟﺘﻲ ﻳﻀﻴﻔﻬﺎ ﻋﻠﻰ ﻧﺎﻓﺬة ﻛﺘﺎﺑﺔ اﻟﻜﻮد:‬ ‫اﻟﺼﻮرة 3. 2. 8002 ‪Refactor! For Visual Basic‬‬‫ﺗﻮﻓﺮ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ اﻳﻀﺎ ﺧﺎﺻﻴﺔ ‪ Code Snippet‬وﻫﻲ ﻣﻀﻤﻨﺔ ﺑﺼﻮرة اﻓﺘﺮاﺿﻴﺔ ﻓﻲ 8002 ،‬ ‫ً‬‫ﺗﻤﻜﻨﻚ ﻫﺬه اﻟﺨﺎﺻﻴﺔ ﻣﻦ إدراج ﻛﻮد ﻛﺎﻣﻞ ﻟﻌﻤﻠﻴﺔ ﻣﻌﻴﻨﺔ ﺑﺪون ﻛﺘﺎﺑﺔ ﺳﻄﺮ واﺣﺪ ، ﻳﺘﻢ ذﻟﻚ‬‫ﺑﺎﺧﺘﻴﺎر اﻟﻤﻬﻤﺔ اﻟﻤﻄﻠﻮﺑﺔ ﻣﻦ ﻗﺎﺋﻤﺔ ﻳﻤﻜﻦ اﻟﺘﺤﺪﻳﺚ ﻓﻴﻬﺎ واﺿﺎﻓﺔ اﻛﻮاد ﺟﺪﻳﺪة ، وﻛﺎﻟﻌﺎدة ﻫﺬا‬ ‫اﻟﺒﺮﻧﺎﻣﺞ ﻣﻦ اﺟﻞ ﻓﻴﺠﻮال ﺑﻴﺴﻚ وﺳﺘﺠﺪ ﻣﺜﻴﻼ ﻟﻪ ﻣﻦ اﺟﻞ ﺳﻲ ﺷﺎرب:‬ ‫ً‬ ‫راﺑﻂ‬‫‪http://msdn2.microsoft.com/en-us/vbasic/bb973770.aspx‬‬ ‫وﻫﺬه ﺻﻮرة ﻟﻠﺒﺮﻧﺎﻣﺞ:‬‫25‬
  • ‫اﻟﺠﺪﻳﺪ ﻣﻊ ال 8002 ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻟﺚ‬ ‫اﻟﺼﻮرة 3. 3. ‪Code Snippet Editor‬‬‫اﺧﻴﺮًا وﻟﻴﺲ آﺧﺮًا اذﻛﺮ ﺑﺄن ﻫﻨﺎك اﺻﺪارات ﺗﻌﻤﻞ ﻋﻠﻰ 5002 ﻓﻠﻴﺲ اﻻﻣﺮ ﺧﺎﺻﺎ ﺑـ 8002 ﻓﻘﻂ ،‬ ‫ً‬ ‫وﻟﻜﻨﻬﺎ ﺧﺎﺻﻴﺔ اﺻﺒﺤﺖ اﻵن ﻣﻀﻤﻨﺔ اﻓﺘﺮاﺿﻴﺎ ﻣﻊ 8002 ‪.Visual Studio‬‬ ‫ً‬‫35‬
  • 54
  • ‫اﻟﺒﺎب‬ ‫4‬ ‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ‪.net‬‬ ‫اﻟﺮﺋﻴﺴﻴﺔ‬‫55‬
  • 56
  • ‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ال ‪ .net‬اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺮاﺑﻊ‬ ‫1. ﻟﻐﺎت ال ‪.net‬‬‫ﻻ ﺗﻌﺘﺒﺮ ‪ .net‬ﻟﻐﺔ واﺣﺪة ، ﺑﻞ ﻫﻲ ﻋﺒﺎرة ﻋﻦ ﻣﻌﻴﺎر ﻗﻴﺎﺳﻲ ﺗﺴﺘﺨﺪﻣﻪ ﻋﺪة ﻟﻐﺎت ﺑﺮﻣﺠﺔ ... ﺗﻢ‬‫ﻃﺮح ﻫﺬا اﻟﻤﻌﻴﺎر ﻣﻦ ﻗﺒﻞ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ ﺣﻮاﻟﻲ اﻟﻌﺎم 0002 وﺗﺒﻨﺖ اﻟﻌﺪﻳﺪ ﻣﻦ اﻟﺸﺮﻛﺎت ﻫﺬا اﻟﻤﻌﻴﺎر‬‫ﻟﻴﻜﻮن ﻗﺎﻋﺪة اﻧﻄﻼﻗﻬﺎ ﻓﻲ ﻟﻐﺎت اﻟﺒﺮﻣﺠﺔ ، ﺣﻴﺚ ﺗﺘﻤﻴﺰ ﺟﻤﻴﻊ ﻫﺬه اﻟﻠﻐﺎت ﺑﺈن ﻟﻬﺎ اﻟﻜﻮد اﻟﻤﺼﺪري‬‫ﻧﻔﺴﻪ ، وﺗﺘﺮﺟﻢ ﻧﻔﺴﻬﺎ ﻣﺮورًا ﺑﻨﻔﺲ اﻟﻤﺮاﺣﻞ وﻻ ﺗﺨﺘﻠﻒ ﺳﻮى ﻓﻲ ﻃﺮﻳﻘﺔ اﻟﺼﻴﺎﻏﺔ ... ﺳﻨﻘﻮم‬‫ﺑﺎﻟﺘﻌﺮف ﻋﻠﻰ اﻟﻤﻜﻮﻧﺎت اﻻﺳﺎﺳﻴﺔ ﻟﻤﺤﺮك اﻟﻠﻐﺔ ‪ Engine‬ﻛﺎﻣﻠﺔ .. وﻟﻜﻦ ﻗﺒﻼ ﻟﻨﺘﻌﺮف ﻋﻠﻰ ﺑﻌﺾ‬ ‫ً‬ ‫اﻟﻠﻐﺎت اﻟﺘﻲ ﺗﺒﻨﺖ ﻣﻌﻴﺎر ‪ .net‬‬‫ﻓﺒﻌﺪ اﻟﻠﻐﺎت اﻟﺘﻲ ﺗﺼﺪرﻫﺎ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ ﺑﻨﻔﺴﻬﺎ واﻟﺘﻲ ﺗﻀﻢ #‪ ، J#.net ،VB.net  ، C‬اﺿﺎﻓﺔ‬‫إﻟﻰ‪ C++/CLI‬وأﺧﻴﺮًا ... ‪ JScript.net‬ﻫﻨﺎك اﻟﻠﻐﺎت اﻷﺧﺮى اﻟﺘﻲ ﺗﺪﻋﻢ ﻣﻌﻴﺎرﻳﺔ ‪ .net‬ﻣﺜﻞ ﺑﺎﺳﻜﺎل‬ ‫ودﻟﻔﻲ ، ﻛﻮﺑﻮل وﺣﺘﻰ ‪ LISP.net‬ﻟﺒﺮﻣﺠﺔ ﺗﻄﺒﻴﻘﺎت اﻟﺬﻛﺎء اﻹﺻﻄﻨﺎﻋﻲ.‬‫ﻻ ﻧﻨﺴﻰ اﻳﻀﺎ اﻹﺻﺪارات اﻟﺘﻲ ﺗﻌﻤﻞ ﻋﻠﻰ ﺑﻴﺌﺔ ‪ ، Linux‬ف ‪ mono‬ﻣﺜﻼ ﻳﺪﻋﻢ ﻣﻌﻴﺎرﻳﺔ ‪ .net‬ﺗﺤﺖ ﺑﻴﺌﺔ‬ ‫ً‬ ‫ً‬‫اﻟﻠﻴﻨﻜﺲ .. ﻟﻜﻦ ﻓﻲ اﻟﻨﻬﺎﻳﺔ ﻓﻘﺪ ﻛﺎن اﻟﻤﻨﺘﺞ اﻻﺳﺎﺳﻲ ﻟﺨﺪﻣﺔ ﺑﻴﺌﺔ ‪ .net‬ﻫﻮ #‪ ، C‬ﻟﺘﻨﻀﻢ إﻟﻴﻪ‬‫ﻻﺣﻘﺎ ‪ VB.net‬رﺑﻤﺎ ﻻﻏﺮاض ﺗﺴﻮﻳﻘﻴﺔ وﺑﺪأ ﺑﻌﺪﻫﺎ ﺗﺘﺎﺑﻊ اﻟﻠﻐﺎت ، ﻻ ﻧﻨﺴﻰ ان اﻧﻀﻤﺎم #‪ f‬ﻟﻠﻤﺠﻤﻮﻋﺔ‬ ‫ً‬ ‫ﻗﺪ ﻳﺠﻌﻠﻪ ﻳﻮﻣﺎ ﻣﺎ اﻻﺳﻠﻮب رﻗﻢ 1 ﻟﻠﺒﺮﻣﺠﺔ ﺑﺘﻘﻨﻴﺔ ‪ .net‬‬ ‫ً‬‫ﺗﺴﺘﻄﻴﻊ ﻓﻲ اﻟﻨﻬﺎﻳﺔ اﻻﻃﻼع ﻋﻠﻰ ﻣﺠﻤﻞ اﻟﻠﻐﺎت اﻟﺘﻲ ﺗﺪﻋﻢ ﻫﺬه اﻟﻤﻌﻴﺎرﻳﺔ ﻣﻊ ﺑﻌﺾ اﻟﺘﻔﺼﻴﻼت ﻋﻨﻬﺎ‬ ‫ﻫﻨﺎ:‬ ‫راﺑﻂ‬ ‫‪http://www.dotnetlanguages.net/DNL/Resources.aspx‬‬‫75‬
  • ‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ال ‪ .net‬اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺮاﺑﻊ‬ ‫اﺿﺎﻓﺔ‬ ‫ﻓﻲ ﻛﺘﺎب :‬ ‫‪Pro C# 2008 .NET 3.5 Platform -Exploring the .NET universe using curly‬‬ ‫‪brackets‬‬ ‫ﻳﻄﺮح اﻟﻜﺎﺗﺐ ﺗﺴﺎؤﻻ وﻳﺠﻴﺐ ﻋﻠﻴﻪ، ﻟﻤﺎذا ﻛﻞ ﻫﺬا اﻟﻌﺪد ﻣﻦ ﻟﻐﺎت ‪ .net‬ﻣﺎ دام ﺳﻴﺘﺤﻮﻟﻮا ﺟﻤﻴﻌﺎ ﻓﻲ‬ ‫ً‬ ‫ً‬ ‫اﻟﻨﻬﺎﻳﺔ إﻟﻰ ‪ maneged code‬وﻳﺠﻴﺐ ﻋﻠﻰ ﻫﺬا اﻟﺘﺴﺎؤل ﺑﻌﺪة اﺳﺒﺎب :‬ ‫ان اﻟﻌﺪﻳﺪ ﻣﻦ اﻟﻤﺒﺮﻣﺠﻴﻦ ﺣﺴﺎﺳﻴﻦ ﺟﺪًا ﻟﻠﻐﺔ اﻟﺘﻲ ﻳﺒﺮﻣﺠﻮن ﺑﻬﺎ وﻳﺤﺒﻮﻧﻬﺎ ، ﻓﺒﻌﻀﻬﻢ ﻳﻔﻀﻞ‬ ‫-‬ ‫اﺳﻠﻮب اﻟﻜﺘﺎﺑﺔ ب ; واﻷﻗﻮاس ... ﻓﻴﻤﺎ ﻳﻔﻀﻞ اﻟﺒﻌﺾ اﻵﺧﺮ اﻻﺳﻠﻮب اﻷﻛﺜﺮ ﻗﺎﺑﻠﻴﺔ ﻟﻠﻘﺮاءة ﻣﺜﻞ‬ ‫‪ Syntax‬ﻟﻐﺎت  ‪ ، Visual  Basic‬ﻻ ﻧﻨﺴﻰ ﻫﻨﺎ اﻟﺪور اﻟﺘﺴﻮﻳﻘﻲ وﻣﺤﺎوﻟﺔ ﺟﺬب ﺟﻤﻴﻊ اﻟﻤﺒﺮﻣﺠﻴﻦ‬ ‫ﻟﻠﻌﻤﻞ ﻣﻊ ‪ .net‬ﺣﻴﺚ ﻳﻤﻜﻦ ﻟﻤﺒﺮﻣﺠﻲ  #‪ C‬و ‪ Basic‬و ++‪ C‬و ‪ Fortran‬و ‪ Delphi‬اﻟﻌﻤﻞ ﺟﻤﻴﻌﺎ‬ ‫ً‬ ‫ﺗﺤﺖ ﻣﻨﺼﺔ واﺣﺪة ، وﻫﺬا ﻣﺎ ﻳﺠﻌﻞ اﻧﺘﻘﺎﻟﻬﻢ ﺑﻴﻨﻬﺎ اﺳﻬﻞ اﺿﺎﻓﺔ ﻟﺘﺠﻤﻴﻊ اﻟﻤﺒﺮﻣﺠﻴﻦ ﺗﺤﺖ ﻣﻈﻠﺔ‬ ‫واﺣﺪة.‬ ‫- ﻣﺸﺎرﻛﺔ اﻟﻔﺮﻳﻖ اﻟﻮاﺣﺪ ﻣﺒﺮﻣﺠﻴﻦ ﺑﻠﻐﺎت ﻣﺘﻌﺪدة ، ﺣﻴﺚ ﻳﻤﻜﻦ ان ﺗﺠﺪ ﻓﻲ اﻟﻔﺮﻳﻖ اﻟﻮاﺣﺪ‬ ‫ﻣﺒﺮﻣﺠﻴﻦ ﻳﺒﺮﻣﺠﻮن ﺑﻌﺪة ﻟﻐﺎت وﻳﺘﻢ اﺧﺮاج ﻣﻨﺘﺞ واﺣﺪ ﻓﻲ اﻟﻨﻬﺎﻳﺔ ﺑﻌﺪ ان ﻛﺎن ﻣﻦ اﻟﻤﻔﻀﻞ ان‬ ‫ﻳﻜﻮن اﻟﻤﺒﺮﻣﺠﻴﻦ ﻟﻨﻔﺲ اﻟﻠﻐﺔ ، ﻫﺬا ﻳﻔﺘﺢ اﻻﺧﺘﻴﺎرات ﻛﺜﻴﺮًا اﻣﺎم اﻟﺸﺮﻛﺎت ﻓﻲ اﺧﺘﻴﺎر‬ ‫اﻟﻤﺒﺮﻣﺠﻴﻦ.‬ ‫ﺑﻌﺾ اﻟﻠﻐﺎت ﺗﺘﻤﻴﺰ ﺑﻨﻘﺎط ﻗﻮة ﺗﻀﻄﺮ اﻟﻨﺎس ﻻﺳﺘﺨﺪاﻣﻬﺎ ، ﻓﻤﺜﻼ ﻫﻨﺎك ﻟﻐﺎت ﻣﻤﻴﺰة ﻓﻲ‬ ‫ً‬ ‫-‬ ‫اﻟﻌﻤﻠﻴﺎت اﻟﺮﻳﺎﺿﻴﺔ واﻟﻤﻌﺎدﻻت ﻣﺜﻞ اﻟﻔﻮرﺗﺮان ، اﻟﻜﻮﺑﻮل ﻣﻤﻴﺰة اﻳﻀﺎ ﻓﻲ اﻟﺘﻌﺎﻣﻼت اﻟﻤﺎﻟﻴﺔ‬ ‫ً‬ ‫واﻟﻌﻤﻠﻴﺎت اﻟﺤﺴﺎﺑﻴﺔ ... ﻫﻜﺬا ﺗﺴﺘﻄﻴﻊ اﻻﺳﺘﻔﺎدة ﻣﻦ ﻫﺬه اﻟﻤﻤﻴﺰات وﺗﺪﻣﺠﻬﺎ ﺟﻤﻴﻌﺎ ﻣﻊ ﺑﻌﻀﻬﺎ‬ ‫ً‬ ‫ﺗﺤﺖ ﺑﻴﺌﺔ ال . ‪. net‬‬‫85‬
  • ‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ال ‪ .net‬اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺮاﺑﻊ‬ ‫2. اﻟﻌﻨﺎﺻﺮ اﻷﺳﺎﺳﻴﺔ ﻟﺒﻴﺌﺔ .‪net‬‬‫ﺗﻘﺪم  ‪ .net‬ﺑﻴﻦ ﻃﻴﺎﺗﻬﺎ ﺛﻼث ﻋﻨﺎﺻﺮ رﺋﻴﺴﻴﺔ ﺗﺘﺤﻜﻢ ﻓﻲ دورة ﺣﻴﺎة اﻟﺒﺮﻧﺎﻣﺞ اﻟﻤﻌﺘﻤﺪ ﻋﻠﻰ‬ ‫ﺑﻴﺌﺔ.‪ ،net‬ﻫﺬه اﻟﺘﻘﻨﻴﺎت اﻟﺜﻼث ﻳﺮﻣﺰ ﻟﻬﺎ اﺧﺘﺼﺎرًا ﺑﺄﺳﻤﺎء: ‪.CLR, CTS and CLS‬‬‫ﺗﻤﺜﻞ ال ‪ CLR‬ال ‪ Runtime  Layer‬ﻟﻠﺒﺮﻧﺎﻣﺞ ، وﻫﻲ اﺧﺘﺼﺎر ل‪،Common  Language  Runtime‬‬‫ﻣﻬﻤﺘﻪ اﻻﺳﺎﺳﻴﺔ ﻫﻲ اﻟﺘﺤﻜﻢ ﻓﻲ اﻷﻧﻮاع واﻟﻤﻜﻮﻧﺎت اﻟﺮﺋﻴﺴﻴﺔ ﻟﻞ - ‪ .net‬اﻟﻤﻜﺘﺒﺎت واﻟﺪوال - وﺣﺠﺰ‬‫اﻟﻤﺘﻐﻴﺮات ﻓﻲ اﻟﺬاﻛﺮة وﺗﻘﺴﻴﻢ اﻟﺬاﻛﺮة واﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ، ال ‪ Threads‬واﻟﺘﻨﻔﻴﺬ اﺿﺎﻓﺔ ﻟﺒﻌﺾ‬‫اﺧﺘﺼﺎرات اﻷﻣﺎن ،" ﺑﺎﺧﺘﺼﺎر ﺷﺪﻳﺪ ﺗﺸﻜﻞ ال ‪ CLR‬اﻟﻤﺮﺣﻠﺔ اﻻﺳﺎﺳﻴﺔ ﻟﺘﺮﺟﻤﺔ أواﻣﺮ  ‪ .net‬وﺗﻨﻔﻴﺬﻫﺎ‬ ‫ﻋﻠﻰ ﺟﻬﺎز اﻟﻜﻮﻣﺒﻴﻮﺗﺮ.‬‫ال ‪ Common  Type  System‬واﻟﺬي ﻳﺘﻢ اﺧﺘﺼﺎره ب ‪ CTS‬ﻣﺨﺘﺺ ﺑﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻧﻮاع اﻟﺒﻴﺎﻧﺎت‬‫اﻟﻤﺪﻋﻮﻣﺔ ﻟﻠﻌﻤﻞ ﺿﻤﻦ ﺑﻴﺌﺔ ‪ ،.net‬وﻛﻴﻒ ﻳﺘﻢ اﻟﺘﻌﺎﻣﻞ ﺑﻴﻨﻬﻢ وﺑﻴﻦ ﺑﻌﻀﻬﻢ ، ﻣﻊ ﻣﺮاﻋﺎة وﺟﻮد ﺑﻌﺾ‬‫اﻻﻧﻮاع ﻏﻴﺮ اﻟﻤﺪﻋﻮﻣﺔ ﻓﻲ ﺟﻤﻴﻊ ﺑﻴﺌﺎت ‪ .net‬واﻟﺘﻲ ﺗﻮﺟﺪ ﺑﻬﺎ اﺧﺘﻼﻓﺎت ﺑﻴﻦ ﺑﻴﺌﺔ وأﺧﺮى ، أﻣﺎ‬‫اﻷﺧﻴﺮة وﻫﻲ ‪ Common Language Specification‬واﻟﺘﻲ ﻳﺘﻢ اﺧﺘﺼﺎرﻫﺎ ﺑﺎﻟﺮﻣﺰ ‪ CLS‬ﻓﻬﻲ ﻣﺨﺘﺼﺔ‬ ‫ﺑﺎﻟﺘﻌﺎﻣﻞ ﻓﻘﻂ ﻣﻊ اﻧﻮاع اﻟﺒﻴﺎﻧﺎت اﻟﻘﻴﺎﺳﻴﺔ واﻟﻤﺪﻋﻮﻣﺔ ﻣﻦ ﺟﻤﻴﻊ اﺻﺪارات ﺑﻴﺌﺔ ‪. . Net‬‬‫وﺑﻬﺬا ﻧﺴﺘﻄﻴﻊ ان ﻧﻘﻮل ان اﻟﺒﺮﻧﺎﻣﺞ اﻟﻤﺼﻤﻢ ﺑﺎﺳﺘﺨﺪام  #‪ C‬ﻣﺜﻼ وﻳﺴﺘﺨﺪم ﻓﻘﻂ اﻷﻧﻮاع اﻟﻤﺘﺎﺣﺔ ﻓﻲ‬ ‫ً‬‫‪ CLS‬ﻫﻮ ﻣﺘﻮاﻓﻖ ﺗﻤﺎﻣﺎ ﻟﻠﻌﻤﻞ ﻋﻠﻰ ﻧﻔﺲ ﺗﻮزﻳﻌﺔ ‪ .net‬ﻣﻦ اﺟﻞ اﻟﻌﻤﻞ ﻋﻠﻰ ‪ Linux‬اﻟﻤﺴﻤﺎه ‪ ،mono‬اﻣﺎ‬ ‫ً‬‫ﻟﻮ ﺧﺮﺟﺖ ﺧﺎرج ﻧﻄﺎق ال‪  CLS‬إﻟﻰ ‪ CTS‬ﻓﻠﻦ ﺗﻀﻤﻦ ان ﻳﺘﻢ ﺗﻨﻔﻴﺬﻫﺎ ﺑﻨﻔﺲ اﻟﻜﻔﺎءة ﻓﻲ ﻛﻞ اﻷﻧﻈﻤﺔ‬ ‫اﻟﻤﺨﺘﻠﻔﺔ.‬‫95‬
  • ‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ال ‪ .net‬اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺮاﺑﻊ‬ ‫3. ال ‪Base Class Library‬‬‫ﺗﻮﻓﺮ ﺗﻘﻨﻴﺔ ‪ .net‬ﻣﺎ ﻳﻌﺮف ﺑﺎﺳﻢ ‪ ،Base Class Library‬وﻫﻲ ﻋﺒﺎرة ﻋﻦ ﻣﺠﻤﻮﻋﺔ ﻣﻦ اﻟﻔﺌﺎت‬‫‪ Classes‬ﺗﺤﺘﻮي ﻋﻠﻰ اﻷواﻣﺮ واﻟﺪوال اﻟﺮﺋﻴﺴﻴﺔ ﻓﻲ ﺑﻴﺌﺔ. ‪ ،net‬ﻫﺬه اﻟﻔﺌﺎت ﻣﻮﺟﻮد ﻓﻲ ﺟﻤﻴﻊ ﺑﻴﺌﺎت‬‫.‪ net‬وﻳﺘﻢ اﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ وﻣﻊ ﺧﺼﺎﺋﺼﻬﺎ ﺑﻨﻔﺲ اﻟﻄﺮﻳﻘﺔ ، و ﺗﻀﻢ اﻟﻌﻨﺎﺻﺮ اﻻﺳﺎﺳﻴﺔ ﻣﺜﻞ اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬‫اﻟﻤﻠﻔﺎت وﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت ، ال‪ ،Threads‬ال ‪ ، XML‬ال ‪ GUI‬وﺧﻼﻓﻪ. وﺗﺴﺎﻫﻢ ﻫﺬه اﻟﻤﻜﺘﺒﺔ ﻓﻲ ﺟﻌﻞ‬ ‫اﺳﻠﻮب اﻟﺒﺮﻣﺠﺔ ﻣﻮﺣﺪ وأﺳﻬﻞ. وﻗﺎﺑﻞ ﻟﻠﺘﻜﺎﻣﻞ ﻣﻊ أي ﻣﻦ اﻟﻠﻐﺎت اﻟﺘﻲ ﺗﺪﻋﻢ ‪.Net‬‬ ‫ﻫﺬا اﻟﺠﺪول ﻟﺒﻌﺾ ﻣﺤﺘﻮﻳﺎت ال ‪ BCL‬ﻣﻦ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ:‬ ‫اﻟﺼﻮرة 4. 1. ﺑﻌﺾ ﻣﻜﻮﻧﺎت ال ‪ - BCL‬ﻣﻦ ال ‪- MSDN‬‬‫وﻛﺘﺮﺟﻤﺔ ﺳﺮﻳﻌﺔ ، ﻳﺤﺘﻮي ‪ System‬ﻋﻠﻰ ﻛﻞ ﻣﺎ ﺗﺤﺘﺎﺟﻪ ﻟﺘﻄﻮﻳﺮ ﺗﻄﺒﻴﻘﺎت ‪ ، .net‬ﻳﺤﺘﻮي اﻳﻀﺎ‬‫ً‬‫ﻋﻠﻰ ال ‪ Data  types‬واﻟﺪوال اﻻﺳﺎﺳﻴﺔ ﻟﻠﻌﻤﻠﻴﺎت اﻟﺤﺴﺎﺑﻴﺔ .. اﻟﺦ ، ﺑﺎﺧﺘﺼﺎر ﺷﺪﻳﺪ ﺗﺠﺪ‬ ‫أن ‪ System‬ﻫﻲ ﻣﺠﺎل اﻷﺳﻤﺎء اﻟﺮﺋﻴﺴﻲ واﻟﺘﻲ ﺗﺤﺘﻮي ﺗﺤﺘﻬﺎ ﻋﻠﻰ ﺑﺎﻗﻲ اﻟﻔﺌﺎت.‬‫06‬
  • ‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ال ‪ .net‬اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺮاﺑﻊ‬ ‫اﻟﻮﺻﻒ‬ ‫ﻣﺠﺎل اﻷﺳﻤﺎء‬ ‫‪ System.CodeDom‬ﺧﺎﺻﺔ ﺑﻜﺘﺎﺑﺔ اﻻﻛﻮاد وﺗﻨﻔﻴﺬﻫﺎ‬ ‫‪ System.Collections‬ﺗﺤﺘﻮي ﻋﻠﻰ ﻋﺪد ﻣﻦ اﻻﻧﻮاع ﻣﺜﻞ ‪.Lists, Stack‬‬ ‫‪ System.Diagnostics‬ﻳﻀﻢ ال ‪ Events‬وال ‪ Counters‬وال‪Process‬‬ ‫‪ System.Globalization‬ﻳﺘﻌﻠﻖ ﺑﺘﺸﻐﻴﻞ ﺑﺮﻧﺎﻣﺠﻚ ﻋﻠﻰ ﻧﻈﻢ ﻣﺨﺘﻠﻔﺔ ﻣﻦ ﺣﻴﺚ اﻟﻠﻐﺎت‬ ‫واﻻﻋﺪادات اﻻﻗﻠﻴﻤﻴﺔ وﺧﻼﻓﻪ.‬ ‫‪ System.IO‬ﻛﻞ ﻣﺎ ﻳﺘﻌﻠﻖ ﺑﻌﺮض واﺳﺘﻘﺒﺎل اﻟﺒﻴﺎﻧﺎت ﺳﻮاء ﻋﻦ ﻃﺮﻳﻖ‬ ‫اﻟﻤﻠﻔﺎت واﻟﻤﺠﻠﺪات ، او ﻋﻦ ﻃﺮﻳﻖ ﻣﻨﺎﻓﺬ اﻟﻜﻮﻣﺒﻴﻮﺗﺮ ﻣﺜﻞ‬ ‫ال‪Serial Port‬‬ ‫‪ System.Resources‬ال ‪ Resources‬اﻟﺘﻲ ﺗﺼﻒ اﻟﺒﺮﻧﺎﻣﺞ ، ﻳﺘﻴﺢ ﻟﻚ ﻋﻤﻞ‬ ‫ﺗﻄﺒﻴﻘﺎت ﻣﺘﻌﺪدة اﻟﻠﻐﺎت ﻋﻠﻰ ﺳﺒﻴﻞ اﻟﻤﺜﺎل‬ ‫‪ System.Text‬ﻛﻞ ﻣﺎ ﻳﺘﻌﻠﻖ ﺑﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻨﺼﻮص‬ ‫‪ System.Text.RegularE‬اﻟﺘﻌﺎﻣﻞ ﻣﻊ ال ‪Regular Expressions‬‬ ‫‪xpressions‬‬ ‫اﻟﺠﺪول 4. 1. ﺑﻌﺾ ﻣﻜﻮﻧﺎت ﻣﺠﺎل اﻷﺳﻤﺎء ‪System‬‬ ‫4 . ‪.net Assemblies‬‬‫ﻓﻲ اﻟﻨﻬﺎﻳﺔ وﻣﻬﻤﺎ ﻛﺎﻧﺖ ﻟﻐﺔ اﻟﺒﺮﻣﺠﺔ وال ‪ Compiler‬اﻟﺬي ﺗﺴﺘﺨﺪﻣﻪ ﻟﺒﻨﺎء ﺗﻄﺒﻴﻘﺎت ‪،.net‬‬‫ﻓﺈن اﻟﻜﻮد ﻳﺘﺤﻮل ﻓﻲ اﻟﻨﻬﺎﻳﺔ ل  ‪ intermediate language‬وﻫﻮ ﻣﺎ ﻳﻌﺮف اﺧﺘﺼﺎرًا ‪ IL‬ﺑﺎﻻﺿﺎﻓﺔ إﻟﻰ‬‫ﺑﻌﺾ ال ‪ ، metadata‬وﻳﺘﻢ وﺿﻌﻪ ﻓﻲ ﻣﻠﻒ اﺳﻤﺒﻠﻲ ﻗﺎﺑﻞ ﻟﻠﻌﻤﻞ ﻣﺒﺎﺷﺮة ﺳﻮاء ﻋﻠﻰ ﺷﻜﻞ ‪ exe‬أو‬ ‫ﻋﻠﻰ ﺷﻜﻞ ‪dll‬‬‫16‬
  • ‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ال ‪ .net‬اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺮاﺑﻊ‬‫ﺳﺎﺑﻘﺎ ﻛﺎن ﻳﺮﻣﺰ ﻟﻞ ‪ IL‬ﺑﺎﺳﻢ ‪ MSIL‬وال ‪ MS‬اﺧﺘﺼﺎر ﻟﻤﺎﻳﻜﺮوﺳﻮﻓﺖ ، اﻣﺎ اﻵن ﻓﺘﻤﺖ اﺿﺎﻓﺔ‬ ‫ً‬ ‫اﻟﻼﺣﻘﺔ ‪ C‬ﻛﺎﺧﺘﺼﺎر ل ‪ Common‬ﺑﺪﻻ ﻣﻦ ‪ MS‬اﻟﺴﺎﺑﻘﺔ.‬ ‫ً‬‫ﻳﻤﺜﻞ ال ‪  IL‬أو ال ‪ MSIL‬اﻟﻤﻬﺎم اﻟﺘﻲ ﻳﻘﻮم ﺑﻬﺎ اﻟﺒﺮﻧﺎﻣﺞ واﻷﻛﻮاد وﻣﺎ ﺷﺎﺑﻪ ، اﻣﺎ ال ‪metadata‬‬‫ﻓﺘﺤﺘﻮي ﻋﻠﻰ وﺻﻒ ﻟﺠﻤﻴﻊ اﻷﻧﻮاع واﻟﻔﺌﺎت اﻟﺘﻲ اﺳﺘﺨﺪﻣﺘﻬﺎ ﻓﻲ ﺑﺮﻧﺎﻣﺠﻚ ، ﻣﻠﻒ اﻻﺳﻤﺒﻠﻲ ﻧﻔﺴﻪ‬‫اﻟﺬي ﻳﻀﻢ ال ‪ IL‬وال ‪ metadata‬ﻳﺘﻢ وﺻﻔﻪ ب ‪ metadata‬أﻳﻀﺎ ، ﻳﺘﻢ اﺿﺎﻓﺔ ‪ manifest‬اﻳﻀﺎ ﻟﻬﺬه‬ ‫ً‬ ‫ً‬‫اﻟﻤﺠﻤﻮﻋﺔ ، ﻫﻨﺎك ﺣﺎﻻت ﺗﺠﺪ ﺑﺮﻧﺎﻣﺠﻚ ﻓﻴﻬﺎ ﻣﺮﺗﺒﻄﺎ ﺑﺎﻛﺜﺮ ﻣﻦ ﻣﻠﻒ اﺳﻤﺒﻠﻲ ، وﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ‬ ‫ً‬‫ﻟﻦ ﻳﻜﻮن ﻟﺪﻳﻚ ﺳﻮى ‪ manifest‬واﺣﺪ ﻓﻘﻂ ﻓﻲ واﺣﺪ ﻣﻨﻬﺎ ﻳﻘﻮم ﺑﻌﻤﻞ اﻟﺒﺪاﻳﺔ ورﺑﻂ اﻟﻤﻠﻔﺎت ﻣﻊ‬ ‫ﺑﻌﻀﻬﺎ اﻟﺒﻌﺾ.‬ ‫5. ال ‪  CIL‬‬ ‫ﻟﻨﻔﺘﺮض ﻫﺬا اﻟﺒﺮﻧﺎﻣﺞ ﺑﻠﻐﺔ #‪ C‬ﻣﻦ ﻛﺘﺎب 8002 ‪Pro CSharp‬‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪// Calc.cs‬‬ ‫;‪using System‬‬ ‫‪namespace CalculatorExample‬‬ ‫{‬ ‫.‪// This class contains the apps entry point‬‬ ‫‪class Program‬‬ ‫{‬ ‫)(‪static void Main‬‬ ‫{‬ ‫;)(‪Calc c = new Calc‬‬ ‫;)48 ,01(‪int ans = c.Add‬‬ ‫;)‪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‬‬ ‫}‬ ‫}‬ ‫ﻟﻮ ﻗﻤﺖ ﺑﻔﺘﺢ اﻻﺳﻤﺒﻠﻲ اﻟﻨﺎﺗﺞ ﻋﻦ ﻫﺬا اﻟﻜﻮد ﺑﺎﺳﺘﺨﺪام أي ﺗﻄﺒﻴﻖ ﻣﻨﺎﺳﺐ ﻣﺜﻞ ‪ ILDASM‬ﺳﺘﺠﺪ اﻟﻜﻮد‬‫26‬
  • ‫. اﻟﺮﺋﻴﺴﻴﺔ‬net ‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ال‬   ‫اﻟﺒﺎب اﻟﺮاﺑﻊ‬ CIL ‫ﻛﻮد‬ .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‫، ﻳﺘﻢ ذﻟﻚ ﻓﻲ‬Platform‐Specific  Instructions ‫ﺣﺘﻰ ﻫﺬه اﻟﻤﺮﺣﻠﺔ ، ﻟﻢ ﻳﺘﻢ ﺗﺤﻮﻳﻞ اﻟﻜﻮد إﻟﻰ‬‫ واﻟﺬي ﻳﻘﻮم ﺑﺘﺮﺟﻤﺔ اﻟﻜﻮد اﻟﻨﺎﺗﺞ إﻟﻰ ﻛﻮد ﻣﻨﺎﺳﺐ‬Jitter ‫اﻟﻤﺮﺣﻠﺔ اﻟﺘﺎﻟﻴﺔ ﻣﻦ ﺧﻼل ﻣﺎ ﻳﻌﺮف ﺑﺎﺳﻢ‬ .‫ﻻﻣﻜﺎﻧﻴﺎت اﻟﺠﻬﺎز وﻧﻈﺎم اﻟﺘﺸﻐﻴﻞ اﻟﺬي ﻳﻌﻤﻞ ﻋﻠﻴﻪ اﻟﺒﺮﻧﺎﻣﺞ‬ : ‫ﺑﺎﻣﻜﺎﻧﻚ اﻟﺘﻌﺮف ﻋﻠﻰ اﻟﻤﺰﻳﺪ ﻋﻦ ﻫﺬا اﻟﻤﻮﺿﻮع ﻣﻦ ﻫﺬا اﻟﺮاﺑﻂ ﻣﻦ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ‬ ‫راﺑﻂ‬ http://msdn.microsoft.com/en-us/library/f7dy01k1(VS.80).aspx   MetaData ‫6. ال‬ ‫ اﻟﺘﻲ ﺗﺴﺘﺨﺪم ﻟﻮﺻﻒ ﻛﻞ ﻣﺤﺘﻮﻳﺎت اﻟﻜﻮد ﻣﻦ دوال وﻓﺌﺎت وواﺟﻬﺎت وﺧﻼﻓﻪ‬MetaData ‫ﻣﺜﺎل ﻋﻠﻰ‬ Assembly Metadata ‫ﻛﻮد‬ 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)63
  • ‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ال ‪ .net‬اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺮاﺑﻊ‬‫ﻳﻘﻮم اﻟﺠﺰء اﻟﺴﺎﺑﻖ ﺑﻮﺻﻒ اﻟﻜﻮد اﻟﺬي ﻗﻤﻨﺎ ﺑﻜﺘﺎﺑﺘﻪ ﻓﻲ أول ﻣﺜﺎل ، ﻳﻤﻜﻨﻚ واﻧﺖ ﺗﻌﻤﻞ ﻋﻠﻰ ‪ .net‬ان‬‫ﺗﻘﻮم ﺑﺎﻻﻃﻼع ﻋﻠﻰ ﻫﺬا اﻟﻜﻮد ، اﻏﻠﺐ اﻟﻨﻘﺎط واﺿﺤﺔ وﺗﺸﺮح ﻧﻔﺴﻬﺎ ، اﻋﺘﻘﺪ اﻧﻪ رﺑﻤﺎ ﻟﻦ ﺗﺤﺘﺎج ﻳﻮﻣﺎ‬‫ً‬ ‫ﻟﻠﺘﻌﺪﻳﻞ اﻟﻴﺪوي ﻋﻠﻰ ﻫﺬا اﻟﻤﻠﻒ.‬ ‫7. ال ‪  Manifest‬‬‫ﻧﺴﺨﺔ واﺣﺪة ﻓﻘﻂ ﻣﻦ ﻫﺬا اﻟﻤﻠﻒ ﻟﻜﻞ ﺑﺮﻧﺎﻣﺞ ﺣﺘﻰ ﻟﻮ ﻛﺎن ﻫﻨﺎك اﻛﺜﺮ ﻣﻦ  ‪Assembly‬‬‫‪ ،File‬ﻳﺼﻒ ﻫﺬا اﻟﻤﻠﻒ اﻻﺳﻤﺒﻠﻲ ﻧﻔﺴﻪ ﻣﻦ ﺣﻴﺚ رﻗﻢ ﻧﺴﺨﺔ اﻻﺳﻤﺒﻠﻲ وﻣﻠﻒ اﻻﺳﻤﺒﻠﻲ اﻟﺮﺋﻴﺴﻲ ﻓﻲ‬ ‫ﺣﺎﻟﺔ وﺟﻮد اﻛﺜﺮ ﻣﻦ ﻣﻠﻒ ، ﻫﺬا ﻣﺜﺎل ﻋﻠﻰ ﻛﻮد ﻣﻦ ﻫﺬه اﻟﻨﻮﻋﻴﺔ:‬ ‫‪Assembly Manifest‬‬ ‫ﻛﻮد‬ ‫‪.assembly extern mscorlib‬‬ ‫{‬ ‫) 98 0‪.publickeytoken = (B7 7A 5C 56 19 34 E‬‬ ‫0:0:0:2 ‪.ver‬‬ ‫}‬ ‫‪.assembly Calc‬‬ ‫{‬ ‫40080000‪.hash algorithm 0x‬‬ ‫0:0:0:0 ‪.ver‬‬ ‫}‬ ‫‪.module Calc.exe‬‬ ‫00000400‪.imagebase 0x‬‬ ‫30000000‪.subsystem 0x‬‬ ‫215 ‪.file alignment‬‬ ‫10000000‪.corflags 0x‬‬ ‫8.  ‪Common Type System‬‬‫ﺳﻨﺮﻛﺰ ﻓﻲ ﻫﺬا اﻟﻤﻮﺿﻮع اﻟﻤﺨﺘﺼﺮ ﻋﻠﻰ ‪ CTS‬ﺣﻴﺚ ﺳﺒﻖ وذﻛﺮﻧﺎ اﻧﻪ ﻣﺨﺘﺺ ﺑﻮﺻﻒ اﻻﻧﻮاع‬ ‫اﻟﻤﺪﻋﻮﻣﺔ ﻓﻲ ﺑﻴﺌﺔ ‪ .net‬وﻛﻴﻔﻴﺔ ﺗﻌﺎﻣﻠﻬﺎ ﻣﻊ ﺑﻌﻀﻬﺎ اﻟﺒﻌﺾ ، ﻫﺬه اﻷﻧﻮاع ﻫﻲ:‬ ‫- ‪  Class‬‬ ‫- ‪Interface‬‬‫46‬
  • ‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ال ‪ .net‬اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺮاﺑﻊ‬ ‫- ‪Structure‬‬ ‫- ‪Enumeration‬‬ ‫- ‪Delegate‬‬‫ﺳﻨﺘﻌﺮف ﻋﻠﻰ ﻃﺮﻳﻘﺔ ﺗﻌﺮﻳﻒ ﻛﻞ ﻣﻨﻬﻢ ﻓﻲ ﻣﺮﺣﻠﺔ ﻣﺨﺘﻠﻔﺔ ﻣﻦ اﻟﻜﺘﺎب ، إﻻ ان ﻣﺎ ﻳﺘﻌﻠﻖ ﺑﻨﺎ اﻵن‬‫ﺧﻼل اﻟﺪرس اﻟﺨﺎص ﺑﻨﺎ ﻫﻮ ﻛﻴﻔﻴﺔ ﺗﻌﺎﻣﻞ ال ‪ CTS‬ﻣﻌﻬﻢ ، إذا ﻛﻨﺖ ﻣﺒﺮﻣﺞ ﺗﻄﺒﻴﻘﺎت ﻋﺎدﻳﺔ ﻓﻠﻦ‬‫ﺗﺤﺘﺎج ﻟﻤﻌﺮﻓﺔ اﻛﺜﺮ ﻣﻦ ﻓﺎﺋﺪة ال ‪ CTS‬اﻣﺎ ﻣﺒﺮﻣﺠﻮ اﻷدوات او اﻟﺬﻳﻦ ﻳﻘﻮﻣﻮن ﺑﺒﻨﺎء ‪ Compiler‬او‬‫ﻟﻐﺔ ﺑﺮﻣﺠﺔ ﺿﻤﻦ ﺑﻴﺌﺔ ﺗﻄﻮﻳﺮ ‪ .net‬ﻓﻴﺤﺘﺎﺟﻮن ﻟﻠﺘﻌﺮف ﻋﻠﻰ اﻟﺨﺼﺎﺋﺺ اﻻﺳﺎﺳﻴﺔ ، ﺳﺄذﻛﺮ ﻣﺜﺎﻻ‬‫ً‬ ‫ﻣﺨﺘﺼﺮًا ﻋﻠﻰ ‪Class‬‬‫ﻫﻨﺎك ﻣﺎ ﻳﻌﺮف ﺑﺎﺳﻢ ‪ ، Abstract Class‬ال ‪ Abstract Class‬ﻻ ﻳﺤﺘﻮي ﻋﻠﻰ اي ﻛﻮد - ﺷﺪﻳﺪ اﻟﺸﺒﻪ‬‫ﺑﺎل - ‪ interface‬ﺑﺤﻴﺚ ﻳﻤﻜﻦ ﺑﻌﺪ ذﻟﻚ ﻋﻤﻞ وراﺛﺔ ﻟﻪ ﻗﺒﻞ اﻟﺒﺪء ﻓﻲ اﺳﺘﺨﺪاﻣﻪ ﺣﻴﺚ اﻧﻪ ﻟﻦ ﻳﺤﺘﻮي‬ ‫ﻋﻠﻰ ﺳﻄﺮ ﻛﻮد واﺣﺪ ، ﻫﺬا ﻣﺜﺎل ﻟﻤﺎ ﻳﻌﺮف ﺑﺎﺳﻢ ‪Abstract Class‬‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪class abst_class‬‬ ‫{‬ ‫;)‪int sum(int x, int y‬‬ ‫;‪string name‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Class abst_class‬‬ ‫‪Private Function sum(ByVal x As Integer, ByVal y As Integer) As Integer‬‬ ‫‪End Function‬‬ ‫‪Private name As String‬‬ ‫‪End Class‬‬‫واﻵن ﻣﻦ ﺿﻤﻦ ﺟﺪول ﺧﺼﺎﺋﺺ ال ‪ CTS‬اﻟﺘﻲ ﺳﺘﺤﺘﺎج إﻟﻴﻬﺎ ﻓﻴﻤﺎ ﻟﻮ رﻏﺒﺖ ﻓﻲ اﻟﺘﻌﺎﻣﻞ ﻣﻊ ‪ CTS‬ﻓﻲ‬‫اﻟﻜﻮﻣﺒﺎﻳﻠﺮ اﻟﺨﺎص ﺑﻚ ﻣﺜﻼ . ﺳﺘﺠﺪ اﻟﺨﺎﺻﻴﺔ ‪ ، Is the class abstract or concrete‬ﺳﺘﺤﺘﺎج ﻗﺒﻞ‬ ‫ً‬ ‫اﺧﺒﺎر ‪ CTS‬ﺑﺎن ﻟﺪﻳﻚ ‪ Class‬ﻫﻨﺎ ان ﺗﺨﺒﺮه اﻳﻀﺎ ﺑﻤﺜﻞ ﻫﺬه اﻟﻨﻘﺎط.‬ ‫ً‬ ‫ﻣﻼﺣﻈﺔ‬ ‫ﻻ ﺗﻘﻠﻖ ﻟﻮ ﻟﻢ ﺗﺘﻀﺢ ﻟﺪﻳﻚ ﻣﺜﻞ ﻫﺬه اﻟﺨﺼﺎﺋﺺ ، ﻓﻲ دروس ﻗﺎدﻣﺔ ﺳﻨﺸﺮح ﺑﺎﻟﺘﻔﺼﻴﻞ ﻛﻴﻔﻴﺔ‬ ‫ﻋﻤﻞ‪ Class‬واﻧﻮاﻋﻪ وﻃﺮﻗﺔ اﻟﻤﺨﺘﻠﻔﺔ.‬‫56‬
  • ‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ال ‪ .ne‬اﻟﺮﺋﻴﺴﻴﺔ‬ ‫‪et‬‬ ‫ﻢ‬ ‫ ‬ ‫اﻟﺮاﺑﻊ‬ ‫اﻟﺒﺎب ﺑﻊ‬ ‫8. 1. ‪bers‬‬ ‫‪  CTS Memb‬‬‫ﺑﻌﺪ ان ﻗﻤﺖ ﺑﻮﺻﻒ اﻷﻧﻮاع ﺨﺘﻠﻔﺔ ﻣﻦ ﺧﻼل ‪ ، CTS‬ﻳﻤﻜﻨﻚ اﺿﺎﻓﺔ اي ﻋﺪد ﻣﻦ ال ‪ Members‬إﻟﻰ‬ ‫ﻣ‬ ‫ﻳ‬ ‫ﺧ‬ ‫اﻟﻤﺨ‬ ‫ﻗ‬ ‫ﻦ ان ﺗﻜﻮن ﻣﺘﻐﻴﺮات ﻋﺎدﻳﺔ ﻟﺤﻘﻮل ‪ ، Fields‬ﻜﻦ ان ﺗﻜﻮن اﻳﻀﺎ :‬ ‫ً‬ ‫ﻳﻤﻜ‬ ‫‪s‬‬ ‫ﻣ‬ ‫‪ Memb‬ﻳﻤﻜﻦ‬ ‫ﻛﻞ ﻬﻢ ، ال ‪bers‬‬ ‫ﻣﻨﻬ‬‫‪construct‬‬‫‪tor, finalize static  constructo nested  type,  ope‬‬ ‫ ,‪er‬‬ ‫ ,‪or‬‬ ‫‪erator,  me‬‬ ‫‪ethod,  pro‬‬ ‫ ,‪operty‬‬‫‪indexer, f‬‬ ‫‐‪field, read‬‬‫,‪‐only field‬‬ ‫,‪, constant‬‬ ‫ ‪, event‬‬ ‫ﻛﻞ ﺣﺪ ﻣﻦ ﻫﺬه اﻷﻋﻀﺎء ﻳﻪ ﻣﺎ ﻳﻌﺮف ﺑﺎﺳﻢ )‪rait‬‬ ‫‪ (visibility tr‬أو ﻣﺪى رؤﻳﺔ ، ﻳﻤﻜﻦ ان ﻳﻜﻮن‬ ‫ر‬ ‫ﻟﺪﻳ‬ ‫واﺣ‬‫ﺮف ﻋﻠﻴﻪ ﻻﺣﻘﺎ ﺿﻤﻦ‬ ‫ً‬ ‫ﺚ ﻳﻤﻜﻦ ﻳﺘﻪ ﻣﻦ رج اﻟﻔﺌﺔ ‪ .. Clas‬اﻟﺦ ﻣﻤﺎ ﺳﻨﺘﻌﺮ‬ ‫‪ss‬‬ ‫ﺧﺎر‬ ‫رؤﻳ‬ ‫‪ Public‬ﻣﺜﻼ ﺑﺤﻴﺚ‬ ‫ً‬ ‫ﻔﻬﺎ ﻓﻲ ‪.CTS‬‬ ‫ﺺ ﻳﺘﻢ ﺗﻮﺻﻴﻔ‬ ‫ف ان ﻛﻞ ﺬه اﻟﺨﺼﺎﺋﺺ‬ ‫ﻫﺬ‬ ‫دروﺳﻨﺎ ، ﻣﺎ ﻳﻌﻨﻴﻨﺎ ﻫﻨﺎ ان ﻧﻌﺮف‬ ‫ﻫ‬ ‫ً‬ ‫‪CTS D‬‬ ‫8. 2. ‪ypes‬‬ ‫‪Data Ty‬‬ ‫ب #‪Pro C‬‬ ‫ول ﻣﻦ ﻛﺘﺎب‬ ‫ﻳﺤﺘﻮي ال ‪ CTS‬ﻀﺎ ﻋﻠﻰ ال ‪ DataType‬اﻟﻤﺪﻋﻮﻣﺔ ﻦ ﻗﺒﻞ ‪ ، .net‬ﻫﺬا اﻟﺠﺪو‬ ‫ﻣﻦ‬ ‫‪es‬‬ ‫اﻳﻀً‬ ‫ ‬ ‫‪ ke‬ﻟﻠﻐﺎت ‪ .n‬اﻻﺳﺎﺳﻴﺔ اﻟﺜﻼث:‬ ‫‪net‬‬ ‫8002 ﻣﻊ ﺗﻮﺿﻴﺢ ﻞ ‪eywords‬‬ ‫ﻟﻞ‬ ‫ﻣ‬‫66‬
  • ‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ال ‪ .net‬اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺮاﺑﻊ‬‫ﻛﻞ ﻣﺎ ﻳﻬﻤﻚ ﻛﻤﺒﺮﻣﺞ ﺗﻄﺒﻴﻘﺎت ﻋﺎدي ان ﺗﻌﺮف ﻟﻤﻌﻠﻮﻣﺎﺗﻚ ﻓﺎﺋﺪة ال ‪ CTS‬ﻛﻨﻮع ﻣﻦ اﻟﻤﻌﺮﻓﺔ‬ ‫اﻟﻌﺎﻣﺔ ﻟﺒﻨﻴﺔ ‪ .net‬اﻻﺳﺎﺳﻴﺔ ، أﻣﺎ إذا ﻛﻨﺖ ﻗﺪ اﻋﺠﺒﺘﻚ اﻟﻔﻜﺮة وﺗﺮﻏﺐ ﻓﻲ اﻟﺘﻌﺮف ﻋﻠﻰ اﻟﻤﺰﻳﺪ ﻋﻦ‬ ‫‪ ،CTS‬ﻓﻴﻤﻜﻨﻚ اﻟﺒﺪء ﻣﻦ ﻫﺬا اﻟﺮاﺑﻂ:‬ ‫راﺑﻂ‬ ‫‪http://msdn2.microsoft.com/en-us/library/zcx1eb1e.aspx‬‬ ‫9. ‪Common Language Specification‬‬‫ﻛﻤﺎ ذﻛﺮﻧﺎ ﻓﻲ اﻟﻤﻮﺟﺰ اﻟﺴﺎﺑﻖ ، ال ‪ CLS‬ﻫﻲ ‪ subset‬ﻣﻦ ال ‪ CTS‬ﺗﺼﻒ اﻟﺤﺪ اﻷدﻧﻰ ﻣﻦ‬‫اﻟﻤﺘﻄﻠﺒﺎت اﻟﻼزﻣﺔ ﻟﻨﺴﺘﻄﻴﻊ اﻟﻘﻮل ان ﻫﺬه اﻟﻠﻐﺔ ﺗﻌﻤﻞ ﺗﺤﺖ ﺑﻴﺌﺔ ‪ ، .net‬وﺑﻤﻌﻨﻰ آﺧﺮ ، ﻓﺈن ﺑﻌﺾ‬‫ﻣﺤﺘﻮﻳﺎت ‪ CTS‬اﺧﺘﻴﺎرﻳﺔ ﺣﻴﺚ ﻳﻤﻜﻦ ان ﺗﺠﺪﻫﺎ ﻓﻲ ﺑﻌﺾ ﻟﻐﺎت ‪ .net‬وﻻ ﺗﺠﺪﻫﺎ ﻓﻲ اﻵﺧﺮ ، ﻣﺠﻤﻮﻋﺔ‬ ‫ﻣﻦ ﻣﺤﺘﻮﻳﺎت ‪ CTS‬ﺗﻢ ﺗﺠﻤﻴﻌﻬﺎ ﻓﻲ ‪ CLS‬ﻟﺘﻜﻮن اﺟﺒﺎرﻳﺔ ﻟﻜﻞ ﻟﻐﺔ ﺗﺴﺘﺨﺪم ﺑﻴﺌﺔ ‪ .net‬ﻟﻠﺘﻄﻮﻳﺮ.‬‫وﻳﺘﻢ اﻃﻼق ﻣﺼﻄﻠﺢ ‪ CLS Rules‬ﻋﻠﻰ ﻫﺬه اﻟﺸﺮوط اﻻﺟﺒﺎرﻳﺔ ، وﻳﺘﻢ ﺗﻮﺻﻴﻔﻬﺎ وﻻ ﺑﺪ ﻣﻦ ﺗﻄﺒﻴﻘﻬﺎ‬ ‫ﻟﻜﻞ ﻟﻐﺔ ﺗﺴﺘﺨﺪم ﺑﻴﺌﺔ ‪ .net‬ﻟﻠﺘﻄﻮﻳﺮ.‬‫ﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﻐﺎت #‪ C‬و ‪ ، VB.net‬ﻫﻨﺎك ﻣﺠﻤﻮﻋﺔ ﻛﺒﻴﺮة ﻣﻦ اﻟﺨﺼﺎﺋﺺ اﻟﺘﻲ ﻻ ﻳﻀﻤﻬﺎ ال ‪،CLS‬‬‫ﺑﺎﻣﻜﺎﻧﻚ ﻣﻌﺮﻓﺔ اذا ﻛﺎن اﻟﻜﻮد اﻟﺬي ﺗﺴﺘﺨﺪﻣﻪ ﻣﻮﺟﻮد ﺿﻤﻦ ال‪ CLS‬ام ﻻ ﻟﻤﺮاﻋﺎة ﻋﻤﻠﻬﺎ ﻋﻠﻰ ﺟﻤﻴﻊ‬‫أﻧﻈﻤﺔ اﻟﺘﺸﻐﻴﻞ ﻣﻦ ﺧﻼل اﺿﺎﻓﺔ اﻟﻜﻮد اﻟﺘﺎﻟﻲ أﻋﻠﻰ اﻟﺠﺰء اﻟﺬي ﺗﻮد أﻻ ﻳﺤﺘﻮي ﺳﻮى ﻋﻠﻰ أواﻣﺮ ﻣﻦ‬ ‫‪: CLS‬‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫])‪[assembly: System.CLSCompliant(true‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫>)‪<Assembly: System.CLSCompliant(True‬‬ ‫إذا ﻛﻨﺖ ﻣﻬﺘﻤﺎ ﺑﻤﻮﺿﻮع ال ‪ CLS‬ﻳﻤﻜﻨﻚ ﻣﻮاﺻﻠﺔ اﻟﻘﺮاءة ﻣﻦ ﻫﻨﺎ:‬ ‫ً‬ ‫راﺑﻂ‬ ‫‪http://msdn.microsoft.com/en-us/library/12a7a7h3.aspx‬‬‫76‬
  • ‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ال ‪ .n‬اﻟﺮﺋﻴﺴﻴﺔ‬ ‫‪net‬‬ ‫ﻢ‬ ‫ ‬ ‫اﻟﺮاﺑﻊ‬ ‫اﻟﺒﺎب ﻊ‬ ‫‪Co mon La‬‬ ‫‪omm‬‬ ‫01. ‪RunTime‬‬ ‫‪anguage R‬‬‫د ال ‪.net‬‬ ‫ت اﻟﻤﻄﻠﻮﺑﺔ ﻟﻴﻌﻤﻞ ﻛﻮد‬ ‫ﺔ اﻟﻤﻌﻠﻮﻣﺎت‬ ‫ﺎ ﺳﺎﺑﻘﺎ ، ﺈن ال ‪ CLR‬ﺗﻀﻢ ﻛﺎﻓﺔ‬ ‫ً ﻓﺈ‬ ‫ﻛﻤﺎ ذﻛﺮﻧﺎ‬ ‫ﻛ‬‫ﻳﺐ اﻟﻤﺜﺎل،‬ ‫ﺑﺔ اﻟﻜﻮد ﺻﻠﻲ، وﻟﺘﻘﺮﻳ‬ ‫اﻷﺻ‬ ‫اﻟﺨﺎص ﺑﻚ ﻋﻠﻰ ﺠﻬﺎز ﺑﻐﺾ اﻟﻨﻈﺮ ﻋﻦ ﻟﻠﻐﺔ اﻟﺘﻲ ﻤﺖ ﺑﻬﺎ ﻛﺘﺎﺑ‬ ‫ﺗﻤ‬ ‫اﻟ‬ ‫اﻟﺠ‬ ‫06‪ msvbvm‬ﻋﻠﻰ اﻟﺠﻬ‬‫ﻬﺎز ﻟﻴﻌﻤﻞ‬ ‫‪m‬‬ ‫ﻚ ﻣﻀﻄﺮ ﻟﻮﺟﻮد ‪0.dll‬‬ ‫ﻟ‬ ‫ﺖ ﻣﺒﺮﻣﺞ ﻓﻴﺠﻮال ﺴﻚ ﻓﺈﻧﻚ‬ ‫ﺑﻴﺴ‬ ‫إذا ﻛﻨﺖ‬‫ﺴﻴﺔ ، اﻣﺎ ﻮ ﻛﻨﺖ ﻣﺒﺮﻣﺞ ﺟﺎﻓﺎ ﻧﻚ ﺗﺤﺘﺎج‬ ‫ﻓﺈﻧ‬ ‫ﻟﻮ‬ ‫ﻚ اﻟﻤﺼﻤﻢ ﺑﺎﻟﻔﻴﺠﻮال ﺑﻴﺴﻚ ﻷدوات اﻟﺮﺋﻴﺴ‬ ‫وﺑﺎﻷ‬ ‫ﺑﺮﻧﺎﻣﺠﻚ‬‫ﻬﺎز اﻟﺬي ﻴﻌﻤﻞ ﻋﻠﻴﻪ ﺗﻄﺒﻴﻘﻚ .. وﺑﻨﻔﺲ ﻟﻄﺮﻳﻘﺔ ، ﺈن ال ‪ CLR‬ﻫﻮ اﻟﻤﻠﻒ‬ ‫ﻓﺈ‬ ‫اﻟ‬ ‫..‬ ‫ﺳﻴ‬ ‫إﻟﻰ ‪ JV‬ﻋﻠﻰ اﻟﺠﻬ‬ ‫‪VM‬‬ ‫ﺟﻪ ﻟﻴﻌﻤﻞ ﻄﺒﻴﻘﻚ ﺼﻤﻢ ﺗﺤﺖ ﻴﺌﺔ ‪ .net‬ﻰ اي ﺟﻬﺎز ﻛﻮﻣﺒﻴﻮﺗﺮ.‬ ‫ﻛ‬ ‫ﻋﻠﻰ‬ ‫ﺑﻴ‬ ‫اﻟﻤﺼ‬ ‫ﺗﻄ‬ ‫اﻟﻮﺣﻴﺪ اﻟﺬي ﺗﺤﺘﺎﺟ‬‫ﻓﻔﻲ ﻟﻢ ال ‪ .net‬ﺗﺤﺘﺎج ﺟﻮد ﻣﻜﺘﺒﺔ ال ‪ CLR‬ﻤﺴﻤﺎه ‪ mscoree.dll‬ﺧﺘﺼﺎرًا ﻟـ ‪Microsof‬‬ ‫ ‪ft‬‬ ‫اﺧ‬ ‫اﻟﻤ‬ ‫ﻟﻮﺟ‬ ‫ﻋﺎﻟ‬‫‪ ،Common Object  R‬ﻣﻊ ﺑﺪء ﺮﻧﺎﻣﺠﻚ ﻣﻊ ﺑﺪاﻳﺔ ﺷﺎرة ﻣﻠﻒ‬ ‫اﺷ‬ ‫وﻣ‬ ‫ﺑﺮ‬ ‫ ‪n‬‬ ‫‪Execution  Engine‬‬ ‫‪Runtime  E‬‬‫ﻤﺒﻠﻲ وﻗﺮاءة ال ‪ ،metadata‬ﻳﻌﻤﻞ‬ ‫م ال ‪ CLR‬ﻌﻤﻞ ‪ Load‬ﻟﻤﻠﻒ اﻻﺳﻤ‬ ‫ﺑﻌ‬ ‫ﻲ إﻟﻰ ﻫﺬه ااﻟﻤﻜﺘﺒﺔ ﻳﻘﻮم‬ ‫اﻻﺳﻤﺒﻠﻲ‬ ‫ﻛﺮة اﻟﺤﻴﺔ، واﺧﻴﺮًا ﻮم ﺑﺘﺮﺟﻤﺔ اواﻣﺮ اﻟﺒﺮﻧﺎ‬‫ﺎﻣﺞ اﻟﻤﻮﺟﻮدة ﻓﻲ ‪CIL‬‬ ‫ﻳﻘﻮ‬ ‫‪ Load‬ﻳﻀﺎ ﻟﻞ ‪ Types‬ﻓﻲ اﻟﺬاﻛ‬ ‫اﻳ ً‬‫ﻘﺎ ﻟﻴﻤﻜﻨﻪ ﻟﺘﻨﻔﻴﺬ ﻋﻠﻰ ﺟﻬﺎزك ... ااﺧﻴﺮًا ﻳﺒﺪء‬ ‫ﺟ‬ ‫اﻟ‬ ‫إﻟﻰ ‪c instructio‬‬ ‫‪ platform specific‬ﻤﺎ اﺗﻔﻘﻨﺎ ﺳﺎﺑﻘً‬ ‫ﻛﻤ‬ ‫‪ons‬‬‫ال ‪ CLR‬ﺑﺘﻨﻔﻴﺬ ﻧﺎﻣﺠﻚ ، ﺧﻼل ﻋﻤﻞ ااﻟﺒﺮﻧﺎﻣﺞ ﻴﻘﻮم ال‪ CLR‬ﺑﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻔﺌﺎت ﻻﺳﺎﺳﻴﺔ ﻟﻞ‬ ‫اﻻ‬ ‫ﻣ‬ ‫ﺳﻴ‬ ‫وﺧ‬ ‫ﺑﺮﻧ‬ ‫ﻚ.‬ ‫‪ B‬إذا ﻛﻨﺖ ﺗﺴﺘﺨﺪﻣﻬﺎ ﻲ ﺑﺮﻧﺎﻣﺠﻚ‬ ‫ﻓﻲ‬ ‫ﺗ‬ ‫اﻟﻤ‬ ‫‪ .net‬ﻤﻮﺟﻮدة ﻓﻲ ‪Base Class‬‬ ‫ﻫﺬا ﺨﻄﻂ ﻣﻦ وﻳﻜﺒﺪﻳﺎ ﺿﺢ ﻣﺮاﺣﻞ ﻛﺘﺎﺑﺔ ﻮد ﺣﺘﻰ ﺤﻮﻳﻠﻪ إﻟﻰ ‪ native‬ﻛﻮد‬‫د وﻣﻦ ﺛﻢ‬ ‫‪e‬‬ ‫ﺗﺤ‬ ‫اﻟﻜﻮ‬ ‫ﻳﻮﺿ‬ ‫و‬ ‫اﻟﻤﺨ‬ ‫ﺗﻨﻔﻴﺬه:‬‫86‬
  • ‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ال ‪ .net‬اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺮاﺑﻊ‬ ‫اﻟﺼﻮرة 4. 2. ﻣﺮاﺣﻞ ﺗﺮﺟﻤﺔ اﻟﻜﻮد إﻟﻰ ‪ native‬ﻛﻮد ﻣﻔﻬﻮم ﻣﻦ اﻵﻟﺔ.‬ ‫وﻛﺎﻟﻌﺎدة، إذا ﻛﻨﺖ ﺗﺮﻏﺐ ﻓﻲ ﻣﻌﺮﻓﺔ اﻟﻤﺰﻳﺪ ﻳﻤﻜﻨﻚ اﻟﺒﺪء ﻣﻦ ﻫﻨﺎ:‬ ‫راﺑﻂ‬ ‫‪http://msdn2.microsoft.com/en-us/library/8bs2ecf4(VS.71).aspx‬‬ ‫11. اﺳﺘﺨﺪام ال ‪Object Browser‬‬ ‫ﻣﻦ ﻗﺎﺋﻤﺔ ‪ View‬اﺧﺘﺮ ‪ ، Object Browser‬ﺳﺘﻈﻬﺮ ﻟﻚ اﻟﺸﺎﺷﺔ اﻟﺘﺎﻟﻴﺔ:‬ ‫اﻟﺼﻮرة 4. 3. ال ‪ Object Browser‬ﻓﻲ اﻟﻔﺠﻮال ﺳﺘﻮدﻳﻮ‬‫96‬
  • ‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ال ‪ .net‬اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺮاﺑﻊ‬‫ﻣﻦ ﺧﻼل ﻫﺬه اﻷداة اﻟﻤﺘﻮﻓﺮة ﻣﻊ اﺻﺪارات ‪ Visual  Studio‬اﻟﻤﺨﺘﻠﻔﺔ ، ﺗﺴﺘﻄﻴﻊ اﺳﺘﻌﺮاض ﻛﺎﻓﺔ‬‫اﻟﻤﻜﺘﺒﺎت واﻟﻔﺌﺎت اﻟﺮﺋﻴﺴﻴﺔ ﻓﻲ. ‪ ،net‬وﺗﺴﺘﻄﻴﻊ ان ﺗﻌﺮف ﻣﻜﺎﻧﻪ وﻣﻠﻔﺎت اﻻﺳﻤﺒﻠﻲ اﻟﺘﻲ ﻳﺘﺒﻌﻬﺎ ،‬ ‫ﻃﺮﻳﻘﺔ اﺳﺘﺨﺪاﻣﻪ وﻧﺒﺬة ﻣﺼﻐﺮة ﻋﻦ ﻓﺎﺋﺪﺗﻪ.‬ ‫ﻟﻤﺰﻳﺪ ﻣﻦ اﻟﻤﻌﻠﻮﻣﺎت ﻋﻦ اي ﻣﻨﻬﺎ ﻳﻤﻜﻨﻚ اﻟﻠﺠﻮء إﻟﻰ ﻣﻜﺘﺒﺎت ‪ MSDN‬ﺳﻮاء اﻟﻤﻮﺟﻮدة ﻓﻲ ﻗﺎﺋﻤﺔ‬ ‫‪ ،Help‬او اﻟﻤﻮﺟﻮدة ﻋﻠﻰ اﻻﻧﺘﺮﻧﺖ ﻣﺒﺎﺷﺮة ﻓﻲ ﻣﻮﻗﻊ ‪.MSDN‬‬ ‫21. ﻣﺠﺎﻻت اﻷﺳﻤﺎء ‪Name Spaces‬‬‫ﻣﻦ ﺧﻼل اﻟﺪروس اﻟﺴﺎﺑﻘﺔ ، ﺗﺴﺘﻄﻴﻊ ان ﺗﻼﺣﻆ أن ‪ System‬ﻫﻲ ال ‪ namespace‬اﻟﺮﺋﻴﺴﻴﺔ‬ ‫اﻟﺘﻲ ﺗﺠﺪ ﺗﺸﺘﻖ ﻣﻨﻬﺎ أﻏﻠﺐ ال ‪ name spaces‬اﻷﺧﺮى.‬‫ﻫﻨﺎك ‪ name  space‬آﺧﺮ ﺑﺎﺳﻢ ‪ Microsoft‬ﺗﺠﺪ ﺗﺤﺘﻬﺎ اﻟﻌﺪﻳﺪ ﻣﻦ اﻟﻔﺌﺎت ﻣﺜﻞ‬‫‪ Microsoft.ManagementConsole‬وﺟﻤﻴﻊ اﻟﻔﺌﺎت اﻟﻤﺸﺘﻘﺔ ﻣﻦ ﻓﺌﺔ ‪ Micosoft‬ﻫﻲ‬ ‫ﺧﺎﺻﺔ ﻓﻘﻂ ﺑﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺧﺪﻣﺎت ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ وﻟﺬا ﻓﻬﻲ ﻻ ﺗﻌﻤﻞ ﺗﺤﺖ ال ‪ mono‬ﻣﺜﻼ.‬ ‫ً‬ ‫ﻻﺣﻘﺎً، ﺳﻴﻜﻮن ﻣﻦ اﻟﻮاﺿﺢ ان ﺗﻔﺴﺮ ال ‪ name space‬اﻟﺘﺎﻟﻲ :‬ ‫‪ System.Windows.Forms‬اﻧﻬﺎ ﺗﺤﺘﻮي ﻋﻠﻰ اﻟﻤﻬﺎم اﻟﺮﺋﻴﺴﻴﺔ اﻟﺘﻲ ﺗﺤﺘﺎﺟﻬﺎ ﻟﺒﻨﺎء ‪.Forms‬‬ ‫21. 1. اﺳﺘﻴﺮاد ﻣﺠﺎﻻت اﻷﺳﻤﺎء  ‬ ‫ﻳﻤﻜﻨﻚ اﺳﺘﻴﺮاد ﻣﺠﺎل اﻻﺳﻤﺎء اﻋﻠﻰ ﻣﻠﻒ اﻟﻜﻮد اﻟﺨﺎص ﺑﻚ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;‪using System.Data.SqlClient‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Imports System.Data.SqlClient‬‬‫إذا ﻗﻤﺖ ﻋﻠﻰ ﺳﺒﻴﻞ اﻟﻤﺜﺎل ﺑﺎﺳﺘﻴﺮاد ﻣﺠﺎل اﻻﺳﻤﺎء ﻛﻤﺎ اوﺿﺤﻨﺎ ، ﻓﻴﻤﻜﻨﻚ ﻛﺘﺎﺑﺔ اﻷﻣﺮ اﻟﺘﺎﻟﻲ‬ ‫ﻣﺒﺎﺷﺮة:‬‫07‬
  • ‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ال ‪ .net‬اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺮاﺑﻊ‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)(‪SqlConnection sql1 = new SqlConnection‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)(‪Dim sql1 As SqlConnection = New SqlConnection‬‬‫ﻓﻲ اﻟﻤﻘﺎﺑﻞ ، ﻟﻮ ﻟﻢ ﺗﻘﻢ ﺑﺘﻌﺮﻳﻔﻪ ﻓﻲ ﻣﺠﺎل اﻻﺳﻤﺎء ، ﻓﻔﻲ ﻫﺬه اﻟﺤﺎﻟﺔ اﻧﺖ ﻣﻀﻄﺮ ﻟﺪﺧﻮﻟﻪ ﺑﺎﻟﺘﺮﺗﻴﺐ‬ ‫ﻓﻲ ﻛﻞ ﻣﺮة ﺗﺴﺘﺨﺪﻣﻪ ﻓﻴﻬﺎ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪System.Data.SqlClient.SqlConnection sql1 = new‬‬ ‫;)(‪System.Data.SqlClient.SqlConnection‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Dim sql1 As System.Data.SqlClient.SqlConnection = New‬‬ ‫)(‪System.Data.SqlClient.SqlConnectionn‬‬ ‫31. اﺳﺘﺨﺪام اﻟﺒﺮﻧﺎﻣﺞ  ‪ildasm‬‬ ‫ﺿﻤﻦ اﻟﺒﺮاﻣﺞ اﻟﻤﻠﺤﻘﺔ ﻣﻊ  ‪Visual‬‬ ‫8002  ‪ Studio‬ﺗﺠﺪ ﻓﻲ اﻟﻐﺎﻟﺐ ﺑﺮﻧﺎﻣﺞ‬ ‫‪ ، ildasm‬ﻳﻤﻜﻨﻚ ﻫﺬا اﻟﺒﺮﻧﺎﻣﺞ ﻣﻦ اﻻﻃﻼع‬ ‫ﻋﻠﻰ اﻻﺳﻤﺒﻠﻲ اﻟﺨﺎص ﺑﺄي ﺑﺮﻧﺎﻣﺞ ﻗﻤﺖ‬ ‫ﺑﻌﻤﻠﻪ ﺑﺎﺳﺘﺨﺪام  ‪ ، .net‬اﻳﻀﺎ ﻳﻤﻜﻨﻚ ﻣﻦ‬ ‫ً‬ ‫رؤﻳﺔ ال ‪ CIL‬اﻟﺨﺎص ﺑﻬﺬا اﻟﺒﺮﻧﺎﻣﺞ ... ﻫﺬه‬ ‫ﺻﻮرة ﻣﻦ اﻟﺒﺮﻧﺎﻣﺞ :‬ ‫اﻟﺼﻮرة 4. 4. ﺑﺮﻧﺎﻣﺞ ال ‪  ildasm‬‬ ‫وﻳﻤﻜﻨﻚ ﺗﺤﻤﻴﻞ ﻧﺴﺨﺔ ﻣﻦ اﻟﺒﺮﻧﺎﻣﺞ‬ ‫وﻣﻌﺮﻓﺔ اﻟﻤﺰﻳﺪ ﻋﻨﻪ ﻣﻦ ﻫﻨﺎ :‬‫17‬
  • ‫ﻣﻔﺎﻫﻴﻢ ﺑﻴﺌﺔ ال ‪ .net‬اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺮاﺑﻊ‬ ‫راﺑﻂ‬ ‫‪http://msdn.microsoft.com/en-us/library/aa730858.aspx‬‬ ‫ ‬‫41. ﻫﻞ ﺗﺒﺤﺚ ﻋﻦ ‪ Open Source .net‬؟‬ ‫راﺑﻂ‬ ‫‪http://www.mono-project.com‬‬‫او ‪ Mono  project‬ﻫﻮ اﺷﻬﺮ ال ‪ Projects‬اﻟﺘﻲ ﺗﺘﻴﺢ ﻟﻞ ‪ CIL‬اﻟﻌﻤﻞ ﻋﻠﻰ ﺗﻮزﻳﻌﺎت ﻟﻴﻨﻮﻛﺲ‬ ‫اﻟﻤﺨﺘﻠﻔﺔ.‬‫ﻫﻨﺎك ﻣﺸﺮوع آﺧﺮ ﺑﺎﺳﻢ ‪ Portable.NET‬ﻳﻤﻜﻦ ‪ CIL‬ﻣﻦ اﻟﻌﻤﻞ ﻋﻠﻰ ﻣﻨﺼﺎت ﻣﺨﺘﻠﻔﺔ.‬ ‫ﺗﺠﺪ راﺑﻄﺎً ﻟﻠﻤﺸﺮوع اﻟﺜﺎﻧﻲ ﻫﻨﺎ :‬ ‫راﺑﻂ‬ ‫‪http://www.dotgnu.org‬‬ ‫ﻓﻲ أﺟﺰاء ﻗﺎدﻣﺔ ﻣﻦ اﻟﻜﺘﺎب ﺳﻨﺘﻌﺮف ﺑﺼﻮرة ﺗﻔﺼﻴﻠﻴﺔ أﻛﺜﺮ ﻋﻦ ‪.MONO‬‬‫27‬
  • 73
  • ‫اﻟﺒﺎب‬ ‫5‬ ‫اﻟﻮاﺟﻬﺔ اﻷﺳﺎﺳﻴﺔ‬ ‫ﻟﻠﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ‬‫47‬
  • 75
  • ‫ﻮال ﺳﺘﻮدﻳﻮ‬ ‫اﻟﻮاﺟﻬﺔ ﺳﺎﺳﻴﺔ ﻟﻠﻔﻴﺠﻮ‬ ‫اﻷﺳ‬ ‫ ‬ ‫اﻟﺒﺎب ﻣﺲ‬ ‫اﻟﺨﺎﻣ‬ ‫1. ﻛﻴﻒ أأﻛﺘﺐ اﻟﻜﻮد؟‬ ‫ﻛ‬ ‫ اﻹﺟﺎﺑﺔ اﻟﺘﻘﻠﻴﺪﻳﺔ ﻋﻠﻰ اﻟﺴﺆال ااﻟﺴﺎﺑﻖ ﻫﻲ ﻣﻦ ﺧﻼل 002 ‪ ،Visual Studio‬إﻻ أن ﻫﺬه ﺟﺎﺑﺔ ﻟﻴﺴﺖ‬ ‫اﻻﺟ‬ ‫80‬ ‫ﻣ‬ ‫ﻋ‬ ‫ﻮد ﻓﻘﻂ.  5.3  ‪mewrok‬‬ ‫‪net  fram‬‬ ‫ﻣﻜﺘﻤﻠﺔ ﺗﻤﺎﻣﺎ ، ﺎﻹﺟﺎﺑﺔ ﺼﺤﻴﺤﺔ ﻫﻲ اﻧﻪ وﻣﻦ ﺧﻼل وﺟﻮ‬ ‫اﻟﺼ‬ ‫ً ﻓﺎ‬ ‫ﺮ ﺗﻄﺒﻴﻘﺎت .8002 ‪ ، net‬ﺳﻨﺘﻌﺮف‬ ‫‪ Development Kit‬ﻋﻠﻰ أي ﻬﺎز ﻓﺈﻧﻚ ﺳﺘﻜﻮن ﻗﺎدرًا ﻋﻠﻰ ﺗﻄﻮﻳﺮ‬ ‫ﺳ‬ ‫ﺟﻬ‬ ‫ﺔ اﻻﺳﺎﺳﻴﺔ‬ ‫ﻓﻲ ﻫﺬا اﻟﺪرس ﻰ ﻋﺠﺎﻟﺔ ﻰ ﺑﻌﺾ ه اﻟﻄﺮق ﺒﻞ ان ﻧﻨﺘﻘﻞ ﻟﻠﺤﺪﻳﺚ ﻮل اﻟﻄﺮﻳﻘﺔ‬ ‫ﺣﻮ‬ ‫ﻗﺒ‬ ‫ﻫﺬه‬ ‫ﻋﻠﻰ‬ ‫ﻋﻠﻰ‬ ‫اﻟﺘﻲ ﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﻣﻦ ﺧﻼل 002 ‪Studio‬‬ ‫‪ Visual S‬‬ ‫80‬ ‫ﺳﻨﺘ‬ ‫ﻣﺒﺪﺋﻴﺎ ﻳﻤﻜﻨﻚ ﻤﻴﻠﻬﺎ ﻣﻦ ﻫﺬا اﻟﺮاﺑﻂ‬ ‫ﺗﺤﻤ‬ ‫ًﻳ‬ ‫راﺑﻂ‬ ‫‪http://ms‬‬ ‫‪sdn2.microso‬‬ ‫‪oft.com/en-u‬‬ ‫‪us/library/zcx‬‬ ‫‪x1eb1e.aspx‬‬ ‫‪x‬‬‫‪  Visua‬‬ ‫‪al Studio 200  Com‬‬ ‫1. 1. ﺨﺪام  ‪d Prom‬‬ ‫‪08 mmand‬‬ ‫اﺳﺘﺨ ‪mpt‬‬ ‫ﻟﻮ اﻓﺘﺮﺿﻨﺎ اﻧﻨﺎ ﺳﻨﻘﻮم ﺑﺒﺮﻣﺠﺔ ‪ ، C‬ﻳﻤﻜﻨﻚ ﻣﻦ ﺧﻼﻟﻪ ﻛﺘﺎﺑﺔ اﻷﻣﺮ ?- ‪ csc‬اﻹﻃﻼع‬ ‫ﺮ‬ ‫ #‪C‬‬ ‫ﻟ‬ ‫ﺮ ﻛﺎﻓﻴﺔ ﺴﺘﻄﻴﻊ اﻟﺒﺪء ﺑﺘﺮﺟﻤﺔ ﻛﻮد #‪ ،C‬ﻦ ﺳﺘﺘﻀﻄﺮ‬ ‫ﻟﻜﻦ‬ ‫ﻛ‬ ‫ﻟﺘﺴ‬ ‫ﻮﺑﺔ، ﺳﺘﻜﻮن ﻫﺬه اﻷواﻣﺮ‬ ‫ﻋﻠﻰ واﻣﺮ اﻟﻤﻄﻠﻮ‬ ‫اﻷو‬ ‫ﺘﺎج ﻟﺘﺤﺪﻳﺪ اﻟﻤﺨﺎرج واﻻﺳﻤﺒﻠﻲ واﻟﻤﻠﻔﺎت .... اﻟﺦ ، ﻲ اﻟﻤﻘﺎﺑﻞ‬ ‫ﻓﻲ‬ ‫و‬ ‫و‬ ‫ﻟﻌﻤﻞ ﻛﻞ ﺷﻲء ﺪوﻳﺎً، ﺳﺘﺤﺘ‬ ‫ﻳﺪ‬ ‫ﻛ‬ ‫ﻳﺎ وﻫﻮ ﻣﺎ ﺘﻴﺢ ﻟﻚ ﻓﺮﺻﺔ ذﻫﺒﻴﺔ ﻟﻠﺘﺤﻜﻢ ﻓﻲ‬ ‫ﻟ‬ ‫ﻳﺘ‬ ‫ﺪ ﻣﻦ ﻣﻴﺰة ﻛﻮﻧﻚ ﻮم ﺑﻌﻤﻞ ﻞ ﺷﻲء ﻳﺪوﻳ‬ ‫ﻛﻞ‬ ‫ﺗﻘﻮ‬ ‫ﺳﺘﺴﺘﻔﻴﺪ‬ ‫ﻧﺎﻣﺞ ﻣﻦ ﻟﻒ إﻟﻰ ء.‬ ‫اﻟﻴﺎء‬ ‫اﻷﻟ‬ ‫ﻛﻞ ﻣﺎ ﻳﺘﻌﻠﻖ ﺑﺎﻟﺒﺮﻧ‬ ‫67‬
  • ‫ﻮال ﺳﺘﻮدﻳﻮ‬ ‫اﻟﻮاﺟﻬﺔ ﺳﺎﺳﻴﺔ ﻟﻠﻔﻴﺠﻮ‬ ‫اﻷﺳ‬ ‫ ‬ ‫اﻟﺒﺎب ﻣﺲ‬ ‫اﻟﺨﺎﻣ‬ ‫‪ ) Visual S‬ﺠﺪﻫﺎ ﻓﻲ ﻤﺠﻠﺪ  ‪tudio‬‬ ‫‪Visual St‬‬ ‫اﻟﻤ‬ ‫ﺗﺠ‬ ‫ة 5. 1. ال ‪08 Command Prompt‬‬ ‫002 ‪Studio‬‬ ‫‪t‬‬ ‫اﻟﺼﻮرة‬ ‫‪ V‬ﻓﻲ ﻗﺎﺋﻤﺔ ااﻟﺒﺮاﻣﺞ(‬ ‫8002- < ‪dio Tools‬‬ ‫‪Visual Stud‬‬ ‫ <‬ ‫ﻨﻚ ﻋﻤﻞ ‪ Compil‬ي ﻣﻠﻒ ‪ cs‬ﺮﻏﺐ ﺑﻪ ﺸﻜﻞ اﻟﺘﺎﻟﻲ :‬ ‫ﺑﺎﻟﺸ‬ ‫ﺗﺮ‬ ‫ﻻي‬ ‫‪le‬‬ ‫ﺑﺄﺑﺴﻂ ﺻﻮرة ، ﻳﻤﻜﻨ‬ ‫ﺻ‬‫‪Command Prompt‬‬ ‫ ‪t‬‬ ‫ﻛﻮد‬‫‪csc Fil‬‬ ‫‪le.cs‬‬ ‫ﻮﻳﻠﻪ إﻟﻰ ﻒ ‪:dll‬‬ ‫ﻣﻠﻒ‬ ‫أو ﻟﺘﺤﻮ‬‫‪Command Prompt‬‬ ‫ ‪t‬‬ ‫ﻛﻮد‬‫‪csc /ta‬‬ ‫‪arget:lib‬‬ ‫‪brary Fil‬‬ ‫‪le.cs‬‬ ‫ﻮﻳﻠﻪ إﻟﻰ ﻒ ‪:exe‬‬ ‫ﻣﻠﻒ‬ ‫أو ﻟﺘﺤﻮ‬‫‪Command Prompt‬‬ ‫ ‪t‬‬ ‫ﻛﻮد‬‫‪csc /ou‬‬ ‫‪ut:My.exe File.cs‬‬ ‫‪e‬‬ ‫‪ Co‬ﻟﻌﺪة ﻔﺎت ﻣﻮﺟﻮدة ﻓﻲ ﻣﺠﻠﺪ واﺣﺪ :‬ ‫و‬ ‫ﻣﻠﻔ‬ ‫اﺧﻴﺮًا ﻌﻤﻞ ‪ompile‬‬ ‫ﻟﻌ‬‫77‬
  • ‫اﻟﻮاﺟﻬﺔ اﻷﺳﺎﺳﻴﺔ ﻟﻠﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺨﺎﻣﺲ‬ ‫ ‪Command Prompt‬‬ ‫ﻛﻮد‬ ‫‪csc /define:DEBUG /optimize /out:File2.exe *.cs‬‬ ‫ﻳﻤﻜﻨﻚ ﻣﻌﺮﻓﺔ اﻟﻤﺰﻳﺪ اﺑﺘﺪاء ﻣﻦ ﻫﺬا اﻟﺮاﺑﻂ ﻣﻦ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ:‬ ‫راﺑﻂ‬ ‫‪http://msdn2.microsoft.com/en-us/library/78f4aasd(VS.80).aspx‬‬ ‫1. 2. اﺳﺘﺨﺪام ال ‪  TextPad‬‬‫ﺑﺮﻧﺎﻣﺞ ﻗﺎﺑﻞ ﻻﻋﺎدة اﻟﺘﻬﻴﺌﺔ، ﺑﻤﻌﻨﻰ اﻧﻪ ﻗﺎﺑﻞ ﻟﻠﻌﻤﻞ ﻋﻠﻰ اي ﺷﻲء وﻗﺎﺑﻞ ﻟﻠﺘﺨﺼﻴﺺ ﻟﻴﻌﻤﻞ ﻛﺄي‬‫ﺷﻲء، ﻧﺴﺨﺔ ﻣﻄﻮرة ﻣﻦ ال ‪ Notepad‬ﻗﺎﺑﻠﻪ ﻟﻠﺘﻄﻮﻳﺮ واﻟﺘﻌﺪﻳﻞ ، ﻳﻤﻜﻨﻚ اﺳﺘﺨﺪاﻣﻬﺎ ﻛﺎداة ﺗﺤﺮﻳﺮ‬‫ﻻي ﻟﻐﺔ ﺑﺮﻣﺠﺔاو ﺻﻔﺤﺎت وﻳﺐ او‪ HTML‬او ﺣﺘﻰ اﺳﻤﺒﻠﻲ ... ﻳﻤﻜﻨﻚ اﺳﺘﺨﺪاﻣﻬﺎ ﻟﺘﺮﻳﺐ اوراﻗﻚ‬ ‫... ﻷي ﺷﻲء ﻣﺎ دﻣﺖ ﺗﺴﺘﻄﻴﻊ ﺗﻌﺪﻳﻞ اﻟﺨﺼﺎﺋﺺ اﻟﻤﻄﻠﻮﺑﺔ.‬‫87‬
  • ‫اﻟﺼﻮرة 5. 2. ﺑﺮﻧﺎﻣﺞ ال ‪.TextPad‬‬ ‫واﺣﺪة ﻣﻦ ﺿﻤﻦ ﺧﺼﺎﺋﺺ ال ‪ TextPad‬اﻧﻚ ﺗﺴﺘﻄﻴﻊ اﺿﺎﻓﺔ ﻣﻠﻒ ﻟﺘﻌﺮﻳﻒ ﻟﻐﺔ #‪ C‬او  ‪VB.net‬‬‫ﻋﻠﻴﻪ، ﺑﻌﺪ اﺿﺎﻓﺔ اﻟﻤﻠﻒ ﺳﺘﺠﺪه ﻳﻘﻮم ﺑﺘﻠﻮﻳﻦ اﻷﻛﻮاد ﻛﻤﺎ ﻓﻲ‪ ،Visual  Studio‬ﻳﻤﻜﻨﻚ اﺿﺎﻓﺔ‬‫اﻣﺮ ‪ Compile‬ﺣﻴﺚ ﺗﺠﺪ ﻧﺴﺨﺔ ﻣﻦ ال ‪ RE‬اﻟﻤﺴﺘﺨﺪﻣﻪ ﻟﻠﻐﺔ ال #‪ ... C‬اﻟﺦ ، ﻟﻤﻌﺮﻓﺔ اﻟﻤﺰﻳﺪ ﺣﻮل‬ ‫ﻫﺬا اﻟﻤﻮﺿﻮع ﻳﻤﻜﻨﻚ ﺗﺘﺒﻊ اﻟﺮاﺑﻂ اﻟﺘﺎﻟﻲ واﻻﻧﻄﻼق ﻣﻨﻪ‬ ‫راﺑﻂ‬‫‪http://www.eggheadcafe.com/community/aspnet/2/10014016/textpad-and-c.aspx‬‬ ‫ﻛﻤﺎ ﺗﺴﺘﻄﻴﻊ ان ﺗﺠﺪ ﻣﻠﻔﺎت ﻛﻞ ﻟﻐﺎت اﻟﺒﺮﻣﺠﺔ او اﻟﻮﺻﻒ ﻟﺘﺮﻛﻴﺒﻬﺎ ﻋﻠﻰ ال ‪ Textpad‬ﻫﻨﺎ‬ ‫راﺑﻂ‬‫‪http://www.textpad.com/add-ons/cliplibs.html‬‬‫97‬
  • ‫اﻟﻮاﺟﻬﺔ اﻷﺳﺎﺳﻴﺔ ﻟﻠﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺨﺎﻣﺲ‬‫ﺑﺎﻣﻜﺎﻧﻚ اﻟﺘﻌﺪﻳﻞ ﻓﻲ ﻟﻐﺔ اﻟﺒﺮﻣﺠﺔ ﻧﻔﺴﻬﺎ إن اردت ﻋﻦ ﻃﺮﻳﻖ ﺗﻐﻴﻴﺮ ال‪ ،Reguler Expressions‬ﻟﻮ‬ ‫ﻗﻤﺖ ﺑﻮﺿﻊ ﻗﻮاﻧﻴﻦ ﻟﻠﻐﺔ اﻟﺒﺮﻣﺠﺔ ﺧﺎﺻﺘﻚ ﻓﺒﺎﺳﺘﻄﺎﻋﺘﻚ ﺗﻨﻔﻴﺬﻫﺎ ﻋﻠﻰ ال ‪ Textpad‬اﻳﻀﺎ.‬ ‫ً‬ ‫1. 3. اﺳﺘﺨﺪام ال ++‪  Notepad‬‬‫ﺗﻄﺒﻴﻖ ﻣﻤﺎﺛﻞ ، إﻻ اﻧﻪ ﻣﺠﺎﻧﻲ ﺑﺎﻟﻜﺎﻣﻞ ، ﻳﺘﻴﺢ ﻟﻚ ﺑﻌﺾ اﻟﺨﺼﺎﺋﺺ اﻟﺘﻲ رﺑﻤﺎ ﻻ ﺗﺘﻮﻓﺮ‬‫ﻟﻞ ‪ Textpad‬ﻣﺜﻞ ﺧﺎﺻﻴﺔ ال ‪ ، auto complete‬اﺿﻒ ﻟﺬﻟﻚ اﻧﻪ ﻣﻔﺘﻮح اﻟﻤﺼﺪر ﺑﻤﻌﻨﻰ اﻧﻪ ﻣﺘﺎح‬ ‫ﺑﺎﻟﺴﻮرس ﻛﻮد.‬ ‫اﻟﺼﻮرة 5. 2. ﺑﺮﻧﺎﻣﺞ ال ++‪.Notepad‬‬‫08‬
  • ‫اﻟﻮاﺟﻬﺔ اﻷﺳﺎﺳﻴﺔ ﻟﻠﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺨﺎﻣﺲ‬ ‫ﻳﻤﻜﻨﻚ ﻣﻌﺮﻓﺔ اﻟﻤﺰﻳﺪ ﻫﻨﺎ:‬ ‫راﺑﻂ‬ ‫‪http://notepad-plus.sourceforge.net/uk/about.php‬‬ ‫اﻟﺒﺮﻧﺎﻣﺞ ﻧﻔﺴﻪ ﺗﺠﺪه ﻫﻨﺎ ﻣﻊ ﻣﺮاﺣﻞ ﺗﻄﻮﻳﺮه ﺣﻴﺚ اﻧﻪ ‪ Open Source‬ﻋﻠﻰ ﻫﺬا اﻟﺮاﺑﻂ‬ ‫راﺑﻂ‬ ‫/‪http://sourceforge.net/projects/notepad-plus‬‬ ‫1. 4. ‪  SharpDevelop‬‬ ‫ﻣﻮﺟﻪ ﻟﺨﺪﻣﺔ ال #‪ ، C‬ﻳﺘﻤﻴﺰ ﺑﻮﺟﻮد واﺟﻬﺔ ﻟﻠﺘﺼﻤﻴﻢ اﻳﻀﺎ :‬ ‫ً‬ ‫اﻟﺼﻮرة 5. 3. ﺑﺮﻧﺎﻣﺞ ال ‪.SharpDevelop‬‬‫18‬
  • ‫اﻟﻮاﺟﻬﺔ اﻷﺳﺎﺳﻴﺔ ﻟﻠﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺨﺎﻣﺲ‬ ‫وﻫﻮ اﻻﻗﺮب ﻟﻠﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ ﻓﻲ اﻟﻤﻈﻬﺮ واﻷدوات ... ﻳﻤﻜﻨﻚ اﻟﺒﺪء ﺑﺎﻟﺘﻌﺮف ﻋﻠﻴﻪ ﻋﺒﺮ اﻟﺮاﺑﻂ‬ ‫اﻟﺘﺎﻟﻲ :‬ ‫راﺑﻂ‬ ‫/‪http://www.icsharpcode.net/OpenSource/SD‬‬ ‫2. اﻟﺒﺪاﻳﺔ ﻣﻊ ال 8002 ‪Visual Studio‬‬ ‫ال ‪ IDE‬اﻟﻤﻌﺘﻤﺪ ﻣﻦ ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ ﻟﻜﺘﺎﺑﺔ ال  #‪ C‬او ال ‪ VB.net‬ﻫﻮ ال ‪Studio Visual‬‬ ‫ﺑﺎﺻﺪارﺗﻴﻪ، ﺣﻴﺚ ﻧﺠﺪ اﻻﺻﺪار ‪ Proffessional‬وﻫﻮ ﻏﻴﺮ ﻣﺠﺎﻧﻲ ، اﻣﺎ ‪ Express‬واﻟﺬي ﻳﻜﻮن ﻣﻮﺟﻪ‬ ‫ﻟﻠﻐﺔ ﻣﻌﻴﻨﺔ ﻓﻬﻮ ﻣﺠﺎﻧﻲ ﻣﺜﻞ ‪. Visual C# 2008 Express‬‬ ‫ﺑﻌﺪ ﺗﺸﻐﻴﻞ اﻟﺒﺮﻧﺎﻣﺞ ﻷول ﻣﺮة ، وﺣﺴﺐ اﻟﻠﻐﺔ اﻟﻤﺴﺘﺨﺪﻣﺔ ﺳﺘﺠﺪ أول ﻣﺎ ﺗﺠﺪ ﺧﻴﺎرات اﻧﺸﺎء‬ ‫ﻣﺸﺮوع أو ‪ Web Site‬ﺟﺪﻳﺪ اﺿﺎﻓﺔ ﻟﻠﺘﻌﺪﻳﻞ ﻋﻠﻰ اﻟﻤﻮﺟﻮدﻳﻦ ، ﻣﻦ ﻗﺎﺋﻤﺔ ‪ New‬اﺧﺘﺮ ‪ Project‬ﻣﺜﻼ‬ ‫ً‬ ‫اﻟﺼﻮرة 5. 4. اﻧﺸﺎء ﻣﺸﺮوع ﺟﺪﻳﺪ ﻓﻲ ال 8002 ‪.Visual Studio‬‬ ‫28‬
  • ‫اﻟﻮاﺟﻬﺔ اﻷﺳﺎﺳﻴﺔ ﻟﻠﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺨﺎﻣﺲ‬‫اﺑﺴﻂ اﻷﻧﻮاع ﻫﻲ ‪ Console Application‬وﻫﻲ ﺷﺎﺷﺔ ﻟﻜﺘﺎﺑﺔ اﻟﻜﻮد ﺗﺤﺘﻮي ﻣﺒﺪﺋﻴﺎ ﻋﻠﻰ ‪ Class‬واﺣﺪ‬ ‫ً‬‫ﺑﺎﺳﻢ ‪ Main‬وال ‪ name space‬ﻫﻮ اﺳﻢ اﻟﻤﺸﺮوع اﻟﺬي اﺧﺘﺮﺗﻪ ... ﻓﻘﻂ. ﺑﺎﻗﻲ اﻻﻧﻮاع ﺳﻨﺘﻄﺮق ﻟﻬﺎ‬‫ﻓﻲ ﻣﺮاﺣﻞ ﻣﺨﺘﻠﻔﺔ ﻣﻦ اﻟﻜﺘﺎب ، ﺳﻨﺴﺘﺨﺪم ‪ Console‬ﻹﻧﻪ اﺑﺴﻂ اﻷﻧﻮاع وﻧﺴﺘﻄﻴﻊ ﻣﻦ ﺧﻼﻟﻪ ﻓﻬﻢ‬ ‫ﻛﺎﻣﻞ ﺑﻴﺌﺔ 8002 ‪ .net‬‬‫ﻋﻠﻰ ﻳﻤﻴﻦ اﻟﺸﺎﺷﺔ ﺗﺠﺪ ال ‪ ، Solution  Explorer‬ﺣﻴﺚ ﻳﻤﻜﻨﻚ اﻟﺘﻨﻘﻞ ﺑﻴﻦ ﻣﻜﻮﻧﺎت اﻟﻤﺸﺮوع‬‫اﻟﻤﺨﺘﻠﻔﺔ ، ﺗﺤﺖ ﺗﺒﻮﻳﺐ ‪ References‬ﺗﺠﺪ اﻟﻤﻜﻮﻧﺎت اﻟﻤﻀﺎﻓﺔ إﻟﻰ ﺑﺮﻧﺎﻣﺠﻚ ، ﺗﺴﺘﻄﻴﻊ اﺿﺎﻓﺔ‬ ‫ﻣﻜﻮﻧﺎت ﺟﺪﻳﺪة ﻣﻦ ﺧﻼل اﻟﻀﻐﻂ ﻋﻠﻰ ‪ References‬ﺑﺰر اﻟﻔﺄرة اﻷﻳﻤﻦ واﺿﻐﻂ ‪  .Add‬‬‫اﺳﻔﻞ ﻫﺬا اﻟﺘﺒﻮﻳﺐ ﻳﻤﻜﻨﻚ اﻟﺘﺒﺪﻳﻞ ﺑﻴﻦ اﺳﻠﻮب اﻟﻌﺮض ، ﺗﺴﺘﻄﻴﻊ اﺧﺘﻴﺎر ﻋﺮض ‪ Class‬ﺑﺤﻴﺚ ﻳﺘﻢ‬ ‫ﻋﺮض ﺟﻤﻴﻊ ال ‪ Classes‬اﻟﻤﻮﺟﻮدة ﻓﻲ ﻣﺸﺮوﻋﻚ واﻟﻄﺮق واﻟﺨﺼﺎﺋﺺ ﻓﻴﻬﺎ :‬‫ﺗﺤﺖ ﺗﺒﻮﻳﺐ ‪ Properties‬ﺗﺠﺪ ﺧﺼﺎﺋﺺ اﻟﻤﺸﺮوع ، ﻟﻮ ﻗﻤﺖ ﺑﺎﻟﻀﻐﻂ ﻋﻠﻴﻪ ﻣﺮﺗﻴﻦ ﺳﺘﺠﺪ ﺧﺼﺎﺋﺺ‬ ‫اﻟﻤﺸﺮوع ﺣﻴﺚ ﻳﻤﻜﻨﻚ اﻟﺨﺼﺎﺋﺺ اﻻﺳﺎﺳﻴﺔ ﻟﻤﺸﺮوﻋﻚ.‬‫ﻳﺘﻴﺢ ﻟﻚ ال ‪ .net‬اﻳﻀﺎ  ‪ Class Designer‬ﺣﻴﺚ ﻳﻤﻜﻦ رﺳﻢ اﻟﻔﺌﺎت ‪ Classes‬وﺗﺤﺪﻳﺪ اﻟﻌﻼﻗﺎت ﺑﻴﻨﻬﻤﺎ‬ ‫ً‬ ‫ﺑﺼﻮرة ﻣﺮﺋﻴﺔ وﻣﻦ ﺛﻢ ﻳﺘﻢ ﺗﻄﺒﻴﻘﻬﺎ ﻣﺒﺎﺷﺮة ﻣﻊ اﻟﺮواﺑﻂ ﺑﻴﻨﻬﻤﺎ ﻋﻠﻰ اﻟﻤﺸﺮوع ﻣﺒﺎﺷﺮة.‬ ‫2. 1. ﺑﺮﻧﺎﻣﺠﻚ اﻷول  ‬ ‫ﺳﻨﺠﺮب اول ﺑﺮﻧﺎﻣﺞ ﺑﺴﻴﻂ ﻟﻨﺎ ، ﻓﻲ ال ‪ function‬اﻟﻤﺴﻤﺎه ‪ Main‬ﺿﻊ اﻟﻜﻮد اﻟﺘﺎﻟﻲ:‬‫38‬
  • ‫اﻟﻮاﺟﻬﺔ اﻷﺳﺎﺳﻴﺔ ﻟﻠﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺨﺎﻣﺲ‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)"‪Console.Write("Hello World‬‬ ‫;)(‪Console.ReadKey‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)"‪Console.Write("Hello World‬‬ ‫)(‪Console.ReadKey‬‬‫ﻓﻘﻂ ... ﺗﻜﻮن ﻫﻜﺬا ﻗﺪ أﻧﺸﺄت ﺑﺮﻧﺎﻣﺠﻚ اﻷول ﻓﻲ 8002 ‪ . Visual Studio‬ﺟﺮب اﻟﻀﻐﻂ ﻋﻠﻰ زر‬ ‫5‪ F‬وﺟﺮب ﻧﺎﺗﺞ اﻟﺒﺮﻧﺎﻣﺞ.‬‫48‬
  • 85
  • ‫اﻟﺒﺎب‬ ‫6‬ ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬‫اﻟﺠﺰئ 10‬‫68‬
  • 87
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎدس‬ ‫ﻗﺒﻞ اﻻﺑﺤﺎر ﻓﻲ ﻋﺎﻟﻢ اﻟﻤﻜﻮﻧﺎت اﻻﺳﺎﺳﻴﺔ ﻟﻠﻐﺎت اﻟﺪوت ﻧﺖ ، ﺳﻨﺘﻌﺮف ﻋﻠﻰ ﺳﻮﻳﺔ ﻋﻠﻰ ﺑﻌﺾ ﺧﺼﺎﺋﺺ‬ ‫ال ‪ Console‬واﻟﺘﻲ ﺳﻨﺴﺘﺨﺪﻣﻬﺎ ﻻﺣﻘﺎ ﻓﻲ دروﺳﻨﺎ.‬ ‫ً‬ ‫ ‬ ‫1. ﺧﺼﺎﺋﺺ ‪Console‬‬‫ﺣﺘﻰ ﻫﺬه اﻟﻤﺮﺣﻠﺔ ﻣﻦ اﻟﺪروس ، ﻧﺴﺘﻄﻴﻊ اﻵن اﻟﻜﺘﺎﺑﺔ ﻋﻠﻰ اﻟﺸﺎﺷﺔ وﻋﻤﻞ دوال واﺳﺘﺪﻋﺎءﻫﺎ‬‫واﺳﺘﺮﺟﺎع ﻗﻴﻢ وﻃﺒﺎﻋﺘﻬﺎ ، ﻋﻨﺪ ﻫﺬه اﻟﻤﺮﺣﻠﺔ ﺳﻨﺄﺧﺬ راﺣﺔ ﻗﺼﻴﺮة ﻟﻠﺘﻌﺮف ﻋﻠﻰ اﻟﻌﻨﺎﺻﺮ اﻻﺳﺎﺳﻴﺔ‬ ‫ﻟﻠﺒﻴﺌﺔ ‪ Console‬اﻟﺘﻲ ﻧﻌﻤﻞ ﻋﻠﻴﻬﺎ ﺣﺎﻟﻴﺎ.‬ ‫ً‬ ‫اﻫﻢ اﻟﺪوال اﻟﺘﻲ ﺗﺤﺘﻮﻳﻬﺎ اﻟﻔﺌﺔ ‪ Console‬ﻫﻲ دوال اﻻدﺧﺎل واﻻﺧﺮاج ، وﻫﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫. ﻧﺺ ﻟﻜﺘﺎﺑﺔ //‬ ‫)‪Console.WriteLine(string‬‬ ‫. اﻹﻧﺘﻬﺎء ﺑﻌﺪ ﺟﺪﻳﺪ ﻟﺴﻄﺮ اﻻﻧﺘﻘﺎل ﺿﻐﻂ ﻣﻊ ﻧﺺ ﻟﻜﺘﺎﺑﺔ //‬ ‫;)(‪string x = Console.ReadLine‬‬ ‫اﻧﺘﺮ ﺿﻐﻂ ﻣﻊ اﻟﻘﺮاءة ﻣﻦ اﻻﻧﺘﻬﺎء وﻳﺘﻢ اﻟﻤﺴﺘﺨﺪم ﻣﻦ ﻣﺪﺧﻼت ﻟﻘﺮاءة //‬ ‫;)(‪int x = Console.ReadKey‬‬ ‫إﻧﺘﺮ ﺿﻐﻂ ﻣﻊ اﻟﻘﺮاءة ﻋﻤﻠﻴﺔ اﻧﻬﺎء وﻳﺘﻢ ﻓﻘﻂ واﺣﺪ ﺣﺮف ﻗﺮاءة //‬ ‫;)(‪ConsoleKeyInfo r = Console.ReadKey‬‬ ‫زر ﻣﺜﻞ ﺷﻲء اي ادﺧﺎل ﻳﻤﻜﻦ ، إدﺧﺎﻟﻪ ﺑﻌﺪ اﻟﻘﺮاءة ﻣﻦ واﻻﻧﺘﻬﺎء ﻓﻘﻂ واﺣﺪ ﺣﺮف ﻗﺮاءة //‬ ‫ً اﻷﺳﻬﻢ‬ ‫ﺧﺎص ﻣﺘﻐﻴﺮ ﻓﻲ اﻟﻨﺎﺗﺞ ﺗﺨﺰﻳﻦ ﻳﺘﻢ ﻟﺬا ﻣﺜﻼ‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫. ﻧﺺ ﻟﻜﺘﺎﺑﺔ ‬ ‫)‪Console.WriteLine(String‬‬ ‫. اﻹﻧﺘﻬﺎء ﺑﻌﺪ ﺟﺪﻳﺪ ﻟﺴﻄﺮ اﻻﻧﺘﻘﺎل ﺿﻐﻂ ﻣﻊ ﻧﺺ ﻟﻜﺘﺎﺑﺔ ‬ ‫)(‪Dim x As String = Console.ReadLine‬‬ ‫اﻧﺘﺮ ﺿﻐﻂ ﻣﻊ اﻟﻘﺮاءة ﻣﻦ اﻻﻧﺘﻬﺎء وﻳﺘﻢ اﻟﻤﺴﺘﺨﺪم ﻣﻦ ﻣﺪﺧﻼت ﻟﻘﺮاءة ‬ ‫)(‪Dim x As Integer = Console.ReadKey‬‬ ‫إﻧﺘﺮ ﺿﻐﻂ ﻣﻊ اﻟﻘﺮاءة ﻋﻤﻠﻴﺔ اﻧﻬﺎء وﻳﺘﻢ ﻓﻘﻂ واﺣﺪ ﺣﺮف ﻗﺮاءة ‬ ‫)(‪Dim r As ConsoleKeyInfo = Console.ReadKey‬‬ ‫زر ﻣﺜﻞ ﺷﻲء اي ادﺧﺎل ﻳﻤﻜﻦ ، إدﺧﺎﻟﻪ ﺑﻌﺪ اﻟﻘﺮاءة ﻣﻦ واﻻﻧﺘﻬﺎء ﻓﻘﻂ واﺣﺪ ﺣﺮف ﻗﺮاءة ‬ ‫ً اﻷﺳﻬﻢ‬ ‫ﺧﺎص ﻣﺘﻐﻴﺮ ﻓﻲ اﻟﻨﺎﺗﺞ ﺗﺨﺰﻳﻦ ﻳﺘﻢ ﻟﺬا ﻣﺜﻼ‬‫88‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎدس‬‫و‬ ‫اﻟﻨﺺ‬ ‫ﻟﻠﻮن‬ ‫‪ForeGroundColor‬‬ ‫ﻣﺜﻞ‬ ‫اﻷﻟﻮان‬ ‫ﺑﻌﻤﻠﻴﺎت‬ ‫ﺧﺎﺻﺔ‬ ‫أﺧﺮى‬ ‫دوال‬‫اﻟﻔﺌﺔ‬ ‫ﻃﺮﻳﻖ‬ ‫ﻋﻦ‬ ‫اﻟﻠﻮن‬ ‫ﺗﻌﻴﻴﻦ‬ ‫ﺗﺴﺘﻄﻴﻊ‬ ‫اﻟﺨﻠﻔﻴﺔ،‬ ‫ﻟﻠﻮن‬ ‫‪BackgroundColor‬‬ ‫‪ ConsoleColor‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;‪Console.ForegroundColor = ConsoleColor.Yellow‬‬ ‫ﻣﻼﺣﻈﺔ‬ ‫ﻟﻮ ﻛﻨﺖ ﻣﺒﺮﻣﺞ ‪ VB.net‬ﻓﻠﻦ ﺗﺤﺘﺎج ﺳﻮى ﻻزاﻟﺔ اﻟـ ; ﻣﻦ آﺧﺮ اﻟﺠﻤﻠﺔ .‬ ‫ﻫﻨﺎك ﺧﺼﺎﺋﺺ أﺧﺮى ﻣﺜﻞ ‪ WindowWidth‬و ‪ Title‬وﺧﻼﻓﻬﺎ ﻟﺘﺤﺪﻳﺪ ﻣﻈﻬﺮ اﻟﻨﺎﻓﺬة.‬ ‫ﻧﻌﻮد ﻷﺣﺪ ﻣﻮاﺿﻴﻊ اﻟﻄﺒﺎﻋﺔ ، ﻟﻨﻔﺘﺮض اﻧﻨﺎ ﻧﺮﻳﺪ اﻟﻘﻴﺎم ﺑﻄﺒﺎﻋﺔ اﻟﻨﺺ اﻟﺘﺎﻟﻲ:‬ ‫اﻹﺳﻢ: اﻟﻤﺘﻐﻴﺮ ‪name‬‬ ‫اﻟﻌﻤﺮ: اﻟﻤﺘﻐﻴﺮ ‪Age‬‬ ‫ﻳﻤﻜﻨﻨﺎ اﻟﻘﻴﺎم ﺑﺬﻟﻚ ﻋﻦ ﻃﺮﻳﻖ ﻛﺘﺎﺑﺔ اﻟﻜﻮد اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)‪Console.Write("First Name: " + name + " - Age: " + age‬‬ ‫ﻫﻨﺎك ﻃﺮﻳﻘﺔ أﺧﺮى اﻓﻀﻞ اﻳﻀﺎ ، ﺑﺎﻟﻄﺮﻳﻘﺔ اﻟﺘﺎﻟﻴﺔ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)‪Console.Write("First Name: {0} - Age: {1}", name, age‬‬ ‫ﺑﻮاﺳﻄﺔ اﻟﻄﺮﻳﻘﺔ اﻟﺜﺎﻧﻴﺔ ، ﻳﻤﻜﻨﻚ ﻋﻤﻞ ‪ Format‬ﻟﻠﻨﺺ ﺑﺎﺳﺘﺨﺪام رﻣﻮز ‪ d‬ﻟﻼرﻗﺎم و ‪ e‬ﻟﻞ‬ ‫‪ exponential‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)99999 ,"}‪Console.WriteLine("E format: {0:E‬‬‫98‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎدس‬ ‫2. ﺗﻌﺮﻳﻒ اﻟﻤﺘﻐﻴﺮات‬ ‫ﻛﻤﺎ ذﻛﺮﻧﺎ ﻓﻲ اﻟﺪروس اﻟﺴﺎﺑﻘﺔ ﻳﻤﻜﻨﻨﺎ ﺗﻌﺮﻳﻒ اﻟﻤﺘﻐﻴﺮات ﺑﺎﻟﻄﺮﻳﻘﺔ اﻟﺘﺎﻟﻴﺔ‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;‪int x‬‬ ‫;‪string name‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Dim x As Integer‬‬ ‫‪Dim name As String‬‬‫وﺧﻼﻓﻪ ، وﻟﻜﻨﻚ ﺑﺎﻟﺘﺄﻛﻴﺪ ﺗﻼﺣﻆ وﺟﻮد اﻟﻜﻠﻤﺔ ‪ new‬ﻓﻲ ﻛﺜﻴﺮ ﻣﻦ ﺗﻌﺮﻳﻒ اﻟﻤﺘﻐﻴﺮات ، ﻓﻤﺎ ﻫﻲ‬ ‫ﻣﻬﻤﺘﻬﺎ ؟‬‫ﺑﻌﺾ اﻻﻧﻮاع اﻟﺒﺴﻴﻄﺔ ﻳﻤﻜﻦ ﺗﻌﺮﻳﻔﻬﺎ ﺑﺎﺳﺘﺨﺪام ‪ new‬وﻫﻮ ﻣﺎ ﺳﻴﻌﻴﺪﻫﺎ إﻟﻰ ﺻﻮرﺗﻬﺎ اﻻﻓﺘﺮاﺿﻴﺔ‬‫اﻟﻤﻮﺟﻮدة ﻓﻲ اﻟﻤﻨﺸﺊ اﻟﺨﺎص ﺑﻬﺎ ، ﺣﻴﺚ ﻳﺘﻢ ﺗﺤﻮﻳﻞ اﻻﻧﻮاع اﻟﻤﻨﻄﻘﻴﺔ ‪ bool‬إﻟﻰ ‪ false‬واﻻرﻗﺎم‬ ‫إﻟﻰ ﺻﻔﺮ وﻛﺬﻟﻚ ﺑﺎﻗﻲ‬ ‫أﻧﻮاع اﻟﻤﺘﻐﻴﺮات.‬ ‫ﻟﻜﻦ ﻫﻨﺎك اﻧﻮاع اﺧﺮى ﻣﻦ‬ ‫اﻟﺒﻴﺎﻧﺎت ﻻ ﻳﻤﻜﻨﻚ اﺳﺘﺨﺪاﻣﻬﺎ‬ ‫ﻣﺜﻞ ال‬ ‫إﻻ ﺑﺎﺳﺘﺨﺪام‪new‬‬ ‫‪arraylists‬‬ ‫‪Objects‬و‬ ‫وﺧﻼﻓﻪ ﻣﻤﺎ ﺳﻨﺘﻌﺮف ﻋﻠﻴﻪ ﻓﻲ‬ ‫ﺣﻴﻨﻪ.‬ ‫ﻫﺬا ﻫﻮ ﺗﻘﺴﻴﻢ اﻻﻧﻮاع ﻓﻲ #‪ C‬‬ ‫اﻟﺼﻮرة 6. 1. اﻷﻧﻮاع ﻓﻲ ال‬ ‫#‪) C‬اﻟﺼﻮرة ﻣﻦ ﻛﺘﺎب‬ ‫ ‪ProCSharp  2008  and  .net‬‬ ‫ ‪(2008 platform‬‬‫09‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎدس‬‫ﺟﻤﻴﻊ اﻻﻧﻮاع اﻟﻤﺸﺘﻘﺔ ﻣﻦ ‪ object‬ﺗﻤﻠﻚ ﺑﺎﻟﻀﺮورة ﻃﺮﻗﻪ اﻻﺳﺎﺳﻴﺔ ﻣﺜﻞ ‪ Equals‬و‬ ‫‪ GetHashCode‬وﺧﻼﻓﻪ.‬‫أﻣﺎ اﻟﻄﺮق اﻻﺳﺎﺳﻴﺔ ﻟﻼﻧﻮاع اﻟﺮﻗﻤﻴﺔ ﻣﺜﻞ ‪ int‬و ‪ long‬ﻓﺘﺸﻤﻞ اﻟﺨﺼﺎﺋﺺ اﻻﺳﺎﺳﻴﺔ‬‫ﻣﺜﻞ ‪ MaxValue‬و ... ‪ MinValue‬ﻓﻴﻤﺎ ﻳﺤﺘﻮي ال ‪ char‬ﻋﻠﻰ ﺧﺼﺎﺋﺺ ﻣﺜﻞ ‪ IsDigit‬و‬ ‫‪ IsLetter‬ﻟﺘﺤﺪﻳﺪ ﻃﺒﻴﻌﺔ اﻟﻤﺪﺧﻼت.‬ ‫2. 1. أﻧﻮاع اﻟﻤﺘﻐﻴﺮات  ‬ ‫ﻓﻲ اي ﺟﺰء ﻣﻦ اﻟﺒﺮﻧﺎﻣﺞ داﺧﻞ ال ‪ Class‬ﻳﻤﻜﻨﻨﺎ ﺗﻌﺮﻳﻒ اﻟﻤﺘﻐﻴﺮات ﺣﺴﺐ اﻟﻨﻮع , ‪int‬‬ ‫‪ string‬ﻣﺜﻼً، وﻳﺘﻢ ﺗﺤﺪﻳﺪ ﻣﺪى اﻟﻮﺻﻮل ﻋﺒﺮ اﻟﻤﻜﺎن اﻟﻤﻮﺟﻮد ﻓﻴﻪ اﻟﺘﻌﺮﻳﻒ.‬‫ﻟﺘﻮﺿﻴﺢ ﻫﺬه اﻟﻨﻘﻄﺔ ﺳﻨﻔﺘﺮض ﻣﺘﻐﻴﺮ ﺗﻢ ﺗﻌﺮﻳﻔﺔ داﺧﻞ داﻟﺔ ، ﻫﺬا اﻟﻤﺘﻐﻴﺮ ﻟﻦ ﻳﺴﺘﻄﻴﻊ أﺣﺪ اﻟﻮﺻﻮل‬ ‫إﻟﻴﻪ إﻻ ﺧﻼل اﻟﺪاﻟﺔ ، وﻧﻔﺲ اﻷﻣﺮ ﻟﻮ ﺗﻢ ﺗﻌﺮﻳﻔﻪ داﺧﻞ ﺷﺮط أو داﺧﻞ ﺣﻠﻘﺔ ﺗﻜﺮارﻳﺔ ، أﻣﺎ ﻟﻮ ﻗﻤﻨﺎ‬‫ﺑﺘﻌﺮﻳﻒ ﻣﺘﻐﻴﺮ ﺧﺎرج اﻟﺪاﻟﺔ ) داﺧﻞ اﻟﻔﺌﺔ ‪ Class‬ﻣﺒﺎﺷﺮة ( ﻓﻴﻤﻜﻦ ﻻي داﻟﺔ اﻟﻮﺻﻮل إﻟﻴﻪ ﻣﺒﺎﺷﺮة ،‬ ‫ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﻳﺴﻤﻰ ‪. Member‬‬‫ﻟﺪﻳﻨﺎ ﻧﻮﻋﻴﻦ ﻣﻦ اﻟﻤﺘﻐﻴﺮات ، اﻟﻨﻮع اﻷول وﻫﻮ اﻟﺒﺴﻴﻂ ﻣﺜﻞ ‪ int‬و ‪ long‬وﺧﻼﻓﻪ ﺣﻴﺚ ﻳﺘﻢ ﻳﺸﻴﺮ‬‫اﺳﻢ اﻟﻤﺘﻐﻴﺮ ﻟﻤﻜﺎﻧﻪ ﻣﻦ اﻟﺬاﻛﺮة أﻣﺎ اﻟﻤﺮﻛﺐ ﻣﺜﻞ ‪ Array‬و‪ Struct‬ﻓﻴﺸﻴﺮ اﻟﻤﺘﻐﻴﺮ إﻟﻰ ﻣﻜﺎن‬‫ﺗﺴﺘﻄﻴﻊ ﻣﻨﻪ اﻻﺷﺎرة إﻟﻰ اﻟﻤﺘﻐﻴﺮ ﻓﻲ اﻟﺬاﻛﺮة ، ﺳﻨﺘﻌﺮف ﻋﻠﻰ ﻫﺬا اﻟﻤﻮﺿﻮع ﺑﺎﻟﺘﻔﺼﻴﻞ ﻓﻲ دروس‬ ‫ﻗﺎدﻣﺔ .‬ ‫2. 2. اﻟﺜﻮاﺑﺚ ‪  Constants‬‬‫ال ‪ Constant‬ﻫﻮ ﻧﻮع ﻣﻦ اﻟﺒﻴﺎﻧﺎت ﻻ ﻳﻤﻜﻦ ﺗﻐﻴﻴﺮ ﻗﻴﻤﺘﻪ اﺑﺪًا ، ﻟﺬا ﻳﻌﺮف ﺑﺎﺳﻢ ‪ Constant‬او اﻟﺜﺎﺑﺖ،‬ ‫ﻳﻤﻜﻦ ﻛﺘﺎﺑﺘﻪ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;001 = ‪public const int myNumber‬‬‫19‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎدس‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫001 = ‪Public Const myNumber As Integer‬‬‫ﻳﺘﻢ اﺳﺘﺨﺪام ﻫﺬه اﻟﺜﻮاﺑﺖ ﻛﻘﻴﻢ ﺛﺎﺑﺘﺔ ﻟﺒﻌﺾ اﻟﻤﻌﺎدﻻت ﻣﺜﻞ 41.3=‪ ، PI‬ﻣﺜﻞ رﻗﻢ ﻣﻌﻴﻦ ﺗﺴﺘﺨﺪﻣﻪ‬ ‫اﻟﺸﺮﻛﺔ ﻓﻲ اﻟﺤﺴﺎﺑﺎت ... اﻟﺦ . ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﻳﻔﻀﻞ ﺗﻌﺮﻳﻔﻪ ﻛﺜﺎﺑﺖ ﺑﺪﻻ ﻣﻦ ﺗﻌﺮﻳﻔﻪ ﻛﻤﺘﻐﻴﺮ‬ ‫ً‬ ‫ﻟﻀﻤﺎن اﺳﺘﺤﺎﻟﺔ ﺗﻐﻴﻴﺮه ﻓﻲ اي وﻗﺖ.‬ ‫ﻳﺘﻢ ﺗﻌﺮﻳﻒ اﻟﺜﺎﺑﺖ ﻣﺮة واﺣﺪة واﻋﻄﺎءه اﻟﻘﻴﻤﺔ ﻟﺤﻈﺔ ﺗﻌﺮﻳﻔﻪ ﻓﻘﻂ...‬ ‫2. 3. اﻟﻘﻴﻢ ﻟﻠﻘﺮاءة ﻓﻘﻂ ‪  Read Only Field‬‬ ‫ﻳﺘﻢ ﺗﻌﺮﻳﻔﻪ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬‫#‪C‬‬ ‫ﻛﻮد‬‫;41.3 = ‪public readonly double PI‬‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫41.3 = ‪Public ReadOnly PI As Double‬‬‫ﻳﻌﻤﻞ ﻣﺜﻞ ال ‪ Constant‬ﺗﻤﺎﻣﺎ ، ﻣﺎ ﻋﺪا اﻧﻪ ﻳﺨﺘﻠﻒ ﻓﻲ اﻣﻜﺎﻧﻴﺔ اﻋﻄﺎءه ﻗﻴﻤﺔ ﺑﻌﺪ اﻧﺸﺎءه ﻣﺮة واﺣﺪة‬ ‫ً‬ ‫دون ان ﺷﺮط اﻋﻄﺎءه اﻟﻘﻴﻤﺔ ﻓﻲ ﻧﻔﺲ ﻟﺤﻈﺔ اﻟﺘﻌﺮﻳﻒ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ :‬ ‫ً‬‫#‪C‬‬ ‫ﻛﻮد‬‫‪class MyMathClass‬‬‫{‬ ‫;‪public readonly double PI‬‬ ‫)(‪public MyMathClass‬‬ ‫{‬ ‫;41.3 = ‪PI‬‬ ‫}‬‫}‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫‪Class MyMathClass‬‬ ‫‪Public ReadOnly PI As Double‬‬ ‫)(‪Public Sub New‬‬ ‫41.3 = ‪PI‬‬ ‫‪End Sub‬‬‫‪End Class‬‬‫29‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎدس‬ ‫3. اﻟﻤﺘﻐﻴﺮات اﻟﻨﺼﻴﺔ ‪String‬‬ ‫ﺳﻨﺘﺤﺪث ﻓﻲ درﺳﻨﺎ ﻫﺬا ﺣﻮل ﻛﻞ ﻣﺎ ﻳﺘﻌﻠﻖ ﺑﺎﻟﻨﻮع ‪String‬‬ ‫3. 1. اﻟﺨﺼﺎﺋﺺ و اﻟﺪوال اﻷﺳﺎﺳﻴﺔ ﻟﻞ ‪  String‬‬ ‫اﻹﺳﺘﺨﺪام‬ ‫اﻟﺪاﻟﺔ أو اﻟﺨﺎﺻﻴﺔ‬ ‫‪ Length‬ﺗﺤﺪد ﻃﻮل اﻟﻨﺺ‬ ‫‪ Compare‬ﻟﻠﻤﻘﺎرﻧﺔ ﺑﻴﻦ ﻧﺼﻴﻦ‬ ‫‪ Contains‬ﻟﻠﺒﺤﺚ ﻋﻦ ﻧﺺ او ﺣﺮف ﺿﻤﻦ اﻟﻨﺺ‬ ‫‪ EndWith‬ﻟﻤﻌﺮﻓﺔ ﻓﻴﻤﺎ اذا ﻛﺎن اﻟﻨﺺ ﻳﺒﺪأ او ﻳﻨﺘﻬﻲ ﺑﺤﺮف او ﻧﺺ ﻣﻌﻴﻦ‬ ‫‪ IndexOf‬ﻟﻤﻌﺮﻓﺔ ﻣﻜﺎن وﺟﻮد ﺣﺮف او ﺑﺪاﻳﺔ ﻧﺺ ﻣﻌﻴﻦ ﺿﻤﻦ اﻟﻨﺺ ، ﺳﻮاء ﻣﻦ‬ ‫‪ LastIndexOf‬اﻟﺒﺪاﻳﺔ او ﻣﻦ اﻟﻨﻬﺎﻳﺔ‬ ‫‪ Remove‬ﺣﺬف ﺟﺰء ﻣﻌﻴﻦ ﻣﻦ اﻟﻨﺺ‬ ‫‪ Insert‬ادراج ﻧﺺ داﺧﻞ ال ‪String‬‬ ‫‪ Replace‬اﺳﺘﺒﺪال ﺟﺰء ﻣﻦ اﻟﻨﺺ‬ ‫‪ Split‬ﺗﻘﺴﻴﻢ اﻟﻨﺺ ﺣﺴﺐ ﺷﻲء ﻣﻌﻴﻦ إﻟﻰ ﻣﺼﻔﻮﻓﺔ ، ﻣﺜﻼ ﺗﻘﺴﻴﻢ اﻟﻨﺺ ﻣﻊ ﻛﻞ‬ ‫ً‬ ‫ﻋﻼﻣﺔ )-( إﻟﻰ ﻣﺼﻔﻮﻓﺔ ﺟﺪﻳﺪة‬ ‫‪ ToUpper‬ﻟﺘﺤﻮﻳﻞ ﺣﺎﻟﺔ اﻻﺣﺮف ﺑﻴﻦ ‪ capital‬و‪small‬‬ ‫اﻟﺠﺪول 6. 1. ﺧﺼﺎﺋﺺ و دوال اﻟﻔﺌﺔ ‪String‬‬‫39‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎدس‬ ‫3. 2. ﺗﻘﺴﻴﻢ اﻟﻨﺼﻮص‬‫ﻳﻤﻜﻨﻚ اﺳﺘﺨﺪام اﻟﺪاﻟﺔ ‪ Split‬ﻟﺘﻘﺴﻴﻢ ﻣﺤﺘﻮﻳﺎت اﻟﻨﺺ إﻟﻰ ﻋﻨﺎﺻﺮ ﻓﻲ ﻣﺼﻔﻮﻓﺔ، اﻟﻤﺜﺎل اﻟﺘﺎﻟﻲ‬ ‫ﻳﻮﺿﺢ ﺗﻘﺴﻴﻢ ﻧﺺ ﺑﻨﺎء ﻋﻠﻰ ﻋﻼﻣﺎت – ﻓﻲ وﺳﻄﻪ :‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)"-"(‪string[] newarray = g.Split‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)"-"(‪Dim newarray As String() = g.Split‬‬ ‫3. 3. دﻣـﺞ اﻟﻨﺼﻮص‬ ‫اﻟﻄﺮﻳﻘﺔ اﻻﺑﺴﻂ ﻟﺪﻣﺞ اﻟﻨﺼﻮص ﻫﻲ ﺑﺎﺳﺘﺨﺪام + ، او ﺑﺎﺳﺘﺨﺪام اﻟﺪاﻟﺔ ‪ Concate‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)2‪string s3 = String.Concat(s1, s‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)2‪Dim s3 As String = [String].Concat(s1, s‬‬ ‫3. 4. ﻣﻘﺎرﻧﺔ اﻟﻨﺼﻮص‬‫ﻳﻤﻜﻦ اﺳﺘﺨﺪام اﻟﻤﻌﺎﻣﻞ == ﻟﻤﻘﺎرﻧﺔ اﻟﻨﺼﻮص ﻓﻲ #‪ C‬أو = ﻓﻲ ‪ ، VB.net‬إﻻ اﻧﻪ ﻣﻦ اﻟﻤﻔﻀﻞ‬ ‫اﺳﺘﺨﺪام اﻟﺪاﻟﺔ ‪ Equals‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;))2‪Console.WriteLine(s1.Equals(s‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫))2‪Console.WriteLine(s1.Equals(s‬‬‫49‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎدس‬ ‫ ‬ ‫3. 5. ‪ – Escape Characters‬ﺳﻲ ﺷﺎرب ﻓﻘﻂ‬ ‫ﻓﻲ ﻛﻞ ﻟﻐﺎت ﻋﺎﺋﻠﺔ اﻟﺴﻲ ، ﺗﺠﺪ ﺣﺮف / ﻣﺤﺠﻮزًا ﻟﺒﻌﺾ اﻟﺤﺮوف اﻟﺨﺎﺻﺔ ﻣﺜﻞ ‪ /n‬ﻟﺴﻄﺮ ﺟﺪﻳﺪ و‬ ‫‪ /t‬ﻟﻌﻤﻞ ‪ Tab‬وﻏﻴﺮه ، ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)"‪Console.Write("My Name:/nAhmed Gamal‬‬‫ﻟﺬا إذا اردت ان ﺗﻜﺘﺐ / ﻓﻼ ﺑﺪ ﻟﻚ ان ﺗﻜﺘﺐ //، ﻫﻨﺎك ﺣﻞ آﺧﺮ وﻫﻮ اﺳﺘﺨﺪام ﻣﺎ ﻳﻌﺮف‬‫ﺑﺎﺳﻢ ‪ Verbatim Strings‬ﺣﻴﺚ ﻳﻤﻜﻨﻚ ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﻛﺘﺎﺑﺔ ﻧﺺ ﻋﺎدي ﺑﺪون اﻟﻘﻠﻖ ﻣﻦ ال ‪Escape‬‬ ‫‪ Characters‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)"‪Console.WriteLine(@"C:MyAppbinDebug‬‬ ‫ ‬ ‫3. 6. اﻟﺘﺤﻮﻳﻞ ﻣﻦ وإﻟﻰ ‪String‬‬‫ﺗﺤﺘﻮي ﻣﻌﻈﻢ اﻻﻧﻮاع اﻻﺳﺎﺳﻴﺔ ﻋﻠﻰ اﻟﺪاﻟﺔ ‪ Parse‬واﻟﺘﻲ ﺗﺤﻮل اﻟﻨﺺ إﻟﻰ ﻣﻨﺎﻇﺮه ،‬ ‫ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)"1"(‪int x = int.Parse‬‬ ‫;)"‪bool v = bool.Parse("True‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)"1"(‪Dim x As Integer = Integer.Parse‬‬ ‫)"‪Dim v As Boolean = Boolean.Parse("True‬‬ ‫ﻛﻤﺎ ﺗﺤﺘﻮي اﻳﻀﺎ ﻋﻠﻰ اﻟﺪاﻟﺔ ‪ ToString‬ﻟﺘﺤﻮﻳﻠﻬﺎ إﻟﻰ ﻧﺺ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ‬ ‫ً‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)(‪string x = m.ToString‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)(‪Dim x As String = m.ToString‬‬‫59‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎدس‬ ‫ ‬ ‫3. 7. ‪StringBuilder‬‬‫ﻋﻨﺪﻣﺎ ﻧﻘﻮم ﺑﺪﻣﺞ اﻟﻨﺼﻮص ، ﻳﻠﺠﺄ اﻟﻜﺜﻴﺮون ﻣﻨﺎ ﻻﺳﺘﺨﺪام اﻟﻤﻌﺎﻣﻞ + ﻓﻲ #‪ C‬أو اﻟﻤﻌﺎﻣﻞ &‬ ‫ﻓﻲ ‪ VB.net‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ - ﻣﺜﺎل اﺿﺎﻓﺔ اﻣﺘﺪاد اﻟﺒﺮﻳﺪ اﻹﻟﻜﺘﺮوﻧﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫:#‪// C‬‬ ‫;"‪Label1.Text = Text1.Text + "@hotmail.com‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫:‪VB.net‬‬ ‫"‪Label1.Text = Text1.Text + "@hotmail.com‬‬‫اﻟﻔﺌﺔ‬ ‫ﺑﺎﺳﺘﺨﺪام‬ ‫اﻟﻨﺼﻮص‬ ‫ﻟﺪﻣﺞ‬ ‫أﺧﺮى‬ ‫ﻃﺮﻳﻘﺔ‬ ‫ﻟﻨﺎ‬ ‫ﻗﺪﻣﺖ‬ ‫‪Visual  Studio‬‬ ‫أن‬ ‫إﻻ‬‫‪ ،StringBuilder‬ﻓﻲ ﻣﺠﺎل اﻷﺳﻤﺎء ‪ ،System.Text.StringBuilder‬ﻳﻤﻜﻦ‬ ‫اﺳﺘﺨﺪاﻣﻬﺎ ﻟﺪﻣﺞ اﻟﻨﺼﻮص ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫:#‪//C‬‬ ‫;)‪System.Text.StringBuilder mail = New System.Text.StringBuilder(Text1.Text‬‬ ‫;)"‪mail.Append("@hotmail.com‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫:‪VB.net‬‬ ‫)‪Dim mail As New System.Text.StringBuilder(Text1.Text‬‬ ‫)"‪mail.Append("@hotmail.com‬‬‫اﻟﻔﺎرق ﺑﻴﻦ اﻻﺛﻨﻴﻦ ﻳﻜﻤﻦ ﻓﻲ ان ‪ StringBuilder‬ﻳﻈﻞ ﻛﻤﺎ ﻫﻮ ﻣﻨﺬ ﻟﺤﻈﺔ اﻧﺸﺎءه، اﻣﺎ‬‫اﺳﺘﺨﺪام اﻟﻤﻌﺎﻣﻼت + أو & ﻓﻬﻮ ﻳﻘﻮم ﺑﻌﻤﻞ ‪ Object‬ﺟﺪﻳﺪ ﻣﻦ ال ‪ String‬ﻣﻊ ﻛﻞ ﻋﻤﻠﻴﺔ‬ ‫دﻣﺞ.‬‫واﻵن ﺳﻨﻔﺘﺮض ﻣﺜﺎل ‪ Loop‬ﺗﻘﻮم ﺑﺪﻣﺞ ﻋﺪد ﻣﻦ اﻟﻨﺼﻮص، وﺳﻨﺼﻮر اﻟﻤﻘﺎرﻧﺔ ﻣﺒﺎﺷﺮة ﻣﻦ‬‫ﻛﺘﺎب. ‪ ،net Gotachas‬ﺣﻴﺚ ﻗﺎم ﺑﻌﻤﻞ اﺧﺘﺒﺎر ﻟﻌﺪد ﻋﻤﻠﻴﺎت دﻣﺞ اﺑﺘﺪاء ﻣﻦ 01 ﻋﻤﻠﻴﺎت دﻣﺞ وﺣﺘﻰ‬‫0000001 ﻋﻤﻠﻴﺔ دﻣﺞ ، وﻗﺎم ﺑﻤﻘﺎرﻧﺔ اﻷداء ﺑﻴﻦ اﺳﺘﺨﺪام ‪ StringBuilder‬او اﺳﺘﺨﺪام‬ ‫ﻣﻌﺎﻣﻼت اﻟﺪﻣﺞ اﻟﺘﻘﻠﻴﺪﻳﺔ ، ﻣﻊ ذﻛﺮ زﻣﻦ اﻟﺘﻨﻔﻴﺬ ﺑﺎﻟﺜﺎﻧﻴﺔ ﻟﻜﻞ ﻣﻨﻬﻢ.‬‫69‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎدس‬ ‫اﻟﺼﻮرة 6. 2. ﻣﻘﺎرﻧﺔ ﻧﺘﺎﺋﺞ ﺳﺮﻋﺔ ﺗﻨﻔﻴﺬ اﻟﻨﺘﺎﺋﺞ ﺑﻴﻦ اﻟﻤﻌﺎﻣﻞ + و ال ‪StringBuilder‬‬ ‫ﻻ ﺗﻨﺴﻰ ان 339.2653 ﺛﺎﻧﻴﺔ ﺗﻌﻨﻲ 4.95 دﻗﻴﻘﺔ ﺗﻘﺮﻳﺒﺎ...‬ ‫ً‬ ‫واﻵن ... ﻫﻞ ﻣﺎ زﻟﺖ ﺗﺴﺘﺨﺪم & او + ﻟﺪﻣﺞ اﻟﻨﺼﻮص ؟؟؟‬‫ﺗﻮﻓﺮ اﻟﻔﺌﺔ ‪ StringBuilder‬اﻳﻀﺎ ﻋﻤﻠﻴﺎت اﺳﺘﺒﺪال ‪ Replace‬وادراج ‪ Insert‬وﺣﺬف‬ ‫ً‬‫‪ Remove‬وﻋﻤﻠﻴﺎت ﻧﺼﻮص أﺧﺮى ﻛﺜﻴﺮة ، ﻳﻤﻜﻨﻚ اﻻﻃﻼع ﻋﻠﻰ أوﺟﻪ ﻛﺜﻴﺮة ﻟﻠﻤﻘﺎرﻧﺔ ﻣﺪﻋﻮﻣﺔ‬ ‫ﺑﺎﻟﺮﺳﻮم اﻟﺒﻴﺎﻧﻴﺔ ﻣﻦ ﺧﻼل ﻫﺬا اﻟﺮاﺑﻂ ﻣﻦ ‪:Code Project‬‬ ‫راﺑﻂ‬ ‫‪http://www.codeproject.com/KB/cs/StringBuilder_vs_String.aspx‬‬‫79‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎدس‬ ‫4. اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﺘﺎرﻳﺦ و اﻟﻮﻗﺖ‬ ‫ﺗﺠﺪ ﺟﻤﻴﻊ ﻣﺎ ﻳﺘﻌﻠﻖ ﺑﺎﻟﺘﺎرﻳﺦ واﻟﻮﻗﺖ ﻓﻲ اﻟﻤﻜﺘﺒﺔ ‪ ، DateTime‬ﻓﻤﺜﻼ ﻻﺿﺎﻓﺔ ﺗﺎرﻳﺦ ﻣﻌﻴﻦ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)71 ,01 ,4002(‪DateTime dt = new DateTime‬‬ ‫ﻟﻄﺒﺎﻋﺔ اﻟﺘﺎرﻳﺦ اﻟﺤﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)‪Console.WriteLine(DateTime.Now‬‬ ‫ﻳﻤﻜﻦ اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻮﻗﺖ أﻳﻀﺎ ﺑﺎﺳﺘﺨﺪام ‪TimeSpan‬‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)0 ,03 ,4(‪TimeSpan ts = new TimeSpan‬‬ ‫اﻻﺿﺎﻓﺔ واﻟﻄﺮح ﺑﺎﺳﺘﺨﺪام اﻟﺪاول ‪ Add‬و ‪ Substract‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)))0 ,51 ,0(‪Console.WriteLine(ts.Subtract(new TimeSpan‬‬ ‫أو‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)2(‪dt = dt.AddMonths‬‬ ‫ﻣﻼﺣﻈﺔ‬ ‫ﻟﻮ ﻛﻨﺖ ﻣﺒﺮﻣﺞ ‪ VB.net‬ﻓﻠﻦ ﺗﺤﺘﺎج ﺳﻮى ﻻزاﻟﺔ اﻟـ ; ﻣﻦ آﺧﺮ اﻟﺠﻤﻠﺔ .‬ ‫5. اﻟﺘﺤﻮﻳﻞ ﺑﻴﻦ اﻟﻤﺘﻐﻴﺮات اﻟﻤﺨﺘﻠﻔﺔ‬ ‫ﺑﺪاﻳﺔ ، ﺗﻨﻘﺴﻢ اﻟﺘﺤﻮﻳﻼت ﺑﻴﻦ اﻟﻤﺘﻐﻴﺮات إﻟﻰ ﻧﻮﻋﻴﻦ رﺋﻴﺴﻴﻦ:‬ ‫• ‪Widening Conversions‬‬ ‫• ‪Narrowing Conversions‬‬‫89‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎدس‬ ‫5. 1. ‪Widening Conversions‬‬‫ﻳﻘﺼﺪ ﺑﻬﺬا اﻟﻨﻮع ﻣﻦ اﻟﺘﺤﻮﻳﻼت ﺗﻠﻚ اﻟﺘﺤﻮﻳﻼت اﻟﺘﻲ ﻻ ﻳﻤﻜﻦ ﻓﻴﻬﺎ ﺧﺴﺎرة اي ﻧﻮع ﻣﻦ اﻟﺒﻴﺎﻧﺎت،‬‫وﺗﺴﻤﻰ ﺑﺎﺳﻢ ‪ ، upward cast‬ﻣﺜﺎل ذﻟﻚ اﻟﺘﺤﻮﻳﻞ ﻣﻦ ‪ Short‬إﻟﻰ ‪ Integer‬ﻓﻲ اﻟﻤﺜﺎل اﻟﺘﺎﻟﻲ :‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;5 = ‪short x‬‬ ‫;)‪power(x‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫5 = ‪Dim x As Short‬‬ ‫)‪power(x‬‬ ‫وﻓﻲ اﻟﺪاﻟﺔ ‪power‬‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪int power(int number‬‬ ‫{‬ ‫;2 ^ ‪return number‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Private Function power(ByVal number As Integer) As Integer‬‬ ‫2 ‪Return number Xor‬‬ ‫‪End Function‬‬‫ﻟﻮ ﻻﺣﻈﺖ ﺳﺘﺠﺪ ان اﻟﺪاﻟﺔ ﺗﺴﺘﻘﺒﻞ ﺑﻴﺎﻧﺎت ﻣﻦ ﻧﻮع ‪ int‬ﻓﻴﻤﺎ ارﺳﻠﻨﺎ ﻟﻬﺎ ﺑﻴﺎﻧﺎت ﻣﻦ ﻧﻮع ‪،short‬‬‫ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﻟﻦ ﺗﻜﻮن ﻫﻨﺎك ﻣﺸﻜﻠﺔ ﻹن ﻣﺪى ال ‪ Integer‬اﻛﺒﺮ ﻣﻦ ﻣﺪى ال ‪،Short‬‬ ‫وﺑﺎﻟﺘﺎﻟﻲ ﻓﺈن اي ﻣﺪى ﻟﻞ ‪ Short‬ﻳﻘﻊ ﺿﻤﻦ ال ‪ Integer‬ﺑﻜﻞ ﺗﺄﻛﻴﺪ.‬ ‫5. 2. ‪Narrowing Conversions‬‬‫اﻟﺤﺎﻟﺔ اﻟﻌﻜﺴﻴﺔ ، اﻟﺘﺤﻮﻳﻞ ﻣﻦ اﻻﻛﺒﺮ إﻟﻰ اﻷﺻﻐﺮ ، ﻣﺜﻼ ﻟﻮ ﻛﺎن اﻟﻤﺘﻐﻴﺮان ﻣﻦ ﻧﻮع ‪Integer‬‬ ‫ً‬‫واﻟﻨﺎﺗﺞ ﻣﻦ ﻧﻮع ‪ ،Short‬ﺳﻴﻌﻤﻞ اﻻﻣﺮ ﺑﺼﻮرة ﺻﺤﻴﺤﺔ ﻟﻮ ﻛﺎن ﻣﺠﻤﻮع اﻟﺮﻗﻤﻴﻦ ‪Integer‬‬‫99‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎدس‬ ‫اﺻﻐﺮ ﻣﻦ اﻟﺤﺪ اﻷﻗﺼﻰ ﻟﻞ ‪ ،Short‬وﻟﻜﻦ ﻟﻮ اﻓﺘﺮﺿﻨﺎ ان ﻣﺠﻤﻮﻋﻬﻢ ﺗﺠﺎوز ﺣﺪود ﻣﺪى ال‬ ‫‪ Short‬ﻓﺈن ذﻟﻚ ﺳﻴﻨﺘﺞ ﻣﺸﻜﻠﺔ.‬ ‫ﻟﻬﺬا اﻟﺴﺒﺐ ، ﻳﻤﻨﻌﻚ اﻟﻤﺘﺮﺟﻢ ﻣﺒﺎﺷﺮة ﻣﻦ ﻛﺘﺎﺑﺔ ﻣﺜﻞ ﻫﺬا اﻟﻜﻮد وﻳﻌﻄﻴﻚ رﺳﺎﻟﺔ اﻟﺨﻄﺄ اﻟﺘﺎﻟﻴﺔ:‬‫.‪Cannot implicitly convert type int to short‬‬‫ﻟﻜﻦ ﻟﻮ رﻏﺒﻨﺎ ﻓﻲ اﻟﺘﺤﻮﻳﻞ رﻏﻤﺎ ﻋﻦ ﻫﺬه اﻟﻨﻘﻄﺔ ﺣﺘﻰ ﻟﻮ ﻧﺘﺞ ﻋﻦ ذﻟﻚ ﺿﻴﺎع ﺑﻌﺾ اﻟﺒﻴﺎﻧﺎت ، ﻓﻲ‬ ‫ً‬ ‫ﻫﺬه اﻟﺤﺎﻟﺔ ﻧﻠﺠﺄ ﻟﻤﺎ ﻳﺴﻤﻰ ﺑـ ‪Cast‬‬ ‫5. 3. ﻋﻤﻠﻴﺎت ال ‪Cast‬‬‫ﻻ ﺗﻨﻄﺒﻖ ﻋﻤﻠﻴﺎت ال ‪ cast‬ﻋﻠﻰ اﻟﺘﺤﻮﻳﻞ ﻣﻦ اﻛﺒﺮ ﻷﺻﻐﺮ ﻓﻘﻂ ، ﺑﻞ ﻳﻤﻜﻦ اﺳﺘﺨﺪاﻣﻬﺎ ﻓﻲ ﻛﻞ‬ ‫ﻋﻤﻠﻴﺎت اﻟﺘﺤﻮﻳﻞ ، اﺑﺴﻂ اﺳﺘﺨﺪام ﻟﻬﺎ ﻫﻮ ﻟﺘﺤﻮﻳﻞ ‪ Integer‬إﻟﻰ ‪ Short‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;01 = ‪int var‬‬ ‫;‪short var2 = (short)var‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫01 = ‪Dim var As Integer‬‬ ‫)‪Dim var2 As Short = CShort(var‬‬‫ﻓﻲ اﻟﻤﺜﺎل اﻟﺴﺎﺑﻖ ، ﻟﻮ ﻗﻤﻨﺎ ﺑﻄﺒﺎﻋﺔ ﻧﺘﻴﺠﺔ 2‪ var‬ﺳﻨﺠﺪ اﻧﻬﺎ 01 ، ﻟﻜﻦ ﻣﺎذا ﻟﻮ اﻓﺘﺮﺿﻨﺎ اﻟﻤﺜﺎل‬ ‫اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;000001 = ‪int var‬‬ ‫;‪short var2 = (short)var‬‬ ‫;)2‪Console.WriteLine(var‬‬ ‫;)(‪Console.ReadKey‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫000001 = ‪Dim var As Integer‬‬ ‫)‪Dim var2 As Short = CShort(var‬‬ ‫)2‪Console.WriteLine(var‬‬ ‫)(‪Console.ReadKey‬‬‫001‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎدس‬‫اﻟﻨﺘﻴﺠﺔ ﻟﻦ ﻳﻤﻜﻦ ﺗﻮﻗﻌﻬﺎ ﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﻌﻤﻴﻞ، وﻟﻜﻦ ﺑﺼﻮرة ﻣﻘﺮﺑﺔ ﻟﻚ ﻛﻤﺒﺮﻣﺞ ﺳﺘﻜﻮن اﻟﻨﺘﻴﺠﺔ ﻫﻲ -‬‫27013، ﺣﻴﺚ ﺳﻴﻘﻮم اﻟﻤﺘﺮﺟﻢ ﺑﻌﻜﺲ اﻹﺷﺎرات اﺑﺘﺪاء ﻣﻦ 86723 وﻣﻦ ﺛﻢ اﻧﻘﺎص رﻗﻢ ﻣﻊ ﻛﻞ‬‫زﻳﺎدة ﻋﻦ اﻟﺮﻗﻢ اﻟﺴﺎﺑﻖ، او ﺑﺎﺧﺘﺼﺎر ﻓﻬﻮ ﻳﻘﻮم ﺑﻄﺮح اﻟﺮﻗﻢ اﻟﻨﺎﺗﺞ ﻣﻦ اﻟﺤﺪ اﻻﻗﺼﻰ او اﻟﻤﺪى‬ ‫اﻻﻗﺼﻰ ﻟﻠﻨﻮع وﻫﻮ 76723.‬‫ﺑﺎﺳﺘﺨﺪام ﻫﺬا اﻟﻨﻮع ﻣﻦ اﻟﺘﺤﻮﻳﻼت ، ﻓﺈﻧﻪ ﻣﻦ اﻟﻤﻔﻀﻞ داﺋﻤﺎ اﺳﺘﺨﺪام ‪ Try Catsh‬واﻟﺘﻲ‬ ‫ً‬ ‫ﺳﻨﺘﻌﺮف ﻋﻠﻴﻬﺎ ﺑﺎﻟﺘﻔﺼﻴﻞ ﻓﻲ ﺟﺰء ﻗﺎدم ﻣﻦ اﻟﻜﺘﺎب.‬ ‫5. 4. اﻟﺘﺤﻮﻳﻞ ﺑﺎﺳﺘﺨﺪام ‪Convert‬‬ ‫ﻳﻤﻜﻦ اﻟﺘﺤﻮﻳﻞ ﺑﻴﻦ اي اﻧﻮاع ﻣﻦ اﻟﺒﻴﺎﻧﺎت ﺑﺎﺳﺘﺨﺪام اﻟﻔﺌﺔ ‪ Convert‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)‪myByte = Convert.ToByte(myInt‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)‪myByte = Convert.ToByte(myInt‬‬ ‫6. اﻟﺠﻤﻞ اﻟﺸﺮﻃﻴﺔ ﻓﻲ ‪  .net‬‬ ‫6. 1. أﺳﺎﺳﻴﺎت اﻟﺸﺮوط‬ ‫اﺑﺴﻂ اﻟﺠﻤﻞ اﻟﺸﺮﻃﻴﺔ ﻫﻲ ﺗﻠﻚ اﻟﺘﻲ ﺗﺴﺘﺨﺪم ‪ ،if else‬وﻃﺮﻳﻘﺔ ﻛﺘﺎﺑﺘﻬﺎ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)5 == ‪if (x‬‬ ‫;)"‪Console.WriteLine("five‬‬ ‫‪else‬‬ ‫;)"‪Console.WriteLine("notFive‬‬‫101‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎدس‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪If x = 5 Then‬‬ ‫)"‪Console.WriteLine("five‬‬ ‫‪Else‬‬ ‫)"‪Console.WriteLine("notFive‬‬ ‫‪End If‬‬‫ﻳﺘﻢ اﺳﺘﺨﺪام ﻛﺎﻓﺔ اﻧﻮاع اﻟﻤﻘﺎرﻧﺎت == و != و < و > ﻓﻲ اﻟﺠﻤﻞ اﻟﺸﺮﻃﻴﺔ ، ﻳﻤﻜﻦ دﻣﺞ اﻛﺜﺮ ﻣﻦ‬ ‫ﺷﺮط ﺑﺎﺳﺘﺨﺪام ‪ else if‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)09 > ‪if (x‬‬ ‫{‬ ‫;)"ﻣﻤﺘﺎز"(‪Console.WriteLine‬‬ ‫}‬ ‫)05 => ‪else if (x‬‬ ‫{‬ ‫;)"ﻧﺎﺟﺢ"(‪Console.WriteLine‬‬ ‫}‬ ‫‪else‬‬ ‫{‬ ‫;)"راﺳﺐ"(‪Console.WriteLine‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪If x > 90 Then‬‬ ‫)"ﻣﻤﺘﺎز"(‪Console.WriteLine‬‬ ‫‪ElseIf x >= 50 Then‬‬ ‫)"ﻧﺎﺟﺢ"(‪Console.WriteLine‬‬ ‫‪Else‬‬ ‫)"راﺳﺐ"(‪Console.WriteLine‬‬ ‫‪End If‬‬‫ﻳﺘﻢ ﺗﻄﺒﻴﻖ اﻟﺠﻤﻠﺔ اﻷوﻟﻰ ﻓﻲ ﺣﺎﻟﺔ ﻛﻮن اﻟﻨﺎﺗﺞ )‪ (True‬وإﻻ ﻳﺘﻢ ﺗﻨﻔﻴﺬ اﻟﺸﺮط اﻟﺜﺎﻧﻲ. اﻟﻨﻈﺎم‬ ‫اﻟﻘﺪﻳﻢ ﻟﻠﻐﺎت اﻟﺴﻲ واﻟﺘﻲ ﻛﺎﻧﺖ ﺗﻘﻀﻲ ﺑﺎﻧﻬﺎ ﺻﺤﻴﺔ ﻟﻮ ﻛﺎﻧﺖ ﺗﺴﺎوي 1 اﻳﻀﺎ ﻣﺜﻞ اﻟﺠﻤﻠﺔ اﻟﺘﺎﻟﻴﺔ:‬ ‫ً‬ ‫ﺗﻨﺒﻴﻪ‬ ‫ﻛﻨﺎ ﻗﺪ ﺗﻌﻮدﻧﺎ ﻣﻊ ﻋﺎﺋﻼت اﻟﻠﻐﺎت اﻟﺘﻲ ﺗﺘﺒﻊ ال ‪ C‬أن ﻧﻘﻮم ﺑﻜﺘﺎﺑﺔ ﺑﻌﺾ ﺷﺮوﻃﻨﺎ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ :‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪if (string.lenght‬‬ ‫ﺣﻴﺚ ﻳﻤﻜﻦ ﻟﻮ ﻛﺎن ﻟﻪ ﻗﻴﻤﺔ أن ﻳﺤﻘﻖ اﻟﺸﺮط = ‪ True‬ﻫﺬا اﻟﻨﻈﺎم ﻟﻢ ﻳﻌﺪ ﺻﺎﻟﺤﺎ ﻣﻊ اﻟﺴﻲ‬ ‫ً‬ ‫ﺷﺎرب ﺑﻌﺪ ...‬‫201‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎدس‬ ‫6. 2. دﻣﺞ اﻟﺸﺮوط‬‫ﻟﻌﻤﻞ اﻛﺜﺮ ﻣﻦ ﺷﺮط ﻳﻤﻜﻦ اﺳﺘﺨﺪام && أو ‪ And‬ﻟﻠﺪﻣﺞ ﺑﻴﻦ اﻟﺸﺮوط ﺑﺤﻴﺚ ﻳﺘﻢ ﺗﻨﻔﻴﺬ اﻟﺸﺮط ﻓﻲ‬‫ﺣﺎﻟﺔ ﻛﻮﻧﻬﻢ ﺟﻤﻴﻌﺎ ‪ True‬او اﺳﺘﺨﺪام ﻣﻌﺎﻣﻞ ‪ Or‬واﻟﺬي ﻳﺘﻢ ﻛﺘﺎﺑﺘﻪ ﻓﻲ ﺳﻲ ﺷﺎرب ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ ‫ً‬‫|| ﻓﻴﻌﻄﻲ ﻧﺘﻴﺠﺔ ﻓﻲ ﺣﺎﻟﺔ ﻛﻮن اي واﺣﺪ ﻣﻨﻬﻢ ﺻﺤﻴﺤﺎ ، اﻟﻤﻌﺎﻣﻞ ‪ Not‬واﻟﺬي ﻳﻜﺘﺐ ﺑﺎﻟﺸﻜﻞ‬ ‫ً‬‫اﻟﺘﺎﻟﻲ ! ﻓﻴﻌﻨﻲ ﻓﻲ ﺣﺎﻟﺔ ﻋﺪم )ﻧﻔﻲ( ﻻﺗﻨﺲ ﺗﺮﺗﻴﺐ اﻻﻗﻮاس ﻓﻲ ﻫﺬه اﻟﺤﺎﻻت ﺣﺘﻰ ﻻ ﺗﺘﺪاﺧﻞ‬ ‫اﻟﺸﺮوط ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫; ))"‪if ((x < 90 || x > 50) && (!name = "ahmed‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪If (x < 90 Or x > 50) And (Not Name = "ahmed") Then‬‬ ‫‪End If‬‬ ‫6. 3. ‪AndAlso‬‬‫ﻛﻨﺎ ﻣﻊ ﻋﺎدﺗﻨﺎ ﻓﻲ ﺑﺮﻣﺠﻴﺎت ‪ .net‬وﻓﻲ اﻟﻤﻌﺎﻣﻞ ‪ And‬ان ﻳﺘﻢ اﺧﺘﺒﺎر اﻟﺸﺮﻃﻴﻦ، وﻳﻜﻮن ﻟﻬﺎ ﺟﺪول‬ ‫اﻟﻨﺎﺗﺞ اﻟﺘﺎﻟﻲ :‬ ‫اﻟﻨﺎﺗﺞ‬ ‫ﻣﺪﺧﻞ 2‬ ‫ﻣﺪﺧﻞ 1‬ ‫‪True‬‬ ‫‪True‬‬ ‫‪True‬‬ ‫‪False‬‬ ‫‪True‬‬ ‫‪False‬‬ ‫‪False‬‬ ‫‪False‬‬ ‫‪True‬‬ ‫‪False‬‬ ‫‪False‬‬ ‫‪False‬‬ ‫اﻟﺠﺪول 6. 2. ﺟﺪول اﻟﺤﻘﻴﻘﺔ اﻟﺨﺎص ﺑﺎﻟﻤﻌﺎﻣﻞ ‪And‬‬‫وﺑﺮﻏﻢ اﻧﻚ ﺗﻠﺤﻆ ﺑﺈﻧﻪ ﻓﻲ ﺣﺎﻟﺔ ﻛﻮن اﻟﻄﺮف اﻷول ‪ false‬ﻓﺈن اﻟﺠﻤﻠﺔ ﻣﺒﺎﺷﺮة ﺳﺘﻜﻮن ﺧﺎﻃﺌﺔ،‬‫وﻻ ﻳﻮﺟﺪ أي داﻋﻲ ﻟﻠﺘﺤﻘﻖ ﻣﻦ اﻟﺠﺰء اﻟﺜﺎﻧﻲ ﻣﻦ اﻟﺸﺮط ، وﻟﻜﻦ ﻟﻼﺳﻒ ﻫﺬا ﻣﺎ ﻻ ﻳﻔﻌﻠﻪ اﻟﻤﻌﺎﻣﻞ‬ ‫‪.And‬‬‫ﻟﻜﻦ ﻣﻊ ‪ AndAlso‬ﻓﺎﻟﻤﻮﺿﻮع ﻣﺨﺘﻠﻒ ، ﻓﻬﻮ ﻳﻌﻴﺪ ‪ false‬ﻣﺒﺎﺷﺮة ﻓﻲ ﺣﺎﻟﺔ وﺟﻮد اي ﺗﻌﺒﻴﺮ‬ ‫ﺧﺎﻃﺊ .‬‫301‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬   ‫اﻟﺒﺎب اﻟﺴﺎدس‬ : ‫ﺑﺒﺴﺎﻃﺔ ﺷﺪﻳﺪة ، ﻟﻨﻔﺘﺮض اﻟﻜﻮد اﻟﺘﺎﻟﻲ‬ ‫ﻣﺎذا ﻧﺴﺘﻔﻴﺪ ﻣﻦ ذﻟﻚ ؟‬ C# ‫ﻛﻮد‬ if (id > 0 & SearchForID(id) > 0) { // do something } VB.NET ‫ﻛﻮد‬ If id > 0 And SearchForID(id) > 0 Then do something End If‫ اﺻﻐﺮ ﻣﻦ اﻟﺼﻔﺮ ، ﻓﺴﻴﺘﻢ ﺗﻨﻔﻴﺬ اﻣﺮ اﻟﺒﺤﺚ وﻫﻮ ﻣﺎ ﻳﻨﺘﺞ ﺑﻂء‬Id ‫ﻓﻲ اﻟﻮاﻗﻊ وﺣﺘﻰ ﻟﻮ ﻛﺎن ال‬ : ‫ﺷﺪﻳﺪ ﺟﺪًا ﻓﻲ اﻟﻤﻌﺎﻟﺠﺔ ﻻ ﻧﺤﺘﺎج إﻟﻴﻪ ، ﻳﺘﻢ اﻟﺘﻐﻠﺐ ﻋﻠﻴﻬﺎ ﺑﺎﻟﻄﺮﻳﻘﺔ اﻟﺘﻘﻠﻴﺪﻳﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ if (id > 0) { if (SearchForID(id) > 0) { // do something } } VB.NET ‫ﻛﻮد‬ If id > 0 Then If SearchForID(id) > 0 Then do something End If End If : AndAlso ‫وﺑﻄﺮﻳﻘﺔ‬ C# ‫ﻛﻮد‬ if (id > 0 && SearchForID(id) > 0) { // do something } VB.NET ‫ﻛﻮد‬ If id > 0 AndAlso SearchForID(id) > 0 Then do something End If104
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎدس‬ ‫6. 4. ‪OrElse‬‬ ‫ﻛﻤﺎ ﻫﻮ اﻟﺤﺎل ﻣﻊ ‪ ، And‬ﻳﺘﻜﺮر اﻷﻣﺮ ﻣﻊ اﻟﻤﻌﺎﻣﻞ ‪ Or‬واﻟﺬي ﻟﻪ ﺟﺪول اﻟﻨﺘﺎﺋﺞ اﻟﺘﺎﻟﻲ :‬ ‫اﻟﻨﺎﺗﺞ‬ ‫ﻣﺪﺧﻞ 2‬ ‫ﻣﺪﺧﻞ 1‬ ‫‪True‬‬ ‫‪True‬‬ ‫‪True‬‬ ‫‪True‬‬ ‫‪True‬‬ ‫‪False‬‬ ‫‪True‬‬ ‫‪False‬‬ ‫‪True‬‬ ‫‪False‬‬ ‫‪False‬‬ ‫‪False‬‬ ‫اﻟﺠﺪول 6. 2. ﺟﺪول اﻟﺤﻘﻴﻘﺔ اﻟﺨﺎص ﺑﺎﻟﻤﻌﺎﻣﻞ ‪Or‬‬‫وﺑﺮﻏﻢ اﻧﻚ ﺗﻠﺤﻆ ﺑﺈﻧﻪ ﻓﻲ ﺣﺎﻟﺔ ﻛﻮن اﻟﻄﺮف اﻷول ‪ True‬ﻓﺈن اﻟﺠﻤﻠﺔ ﻣﺒﺎﺷﺮة ﺳﺘﻜﻮن‬‫ﺻﺤﻴﺤﺔ، وﻻ ﻳﻮﺟﺪ أي داﻋﻲ ﻟﻠﺘﺤﻘﻖ ﻣﻦ اﻟﺠﺰء اﻟﺜﺎﻧﻲ ﻣﻦ اﻟﺸﺮط ، وﻟﻜﻦ ﻟﻼﺳﻒ ﻫﺬا ﻣﺎ ﻻ ﻳﻔﻌﻠﻪ‬ ‫اﻟﻤﻌﺎﻣﻞ ‪.Or‬‬‫ﻣﻦ اﺟﻞ ﻫﺬا ﻛﺎن اﻟﻤﻌﺎﻣﻞ ‪ OrElse‬واﻟﺬي ﻻ ﻳﻜﻠﻔﻚ ﻋﻨﺎء اﻟﺘﺤﻘﻖ ﻣﻦ ﻋﺪة ﻣﺪﺧﻼت ﻛﻤﺎ‬ ‫ﻫﻮ اﻟﺤﺎل ﻓﻲ اﻟﺪرس اﻟﺴﺎﺑﻖ اﻳﻀﺎ ﻣﻊ ‪. AndAlso‬‬ ‫ً‬ ‫6. 5. اﺳﺘﺨﺪام ال ‪switch‬‬ ‫ﻃﺮﻳﻘﺔ اﺧﺮى ﻟﻠﺠﻤﻞ اﻟﺸﺮﻃﻴﺔ ﻫﻲ اﺳﺘﺨﺪام ‪ switch‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪switch (x‬‬ ‫{‬ ‫:09 ‪case‬‬ ‫;)"ﻣﻤﺘﺎز"(‪Console.WriteLine‬‬ ‫;‪break‬‬ ‫:05 ‪case‬‬ ‫;)"ﻧﺎﺟﺢ"(‪Console.WriteLine‬‬ ‫;‪break‬‬ ‫}‬‫501‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎدس‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Select Case x‬‬ ‫09 ‪Case‬‬ ‫)"ﻣﻤﺘﺎز"(‪Console.WriteLine‬‬ ‫05 ‪Case‬‬ ‫)"ﻧﺎﺟﺢ"(‪Console.WriteLine‬‬ ‫‪End Select‬‬ ‫ﻻ ﺗﻨﺲ اﺿﺎﻓﺔ ‪ break‬ﻓﻲ اﺧﺮ اﻟﺸﺮط ، اﻟﺴﺒﺐ ان ذﻟﻚ ﻳﻤﻨﻊ اﻟﻤﺘﺮﺟﻢ ﻣﻦ اﻻﺳﺘﻤﺮار ﻓﻲ اﺧﺘﺒﺎر‬ ‫ﺑﺎﻗﻲ اﻟﺸﺮوط ﻋﻨﺪﻣﺎ ﻳﻌﺜﺮ ﻋﻠﻰ اول ﺷﺮط ، اﻣﺎ إذا ﻛﻨﺖ ﺗﺮﻏﺐ ﻓﻲ ﻣﺮوره ﻋﻠﻰ ﻛﻞ اﻟﺸﺮوط ﺣﺘﻰ‬ ‫ﻣﻊ ﺗﺤﻘﻖ اي ﻣﻨﻬﻢ ﻓﻼ ﺗﻀﻒ ‪ ، break‬ﻓﻲ اﻟﻔﻴﺠﻮال ﺑﻴﺴﻚ ﻟﻦ ﺗﺘﻌﺮض ﻟﻬﺬه اﻟﻤﻌﻀﻠﺔ .‬ ‫7. اﻟﺤﻠﻘﺎت اﻟﺘﻜﺮارﻳﺔ  ‬‫ﻧﺴﺘﺨﺪم اﻟﺤﻠﻘﺎت اﻟﺘﻜﺮارﻳﺔ ﻟﺘﻜﺮار ﺳﻄﺮ او اﻣﺮ ﻋﺪة ﻣﺮات ، ﺳﻨﺸﺮح ﻃﺮق اﻟﺘﻜﺮار ﻓﻲ ﻫﺬا اﻟﺪرس‬ ‫ﻋﻠﻰ ﻋﺠﺎﻟﺔ:‬ ‫7. 1. ‪For-Next Loop‬‬ ‫ﺣﻠﻘﺔ ﺗﻜﺮار ﻳﺘﻢ ﺗﺤﺪﻳﺪ ﻧﻘﻄﺔ اﻟﺒﺪاﻳﺔ واﻟﻨﻬﺎﻳﺔ وﻣﻘﺪار اﻟﺨﻄﻮة ﻓﻴﻬﺎ ، اﺑﺴﻂ ﻣﺜﺎل ﻋﻠﻴﻬﺎ اﻟﻜﻮد اﻟﺘﺎﻟﻲ‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)++‪for (int i = 0; i < 10; i‬‬ ‫{‬ ‫;)‪Console.WriteLine(i‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫9 ‪For i As Integer = 0 To‬‬ ‫)‪Console.WriteLine(i‬‬ ‫‪Next‬‬ ‫ﻳﻤﻜﻦ ﻋﻤﻞ ﻣﻘﺪار اﻟﻘﻔﺰ = 2 ﻣﺜﻼ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ - ﻟﻄﺒﺎﻋﺔ اﻻرﻗﺎم اﻟﺰوﺟﻴﺔ ﻣﺜﻼ: -‬ ‫ً‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)2 =+ ‪for (int i = 0; i < 10; i‬‬ ‫{‬ ‫;)‪Console.WriteLine(i‬‬ ‫}‬‫601‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬   ‫اﻟﺒﺎب اﻟﺴﺎدس‬ VB.NET ‫ﻛﻮد‬ For i As Integer = 0 To 9 Step 2 Console.WriteLine(i) Next While Loop .2 .7‫ﺣﻠﻘﺔ ﺗﻜﺮار ﺗﺴﺘﻤﺮ ﻓﻲ اﻟﻌﻤﻞ ﺣﺘﻰ ﺗﺤﻘﻖ ﺷﺮط ﻣﻌﻴﻦ ، ﻟﻨﻔﺘﺮض ﻣﺜﻼ ﺣﺘﻰ وﺻﻮل اﻟﻌﺪاد إﻟﻰ رﻗﻢ‬ ً :10 C# ‫ﻛﻮد‬ int x = 0; while (x < 10) { Console.WriteLine(x); x++; } VB.NET ‫ﻛﻮد‬ Dim x As Integer = 0 While x < 10 Console.WriteLine(x) X+=1 End WhileDo ‫" ، ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﺳﻮف ﻧﻀﻴﻒ‬exit" ‫ﺣﺎﻟﺔ اﺧﺮى ﻏﻴﺮ رﻗﻤﻴﺔ ، ادﺧﺎل ﺑﻴﺎﻧﺎت ﺣﺘﻰ ادﺧﺎل‬ .‫ ﻓﻲ اﻟﻨﻬﺎﻳﺔ‬While ‫ﻓﻲ اﻟﺒﺪاﻳﺔ وﻧﻀﻊ‬ C# ‫ﻛﻮد‬ string inp; do { inp = Console.ReadLine(); Console.WriteLine(inp); } while (inp != "exit");107
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬   ‫اﻟﺒﺎب اﻟﺴﺎدس‬ VB.NET ‫ﻛﻮد‬ Dim inp As String Do inp = Console.ReadLine() Console.WriteLine(inp) Loop While inp <> "exit" For Each Loop .3 .7 :‫ﻟﻠﺪوران ﻋﻠﻰ )ﻛﻞ( ﺷﻲء ﻣﻌﻴﻦ، ﻣﺜﻼ ﻟﻠﺪوران ﻋﻠﻰ ﻛﻞ ﻋﻨﺎﺻﺮ ﻣﺼﻔﻮﻓﺔ ﻣﻌﻴﻨﺔ ﻣﺜﻼ‬ ً ً C# ‫ﻛﻮد‬ int[] arr = { 10, 20, 30, 40 }; foreach (int i in arr) Console.WriteLine(i); VB.NET ‫ﻛﻮد‬ Dim arr As Integer() = {10, 20, 30, 40} For Each i As Integer In arr Console.WriteLine(i) Next108
  • 109
  • ‫اﻟﺒﺎب‬ ‫7‬ ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬‫اﻟﺠﺰئ 20‬‫011‬
  • 111
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ ‫1. ﻟﻨﻔﻬﻢ ﺑﺮﻧﺎﻣﺠﻨﺎ اﻷول  ‬ ‫ﻟﻮ ﻻﺣﻈﻨﺎ ﺑﺮﻧﺎﻣﺠﻨﺎ اﻷول ﻟﻄﺒﺎﻋﺔ ﺟﻤﻠﺔ ‪ Hello World‬واﻟﺬي ﻛﺎن ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;‪using System‬‬ ‫;‪using System.Collections.Generic‬‬ ‫;‪using System.Text‬‬ ‫4‪namespace ConsoleApplication‬‬ ‫{‬ ‫‪class Program‬‬ ‫{‬ ‫)‪static void Main(string[] args‬‬ ‫{‬ ‫;)"‪Console.Write("Hello World‬‬ ‫;)(‪Console.ReadKey‬‬ ‫}‬ ‫}‬ ‫}‬ ‫أﻣﺎ ﻓﻲ ﻓﻴﺠﻮال ﺑﻴﺴﻚ ﻓﻜﺎن ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ :‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫1‪Module Module‬‬ ‫)(‪Sub Main‬‬ ‫)"‪Console.Write("Hello World‬‬ ‫)(‪Console.ReadKey‬‬ ‫‪End Sub‬‬ ‫‪End Module‬‬‫اول ﻣﺎ ﺳﻨﺠﺪه ﻓﻲ #‪ C‬ﻫﻮ اﺳﺘﻴﺮاد اﻟﻤﻜﺘﺒﺎت اﻟﺘﻲ ﺳﻨﺴﺘﺨﺪﻣﻬﺎ ﻟﻜﺘﺎﺑﺔ اﻛﻮادﻧﺎ ﺑﺎﺳﺘﺨﺪام ‪ using‬أﻣﺎ‬‫ﻓﻲ اﻟﻔﻴﺠﻮال ﺑﻴﺴﻚ ﻓﺘﻢ ﺗﻌﺮﻳﻒ ‪ Module‬ﻗﻤﺖ ﺑﻜﺘﺎﺑﺔ اﻷﻛﻮاد داﺧﻠﻪ ﻣﺒﺎﺷﺮة ، ال ‪ Module‬ﻫﻮ‬‫ﻓﺌﺔ ‪ Class‬ﻋﺎدﻳﺔ ﻣﺎ ﻋﺪا أن ﺟﻤﻴﻊ ﻓﺌﺎﺗﻬﺎ ﻫﻲ ‪ Shared-static‬ﻳﻨﺸﺄﻫﺎ اﻟﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ‬ ‫ﻟﻚ ﻓﻲ ﺣﺎﻟﺔ ﻛﻮن ﻣﺸﺮوﻋﻚ ﻣﻦ ﻧﻮع ‪.VB‬‬‫اﻟﺠﺰء اﻟﺜﺎﻧﻲ ﻓﻲ ﻛﻮد #‪ C‬ﻫﻮ ﺗﻌﺮﻳﻒ ال ‪ name space‬اﻟﺨﺎص ﺑﺒﺮﻧﺎﻣﺠﻨﺎ وﻫﻮ اﻻﺳﻢ اﻟﺬي ﺗﻮﺿﻊ‬‫ﺗﺤﺘﻪ ﻛﻞ ﻣﻜﻮﻧﺎت اﻟﺒﺮﻧﺎﻣﺞ ، وﻣﻦ ﺛﻢ ال ‪ Class‬اﻻﺳﺎﺳﻲ ﻟﺪﻳﻨﺎ ﺑﺎﺳﻢ ‪ ... Main‬ﻛﻤﺎ ﺗﻌﻠﻤﻨﺎ ﻓﻲ‬‫اي ﻣﺒﺎدئ ﻟﻠﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ ﻓﺈن أي ﺑﺮﻧﺎﻣﺞ ﻳﺘﻜﻮن ﻣﻦ واﺣﺪ او اﻛﺜﺮ ﻣﻦ ال ‪ ،Classes‬اﻟﺪاﻟﺔ‬‫اﻟﺮﺋﻴﺴﻴﺔ ﻓﻲ ال ‪ Class‬اﻟﻤﺴﻤﻰ ‪ Main‬ﻫﻲ اﻟﺪاﻟﺔ ‪ main‬واﻟﺘﻲ ﻳﺘﻢ ﺗﻨﻔﻴﺬﻫﺎ اول ﺷﻲء ﻓﻲ‬‫اﻟﺒﺮﻧﺎﻣﺞ. ﺗﺴﺘﻘﺒﻞ اﻟﺪاﻟﺔ ‪ Main‬ﻣﺠﻤﻮﻋﺔ ﻣﻦ اﻟﺒﺎﻣﻴﺘﻴﺮ ﺗﺤﺖ اﺳﻢ ‪ ، args‬ﻣﻌﻨﻰ ﻫﺬا ان اﻟﺒﺮﻧﺎﻣﺞ‬‫211‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬‫ﻳﺴﺘﻘﺒﻞ ﻣﻊ ﺗﺸﻐﻴﻠﻪ ﻣﺼﻔﻮﻓﺔ ﻣﻦ ]0[‪ args‬إﻟﻰ ]‪ ،args[n‬ﻳﻤﻜﻦ ارﺳﺎل ﻛﻞ ﻣﺎ ﺗﺮﻳﺪ إﻟﻰ‬ ‫اﻟﺒﺮﻧﺎﻣﺞ ﻣﻦ ﺧﻼﻟﻬﺎ ، وﻫﻮ ﻣﺎ ﻳﺴﻤﻰ ‪.Command Line Parameters‬‬‫ﻟﻜﻲ ﻻ ﻧﺒﻌﺪ ﻋﻦ ﻣﺴﺎرﻧﺎ ﻓﻲ اﻟﺸﺮح ، ال ‪ Command Line Args‬ﻫﻲ ﻣﺠﻤﻮﻋﺔ ﻣﻦ اﻟﻤﺘﻐﻴﺮات اﻟﺘﻲ‬ ‫ﻳﻤﻜﻦ ﺗﻤﺮﻳﺮﻫﺎ ﻟﻠﺒﺮﻧﺎﻣﺞ وﻗﺖ ﺗﺸﻐﻴﻠﻪ ﻟﺘﺘﺤﻜﻢ ﻓﻲ ﺑﻌﺾ اﻟﻨﻘﺎط ، ﻣﺜﻼ ﻟﻮ ﻗﻤﻨﺎ ﺑﻜﺘﺎﺑﺔ اﻻﻣﺮ اﻟﺘﺎﻟﻲ:‬ ‫ً‬ ‫ ‪Shell‬‬ ‫ﻛﻮد‬ ‫‪Explorer http://www.vb4arab.com‬‬‫اول ﻣﺎ ﻳﺘﻢ ﻓﺘﺢ ﺑﺮﻧﺎﻣﺞ ‪ ، Explorer‬ﻳﻘﻮم ﺑﻘﺮاءة اﻟﻨﺺ اﻟﻤﻤﺮر ﻟﻪ ، إذا ﻛﺎن ﻣﻮﻗﻊ اﻧﺘﺮﻧﺖ ﻳﻘﻮم‬‫ﺑﻔﺘﺤﻪ ﺑﺎﻟﺸﻜﻞ اﻟﻤﻌﻬﻮد ﻟﻤﺘﺼﻔﺢ اﻻﻧﺘﺮﻧﺖ، اﻣﺎ ﻟﻮ ﻛﺎن ﻣﺴﺎر ﻣﺜﻼ :‪ C‬ﻓﺴﻴﻘﻮم ﺑﻔﺘﺢ ﻣﺘﺼﻔﺢ‬ ‫ً‬ ‫اﻟﻤﺠﻠﺪات ﻣﻊ اﻧﻬﻢ ﻧﻔﺲ اﻟﺒﺮﻧﺎﻣﺞ ﻓﻲ اﻟﻨﻬﺎﻳﺔ .‬ ‫ﺗﺴﺘﻄﻴﻊ ﺗﺠﺮﺑﺔ ذﻟﻚ ﻋﻠﻰ ﺑﺮﻧﺎﻣﺠﻚ ﻣﻦ ﺧﻼل ﻗﺮاءة اﻟﻤﺘﻐﻴﺮات اﻟﻤﻤﺮة ﻟﻪ ﻋﻦ ﻃﺮﻳﻖ ‪For‬‬ ‫‪Loop‬‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)++‪for (int i = 0; i < args.Length; i‬‬ ‫;)]‪Console.WriteLine(args[i‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫1 - ‪For i As Integer = 0 To args.Length‬‬ ‫))‪Console.WriteLine(args(i‬‬ ‫‪Next‬‬‫اﻵن ﻗﻢ ﺑﺎﻟﺬﻫﺎب إﻟﻰ ‪ ،Run‬ﻗﻢ ﺑﻜﺘﺎﺑﺔ ﻣﺴﺎر ﺑﺮﻧﺎﻣﺠﻚ وﻣﻦ ﺛﻢ ﻣﺴﺎﻓﺔ وﻣﻦ ﺛﻢ ﻛﺘﺎﺑﺔ اﻟﺒﺎرﻣﻴﺘﺮات‬ ‫اﻟﺘﻲ ﺗﺮﻏﺐ ﻓﻲ ﺗﻤﺮﻳﺮﻫﺎ، ﻓﻲ ﺟﻬﺎزي ﻛﺘﺒﺖ اﻻﻣﺮ اﻟﺘﺎﻟﻲ ﻓﻲ ‪:Run‬‬‫ ‪Shell‬‬ ‫ﻛﻮد‬‫‪C:UsersAhmedDocumentsVisual Studio‬‬‫‪2008ProjectsConsoleApplication4ConsoleApplication4binDebugcon‬‬‫‪soleapplication4.exe ahmed ali‬‬ ‫اﻟﻨﺎﺗﺞ اﻟﺬي ﻇﻬﺮ ﻟﻲ ﻛﺎن ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬‫311‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ ‫اﻟﺼﻮرة 7. 1. ﻧﺘﺎﺋﺞ ﺗﺸﻐﻴﻞ اﻷﻣﺮ ﻓﻲ اﻟﺸﻞ‬‫ﻛﺘﻄﺒﻴﻖ ﺳﺮﻳﻊ ، ﺳﻨﻘﻮم ﺑﻘﺮاءة اﻟﻤﺘﻐﻴﺮ اﻷول وﻓﻲ ﺣﺎﻟﺔ وﺟﻮد 0 ﻣﺜﻼ ﻳﺘﻢ ﺗﻠﻮﻳﻦ ﺧﻠﻔﻴﺔ اﻟﻜﻼم‬ ‫ً‬ ‫ﺑﺎﻻزرق ، وﻓﻴﻤﺎ ﻋﺪا ذﻟﻚ ﻳﺘﻢ ﺗﻠﻮﻳﻦ ﺧﻠﻴﻔﺔ اﻟﻜﻼم ﺑﺎﻷﺣﻤﺮ ، ﻫﺬا ﻫﻮ اﻟﻜﻮد اﻟﺨﺎص ﺑﺬﻟﻚ:‬‫#‪C‬‬ ‫ﻛﻮد‬‫)"0" == ]0[‪if (args‬‬‫{‬ ‫;‪Console.BackgroundColor = ConsoleColor.Blue‬‬ ‫;)"‪Console.WriteLine("0 enterd‬‬‫}‬‫‪else‬‬‫{‬ ‫;‪Console.BackgroundColor = ConsoleColor.Red‬‬ ‫;)"‪Console.WriteLine("Empty‬‬‫}‬‫;)(‪Console.ReadKey‬‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫‪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‬‬‫ﺗﻮاﺟﻬﻨﺎ ﻫﻨﺎ ﻣﺸﻜﻠﺔ، ﻣﺎذا ﻟﻮ ﻟﻢ ﻧﻘﻢ ﺑﺘﻤﺮﻳﺮ اي ﻣﺘﻐﻴﺮات .. ﺳﺘﻈﻬﺮ ﻟﻚ رﺳﺎﻟﺔ ﺧﻄﺎ ، إذن ﻧﺤﻦ‬‫ﺑﺤﺎﺟﺔ ﻟﻠﺘﺄﻛﺪ ﻣﻦ وﺟﻮد ﺑﺎرﻣﺘﻴﺮس ﻗﺒﻞ ﻗﺮاءﺗﻬﺎ ، ﺳﻨﻘﻮم ﺑﺬﻟﻚ ﻋﻦ ﻃﺮﻳﻖ اﻟﺘﺄﻛﺪ ﻣﻦ وﺟﻮد‬‫ﻣﺘﻐﻴﺮات ، إذا ﻛﺎن ﻫﻨﺎك ﻓﻴﺘﻢ اﻟﺘﺄﻛﺪ ﻣﻦ ﻛﻮﻧﻬﺎ ﺻﻔﺮ ، إذا اﺧﺘﻞ اي ﻣﻦ اﻟﺸﺮﻃﻴﻦ ﻧﻠﺠﺄ ﻟﻠﻮن‬ ‫اﻟﺜﺎﻧﻲ:‬‫411‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬   ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ 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.NET ‫ﻛﻮد‬ 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() ‫ﻫﻨﺎك ﺣﻞ آﺧﺮ ، ﻣﺎذا ﻟﻮ اﺣﺒﺒﻨﺎ ان ﻧﺠﻌﻞ اﻟﺘﺄﻛﺪ ﻓﻲ ﺳﻄﺮ واﺣﺪ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ if (args.Length >0 && args[0] == "0") VB.NET ‫ﻛﻮد‬ If args.Length > 0 AndAlso args(0) = "0" Then‫ﻫﺬا ﻳﻌﻨﻲ اﻧﻪ ﺳﻴﺘﺄﻛﺪ ﻣﻦ وﺟﻮد ﺑﺎرﻣﻴﺘﺮس ، إذا وﺟﺪﻫﺎ ﺳﻴﻨﺘﻘﻞ ﻟﻠﺸﺮط اﻟﺜﺎﻧﻲ وإذا ﻟﻢ ﻳﺠﺪﻫﺎ ﻓﺈﻧﻪ‬ ...‫ﻳﺨﺮج ﻣﺒﺎﺷﺮة دون ﻗﺮاءة اﻟﺸﺮط اﻟﺜﺎﻧﻲ‬AndAlso ‫، ﺑﻞ ﺳﺘﻀﻄﺮ ﻻﺳﺘﺨﺪام‬VB.net ‫ ﻟﻦ ﻳﻤﻜﻦ ﺗﻄﺒﻴﻘﻪ ﻓﻲ‬And ‫اﻟﺠﺪﻳﺮ ﺑﺎﻟﺬﻛﺮ ان اﻟﻤﻌﺎﻣﻞ‬ .‫اﻟﺬي ﺳﺒﻖ ﺷﺮﺣﻪ ﻓﻲ دروس ﺳﺎﺑﻘﺔ‬115
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ ‫2. اﻟﺪوال ‪  Functions‬‬‫ﻛﻤﺎ ﺷﺎﻫﺪﻧﺎ ﻓﻲ داﻟﺔ ‪ ،Main‬ﻳﻤﻜﻨﻨﺎ اﻧﺸﺎء اي ﻋﺪد ﻣﻦ اﻟﺪوال ﺑﺄي ﻋﺪد ﻣﻦ اﻟﻤﺘﻐﻴﺮات ، ﻛﻞ‬‫ﻣﺎ ﻧﺤﺘﺎج إﻟﻴﻪ ﻫﻮ ﻣﻌﺮﻓﺔ اﻟﺒﺎرﻣﺘﻴﺮات اﻟﺘﻲ ﻧﺮﻳﺪ ﻟﻬﺎ ان ﺗﺼﻞ ﻟﻠﺪاﻟﺔ ، واﻳﻀﺎ اﻟﻨﺎﺗﺞ اﻟﺨﺎرج ﻣﻨﻬﺎ،‬ ‫ً‬ ‫ﻟﻨﻔﺘﺮض ﻣﺜﻼ اﻧﻨﺎ ﻧﺼﻤﻢ داﻟﺔ ﻟﻌﻤﻠﻴﺔ اﻟﺠﻤﻊ ، ﺗﺴﺘﻘﺒﻞ رﻗﻤﻴﻦ ‪ int‬وﺗﺨﺮج ﻧﺎﺗﺞ ‪ ، int‬ﺳﺘﻜﻮن‬ ‫ً‬ ‫اﻟﺪاﻟﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬‫#‪C‬‬ ‫ﻛﻮد‬‫)2‪static int sum(int number1, int number‬‬‫{‬ ‫;2‪int total = number1 + number‬‬ ‫;‪return total‬‬‫}‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫‪Private Function sum(ByVal number1 As Integer, ByVal number2 As Integer) As‬‬‫‪Integer‬‬ ‫2‪Dim total As Integer = number1 + number‬‬ ‫‪Return total‬‬‫‪End Function‬‬ ‫وﻣﻦ ﺛﻢ ، ﺳﻨﺤﺎول ﻣﻦ ﺧﻼل ‪ Main‬اﺳﺘﺪﻋﺎﺋﻬﺎ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬‫#‪C‬‬ ‫ﻛﻮد‬‫;)8 ,5(‪int result = sum‬‬‫;)‪Console.Write(result‬‬‫;)(‪Console.ReadKey‬‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫)8 ,5(‪Dim result As Integer = sum‬‬‫)‪Console.Write(result‬‬‫)(‪Console.ReadKey‬‬ ‫ﻟﻤﺎذا ﺗﻢ ﺗﻌﺮﻳﻒ ‪ sum‬ﻋﻠﻰ اﻧﻬﺎ ‪ static‬ﻓﻲ اﻟﺴﻲ ﺷﺎرب ؟؟‬‫اﻟﺴﺒﺐ اﻧﻪ ﻻ ﻳﻤﻜﻦ اﺳﺘﺪﻋﺎء داﻟﺔ ﻏﻴﺮ ‪ static‬ﻣﻦ ﺧﻼل داﻟﺔ ‪ ، static‬وﺑﻤﺎ ان داﻟﺔ ‪ Main‬ﻫﻲ‬ ‫ﻣﻦ ﻧﻮع ‪ static‬ﻓﻼ ﺑﺪ ﻣﻦ ان ﺗﻜﻮن اي داﻟﺔ اﺧﺮى ﻳﺘﻢ اﺳﺘﺪﻋﺎﺋﻬﺎ ﻣﻦ ﺧﻼل ال ‪ main‬ﻫﻲ‬ ‫‪ static‬اﻳﻀﺎ ، ﺳﻨﺘﻌﺮف ﻋﻠﻰ ﺑﻌﺾ اﻟﺘﻔﺎﺻﻴﻞ اﻻﺿﺎﻓﻴﺔ ﻻﺣﻘﺎ .‬ ‫ً‬ ‫ً‬‫611‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ ‫3. اﻟﻄﺮق ‪  Methods‬‬ ‫اﻟﻄﺮق ﻫﻲ اﻟﺪاﻟﺔ اﻟﺘﻲ ﻻ ﺗﻌﻴﺪ ﻧﺎﺗﺞ ، ﻣﺜﻞ داﻟﺔ ﻋﺮض ﻛﺘﺎﺑﺔ رﺳﺎﻟﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪void printmsg(string msg‬‬ ‫{‬ ‫;)‪Console.WriteLine(msg‬‬ ‫}‬‫ﻓﻲ اﻟﻔﺠﻴﻮال ﺑﻴﺴﻚ 6، ﻛﺎن ﻳﺘﻢ ﺗﻌﺮﻳﻒ اﻟﻄﺮﻳﻘﺔ ﺑﺎﺳﻢ ‪ ،Sub‬وﻫﻮ اﻟﻤﺴﺘﻤﺮ اﻳﻀﺎ ﻣﻊ ‪VB.net‬‬ ‫ً‬ ‫ﻟﻴﻜﻮن ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)‪Private Sub printmsg(ByVal msg As String‬‬ ‫)‪Console.WriteLine(msg‬‬ ‫‪End Sub‬‬ ‫4. اﻟﻮﻇﻴﻔﺔ ‪  out‬‬‫ﻛﻤﺎ ﺗﻌﻠﻤﻨﺎ ﻓﻲ اﻟﻤﺜﺎل اﻟﺴﺎﺑﻖ ﻓﺈﻧﻨﺎ ﻧﻘﻮم ﺑﺎرﺟﺎع اﻟﻨﺘﻴﺠﺔ ﻣﻦ ﺧﻼل ‪ ،return‬ﻣﺎذا ﻟﻮ اردﻧﺎ‬ ‫اﻋﺎدة ﻧﺘﻴﺠﺔ ﻣﻦ داﻟﺔ ‪ ،void‬ﻳﺘﻢ ذﻟﻚ ﺑﺎﺳﺘﺨﺪام اﻟﺪاﻟﺔ ‪ out‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪static void sum(int number1, int number2, out int total‬‬ ‫{‬ ‫;2‪total = number1 + number‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫,‪Private Shared Sub sum(ByVal number1 As Integer, ByVal number2 As Integer‬‬ ‫)‪ByRef total As Integer‬‬ ‫2‪total = number1 + number‬‬ ‫‪End Sub‬‬‫اﻟﺪاﻟﺔ اﻟﺴﺎﺑﻘﺔ اﻟﺨﺎﺻﺔ ﺑﺎﻟﻔﻴﺠﻮال ﺑﻴﺴﻚ ﻫﻲ اﻟﺘﺮﺟﻤﺔ اﻟﺼﺤﻴﺤﺔ ﻟﻜﻮد ال #‪ ، C‬وﻟﻜﻦ ﻟﻜﻲ ﺗﻌﻤﻞ‬‫ﻣﻌﻚ ﺑﺼﻮرة ﺻﺤﻴﺤﺔ ﻓﻲ ‪ Module‬ﻻ ﺑﺪ أن ﺗﺴﺘﻐﻨﻲ ﻋﻦ ‪ ، Shared‬ﻟﺬا ﺳﻨﻘﻮم ﺑﺎﻻﺳﺘﻐﻨﺎء ﻋﻨﻬﺎ‬ ‫اﺑﺘﺪاء ﻣﻦ ﻫﺬا اﻟﻜﻮد ﺣﺘﻰ ﻳﺤﻴﻦ ﻣﻮﻋﺪ ﺷﺮح ﻣﻌﻨﺎﻫﺎ وﻓﺎﺋﺪﺗﻬﺎ .‬‫711‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ ‫وﻋﻨﺪ اﺳﺘﺪﻋﺎء اﻟﺪاﻟﺔ ﻳﺘﻢ ﺗﻤﺮﻳﺮ اﻟﻤﺘﻐﻴﺮ اﻟﺬي ﻧﺤﺘﺎج إﻟﻴﻪ ﻟﻌﺮض اﻟﻨﺘﻴﺠﺔ اﻳﻀﺎ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;‪int result‬‬ ‫;)‪sum(5, 8,out result‬‬ ‫;)‪Console.Write(result‬‬ ‫;)(‪Console.ReadKey‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Dim result As Integer‬‬ ‫)‪sum(5, 8, result‬‬ ‫)‪Console.Write(result‬‬ ‫)(‪Console.ReadKey‬‬ ‫وﻟﻜﻦ ﻣﺎ ﻫﻮ اﻟﺴﺒﺐ اﻟﺬي ﻗﺪ ﻳﺪﻓﻌﻨﻲ ﻻﺳﺘﺨﺪام ﻫﺬه اﻟﻄﺮﻳﻘﺔ ﺑﺪﻻ ﻣﻦ اﺳﺘﺨﺪام‬ ‫ً‬ ‫‪return‬؟‬‫اﻻﺟﺎﺑﺔ اﻻﺑﺴﻂ، ﻫﻲ اﻧﻨﻲ ﻟﻮ اردت اﻋﺎدة اﻛﺜﺮ ﻣﻦ ﻧﺘﻴﺠﺔ ﻣﺜﻞ ﻧﺎﺗﺞ اﻟﻀﺮب واﻟﺠﻤﻊ واﻟﻘﺴﻤﺔ ، ﻓﻠﻴﺲ‬ ‫اﻣﺎﻣﻲ ﺣﻞ ﺳﻮى اﻋﺎدة ﻣﺼﻔﻮﻓﺔ ﺑﺎﻻرﻗﺎم وﻗﺮاءﺗﻬﺎ ﻫﻨﺎك ، اﻟﺤﻞ اﻻﺑﺴﻂ ﻫﻮ ﺑﺎﺳﺘﺨﺪام ‪.out‬‬ ‫5. اﻻرﺳﺎل ﺑﺎﻟﻤﺮﺟﻊ ‪ byref‬و اﻻرﺳﺎل ﺑﺎﻟﻘﻴﻤﺔ‬ ‫‪byval‬‬ ‫ﻟﻨﻔﺘﺮض اﻟﻤﺜﺎل اﻟﺨﺎص ﺑﻌﻤﻠﻴﺔ اﻟﻄﺮح ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;5 = ‪int x‬‬ ‫;01 = ‪int y‬‬ ‫;)‪sub(x, y‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫5 = ‪Dim x As Integer‬‬ ‫01 = ‪Dim y As Integer‬‬ ‫)‪sub(x, y‬‬ ‫واﻟﺪاﻟﺔ:‬‫811‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)2‪static void sub(int number1, int number‬‬ ‫{‬ ‫;2‪number1 = number1 - number‬‬ ‫;1‪return number‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)‪Private Sub [sub](ByVal number1 As Integer, ByVal number2 As Integer‬‬ ‫2‪number1 = number1 - number‬‬ ‫1‪Return number‬‬ ‫‪End Sub‬‬‫ﻓﻲ اﻟﺪاﻟﺔ اﻟﺴﺎﺑﻘﺔ ﻗﻤﻨﺎ ﺑﺘﻐﻴﻴﺮ ﻗﻴﻤﺔ 1‪ ، number‬وﻟﻜﻦ ﻫﻞ ﺳﻴﻐﻴﺮ ﻫﺬا ﻣﻦ ﻗﻴﻤﺔ ‪ x‬اﻟﺘﻲ ارﺳﻠﻨﺎﻫﺎ،‬ ‫اﻹﺟﺎﺑﺔ ﻫﻲ ﺑﻼ ، ﻫﺬا ﻣﺎ ﻳﻌﺮف ﺑﺎرﺳﺎل اﻟﻘﻴﻤﺔ ﺣﻴﺚ ﻧﻘﻮم ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﺑﺎرﺳﺎل ﻗﻴﻤﺔ ‪ x‬إﻟﻰ اﻟﺪاﻟﺔ‬ ‫وﻟﻴﺴﺖ ﻗﻴﻤﺔ ‪.X‬‬‫اﻻرﺳﺎل ﺑﺎﻟﻤﺮﺟﻊ ‪ ByRef‬ﻫﻲ اﻟﺤﺎﻟﺔ اﻟﺜﺎﻧﻴﺔ ، ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﻳﺘﻢ ارﺳﺎل ﻋﻨﻮان اﻟﻤﺘﻐﻴﺮ ‪ x‬ﻓﻲ‬ ‫اﻟﺬاﻛﺮة إﻟﻰ اﻟﺪاﻟﺔ ، ﻫﺬا ﻣﺎ ﻳﻌﻨﻲ ان اي ﺗﻐﻴﻴﺮ ﻓﻲ 1‪ number‬ﺳﻴﺆﺛﺮ ﺑﺎﻟﻀﺮورة ﻋﻠﻰ اﻟﻤﺘﻐﻴﺮ ‪.x‬‬ ‫ﻟﻜﺘﺎﺑﺔ اﻟﻜﻮد اﻟﺴﺎﺑﻖ ﺑﻄﺮﻳﻘﺔ ‪ ByRef‬ﻧﻜﺘﺐ اﻟﻜﻮد اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)2‪static void sub(ref int number1, ref int number‬‬ ‫{‬ ‫;2‪int result = number1 - number‬‬ ‫;‪return result‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)‪Private Sub [sub](ByRef number1 As Integer, ByRef number2 As Integer‬‬ ‫2‪Dim result As Integer = number1 - number‬‬ ‫‪Return result‬‬ ‫‪End Sub‬‬‫اﻻرﺳﺎل ﺑﺎﻟﻘﻴﻤﺔ ﻳﻤﻜﻦ ﺗﻄﺒﻴﻘﻪ ﻓﻘﻂ ﻣﻊ اﻟﻤﺘﻐﻴﺮات اﻟﺒﺴﻴﻄﺔ، اﻣﺎ اﻟﻤﺘﻐﻴﺮات اﻟﻤﺮﻛﺒﺔ ﻣﺜﻞ ‪Struct‬‬ ‫ﻓﻴﺘﻢ اﻟﺘﻌﺎﻣﻞ ﻣﻌﻪ ‪ ByRef‬اﻓﺘﺮاﺿﻴﺎ...‬ ‫ً‬‫911‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ ‫6. اﻟﻤﺼﻔﻮﻓﺎت ‪Arrays‬‬ ‫ﻓﻲ ﻫﺬا اﻟﺪرس ﺳﻮف ﻧﺘﻌﺮف ﻋﻠﻰ اﻟﻤﺼﻔﻮﻓﺎت وﻛﻴﻔﻴﺔ اﺳﺘﺨﺪاﻣﻬﺎ وﺗﻌﺮﻳﻔﻬﺎ.‬ ‫6. 1. ﻣﺎ ﻫﻲ اﻟﻤﺼﻔﻮﻓﺎت ‪ Arrays‬‬‫اﻟﻤﺼﻔﻮﻓﺔ ﻫﻲ ﻋﺒﺎرة ﻋﻦ ﺳﻠﺴﻠﺔ ﻣﻦ اﻟﺒﻴﺎﻧﺎت ﻣﻦ ﻧﻔﺲ اﻟﻨﻮع ، ﻟﺘﻌﺮﻳﻒ ‪ Array‬ﻣﻦ اﻻرﻗﺎم ﻃﻮﻟﻬﺎ 5‬ ‫ﻋﻨﺎﺻﺮ ﻧﻜﺘﺐ اﻟﻜﻮد اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;]5[‪int[] intarray = new int‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)4(‪Dim intarray As Integer() = New Integer‬‬ ‫ﻳﺒﺪأ اﻟﺘﺮﻗﻴﻢ ﻓﻲ اﻟﻤﺼﻔﻮﻓﺎت ﻣﻦ اﻟﺼﻔﺮ وﺣﺘﻰ 4، ﻟﻘﺮاءة اﺣﺪ ﻋﻨﺎﺻﺮ اﻟﻤﺼﻔﻮﻓﺔ ﻧﻜﺘﺐ ﻛﻮد ﻣﺜﻞ‬ ‫اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)]3[‪Console.WriteLine(intarray‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫))3(‪Console.WriteLine(intarray‬‬ ‫وﻟﻘﺮاءة ﺟﻤﻴﻊ اﻟﻌﻨﺎﺻﺮ ﻳﻤﻜﻦ اﺳﺘﺨﺪام ﺣﻠﻘﺎت اﻟﺘﻜﺮار ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)++‪for (int i = 0; i < 5; i‬‬ ‫;)]‪Console.WriteLine(intarray[i‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫4 ‪For i As Integer = 0 To‬‬ ‫))‪Console.WriteLine(intarray(i‬‬ ‫‪Next‬‬‫021‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ ‫6. 2. ﺗﻜﻮﻳﻦ اﻟﻤﺼﻔﻮﻓﺎت‬ ‫اﻟﻄﺮﻳﻘﺔ اﻻﺳﻬﻞ ﻻدﺧﺎل اﻟﺒﻴﺎﻧﺎت إﻟﻰ اﻟﻤﺼﻔﻮﻓﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬‫#‪C‬‬ ‫ﻛﻮد‬‫;51 = ]0[‪array‬‬‫;02 = ]1[‪array‬‬‫;31 = ]2[‪array‬‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫51 = )0(‪array‬‬‫02 = )1(‪array‬‬‫31 = )2(‪array‬‬‫أو ﻋﻦ ﻃﺮﻳﻖ ﺣﻠﻘﺔ ﺗﻜﺮار اﻳﻀﺎ ، إﻻ ان ﻫﻨﺎك ﻃﺮﻳﻘﺔ أﺧﺮى ﻻدﺧﺎل اﻟﺒﻴﺎﻧﺎت إﻟﻰ اﻟﻤﺼﻔﻮﻓﺔ ﺑﺎﻟﺸﻜﻞ‬ ‫ً‬ ‫اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬‫#‪C‬‬ ‫ﻛﻮد‬‫;} 31 ,02 ,51 { ][‪int[] intarray = new int‬‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫}31 ,02 ,51{ )(‪Dim intarray As Integer() = New Integer‬‬ ‫6. 3. اﻟﻤﺼﻔﻮﻓﺎت ﻣﺘﻌﺪدة اﻷﺑﻌﺎد‬‫ﺟﻤﻴﻊ اﻟﻤﺼﻔﻮﻓﺎت اﻟﺴﺎﺑﻘﺔ ﻫﻲ ﻣﺼﻔﻮﻓﺎت اﺣﺎدﻳﺔ اﻟﺒﻌﺪ  ‪ ، one  dimensional‬ﻫﻨﺎك اﻧﻮاع‬‫اﺧﺮى ﻣﻦ اﻟﻤﺼﻔﻮﻓﺎت ﺛﻨﺎﺋﻴﺔ او ﻣﺘﻌﺪدة اﻻﺑﻌﺎد ‪ ، Multi  dimensional‬ﻫﺬا ﻣﺜﺎل ﻋﻠﻰ ﻣﺼﻔﻮﻓﺔ‬ ‫ﺛﻨﺎﺋﻴﺔ اﻻﺑﻌﺎد - ﺗﺴﻤﻰ ﺑﺎﺳﻢ- ‪:Matrix‬‬‫#‪C‬‬ ‫ﻛﻮد‬‫;]3 ,3[‪int matrix = new int‬‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫)2 ,2(‪Dim matrix As Integer = New Integer‬‬‫121‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ ‫ﺳﻴﻜﻮن ﺷﻜﻞ اﻟﻤﺼﻔﻮﻓﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ )اﻓﺘﺮاﺿﻲ( :‬ ‫0 0 0  ‬ ‫0 0 0  ‬ ‫0 0 0‬ ‫وﻳﻤﻜﻦ ادﺧﺎل اﻟﺒﻴﺎﻧﺎت إﻟﻰ ﻧﻘﻄﺔ ﻣﻦ اﻟﻤﺼﻔﻮﻓﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬‫#‪C‬‬ ‫ﻛﻮد‬‫;02 = ]2 ,1[‪matrix‬‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫02 = )2 ,1(‪matrix‬‬ ‫ﻳﻤﻜﻦ ﻋﻤﻞ ﺣﻠﻘﺔ ﺗﻜﺮار ﻻدﺧﺎل اﻟﺒﻴﺎﻧﺎت ، وﻟﻴﻜﻦ ﻋﻦ ﻃﺮﻳﻖ اﻟﻤﺴﺘﺨﺪم ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬‫#‪C‬‬ ‫ﻛﻮد‬‫;]3 ,3[‪int matrix = new int‬‬‫)++‪for (int i = 0; i < 3; i‬‬ ‫)++‪for (int j = 0; j < 3; j‬‬ ‫;)(‪matrix[i, j] = Console.ReadLine‬‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫}{ )2 ,2(‪Dim matrix As Integer = New Integer‬‬‫2 ‪For i As Integer = 0 To‬‬ ‫2 ‪For j As Integer = 0 To‬‬ ‫)(‪matrix(i, j) = Console.ReadLine‬‬ ‫‪Next‬‬‫‪Next‬‬ ‫واﻟﻄﺒﺎﻋﺔ ﺑﻨﻔﺲ اﻟﺸﻜﻞ اﻳﻀﺎ.‬ ‫ً‬ ‫6. 4. ﻋﻤﻞ ﻣﺼﻔﻮﻓﺔ ﻣﻦ اﻟﻤﺼﻔﻮﻓﺎت‬ ‫ﻳﻤﻜﻦ ﻋﻤﻞ ﻣﺼﻔﻮﻓﺔ ﻳﺤﺘﻮي ﻛﻞ ﻋﻨﺼﺮ ﻣﻨﻬﺎ ﻋﻠﻰ ﻣﺼﻔﻮﻓﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬‫#‪C‬‬ ‫ﻛﻮد‬‫;][]5[‪int[][] complexarray = new int‬‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫)()4(‪Dim complexarray As Integer()() = New Integer‬‬‫221‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ ‫وﻳﻤﻜﻦ اﻟﻮﺻﻮل ﻷي ﻋﻨﺼﺮ ﻓﻴﻬﺎ ﻋﻦ ﻃﺮﻳﻖ اﻟﻜﻮد اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬‫#‪C‬‬ ‫ﻛﻮد‬‫;)]4[]1[‪Console.WriteLine(complexarray‬‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫))4()1(‪Console.WriteLine(complexarray‬‬‫وﻫﺬا ﻣﺎ ﻳﻌﻨﻲ اﻟﻌﻨﺼﺮ رﻗﻢ 4 ﻣﻦ اﻟﻤﺼﻔﻮﻓﺔ اﻷوﻟﻰ اﻟﻤﻮﺟﻮدة ﺿﻤﻦ اﻟﻤﺼﻔﻮﻓﺔ ‪complexarray‬‬ ‫6. 5. ارﺳﺎل و اﺳﺘﻘﺒﺎل اﻟﻤﺼﻔﻮﻓﺎت ﻣﻦ و إﻟﻰ اﻟﺪوال‬ ‫ﻳﻤﻜﻨﻚ ﻋﻤﻞ داﻟﺔ ﻟﻄﺒﺎﻋﺔ ﻣﺤﺘﻮﻳﺎت ﻣﺼﻔﻮﻓﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬‫#‪C‬‬ ‫ﻛﻮد‬‫)‪static void print(int[] arr‬‬‫{‬ ‫)++‪for (int i = 0; i < arr.Length; i‬‬ ‫;)]0[‪Console.WriteLine(arr‬‬‫}‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫))(‪Private Sub print(ByVal arr As Integer‬‬ ‫1 - ‪For i As Integer = 0 To arr.Length‬‬ ‫))0(‪Console.WriteLine(arr‬‬ ‫‪Next‬‬‫‪End Sub‬‬‫ﻻ ﺗﻨﺴﻰ ﻃﺒﻌﺎ اﻧﻪ ﻳﺘﻢ اﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ‪ byref‬اﻓﺘﺮاﺿﻴﺎً، ﻟﺬا أي ﺗﻌﺪﻳﻞ ﻓﻲ اﻟﺪاﻟﺔ ﺳﻴﺆﺛﺮ ﻋﻠﻰ‬ ‫ً‬ ‫اﻟﻤﺼﻔﻮﻓﺔ اﻷﺳﺎﺳﻴﺔ.‬ ‫ﻓﻲ ﺣﺎﻟﺔ ﻛﻮن ال ‪ array‬ﻫﻲ ﻣﺎ ﻧﻮد اﻋﺎدﺗﻪ ﻣﻦ اﻟﺪاﻟﺔ ‪ ،return‬ﻧﻜﺘﺐ اﻟﻜﻮد ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬‫#‪C‬‬ ‫ﻛﻮد‬‫)(‪static int[] read‬‬‫{‬ ‫;]3[‪int[] arr = new int‬‬ ‫)++‪for (int i = 0; i < 3; i‬‬ ‫;)(‪arr[i] = Console.Read‬‬ ‫;‪return arr‬‬‫}‬‫321‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)(‪Private Function read() As Integer‬‬ ‫}{ )2(‪Dim arr As Integer() = New Integer‬‬ ‫2 ‪For i As Integer = 0 To‬‬ ‫)(‪arr(i) = Console.Read‬‬ ‫‪Next‬‬ ‫‪Return arr‬‬ ‫‪End Function‬‬ ‫6. 6. ﺧﺼﺎﺋﺺ اﻟﻤﺼﻔﻮﻓﺎت اﻟﺮﺋﻴﺴﻴﺔ‬‫ﺗﺤﺘﻮي اﻟﻤﺼﻔﻮﻓﺎت ﻋﻠﻰ ﺑﻌﺾ ﺧﺼﺎﺋﺺ ودوال ﻗﺪ ﺗﺴﺎﻋﺪك ﻓﻲ اﻟﻌﻤﻞ ﻋﻠﻴﻬﺎ، اﺷﻬﺮﻫﺎ واﻛﺜﺮﻫﺎ‬ ‫اﺳﺘﺨﺪاﻣﺎ :‬ ‫ً‬ ‫اﻻﺳﺘﺨﺪام‬ ‫اﻟﺨﺎﺻﻴﺔ‬ ‫ﺗﺤﺪد ﻃﻮل ﻋﻨﺎﺻﺮ اﻟﻤﺼﻔﻮﻓﺔ‬ ‫‪Length‬‬ ‫ﺗﻘﻮم ﺑﺘﺮﺗﻴﺐ ﻋﻨﺎﺻﺮ اﻟﻤﺼﻔﻮﻓﺔ‬ ‫‪Sort‬‬ ‫‪ Reverse‬ﺗﻘﻮم ﺑﻌﻜﺲ ﺗﺮﺗﻴﺐ ﻋﻨﺎﺻﺮ اﻟﻤﺼﻔﻮﻓﺔ‬ ‫‪Reverse‬‬ ‫ﻟﺘﺤﻮﻳﻞ اﻟﻤﺼﻔﻮﻓﺔ إﻟﻰ ﻣﺘﻐﻴﺮ ﻧﺼﻲ‬ ‫‪ToString‬‬ ‫‪ Rank‬ﺗﺤﺪد ﻋﺪد اﻻﺑﻌﺎد ﻓﻲ اﻟﻤﺼﻔﻮﻓﺔ‬ ‫‪Rank‬‬ ‫اﻟﺠﺪول 7. 1. ﺧﺼﺎﺋﺺ اﻟﻔﺌﺔ ‪Array‬‬ ‫7. ال ‪Enumeration‬‬‫اﺧﺘﺼﺎر ل - ‪ enumerations‬ﺗﺤﺘﻮي ﻋﻠﻰ ﻣﺠﻤﻮﻋﺔ ﻣﻦ اﻟﻌﻨﺎﺻﺮ ﺗﻤﺜﻞ ﺣﺎﻻت وﻗﻴﻢ ﻣﺨﺘﻠﻔﺔ‬ ‫داﺧﻞ اﻟﺒﺮﻧﺎﻣﺞ.‬‫اﺑﺴﻂ ﻣﺜﺎل ﻋﻠﻰ ال ‪ Enum‬ﻫﻮ اﺳﺘﺨﺪاﻣﻬﺎ ﻓﻲ ﺣﺎﻟﺔ ﻟﻤﻮدﻳﻼت اﻟﺴﻴﺎرات ، ﻟﻨﻔﺘﺮض ﻟﺪﻳﻨﺎ‬‫ﺛﻼث اﻧﻮاع ﻣﻦ اﻟﺴﻴﺎرات ، ‪ Nissan ،Toyota‬و اﺧﻴﺮًا ‪ ، FIAT‬ﻟﻮ ﻛﻨﺎ ﻧﻘﻮم ﺑﺘﺨﺰﻳﻨﻬﻢ ﻋﻠﻰ ﺷﻜﻞ‬‫ﻗﻴﻢ 0، 1  و 2 ﻓﻲ ﻗﺎﻋﺪة اﻟﺒﻴﺎﻧﺎت ﻣﺜﻼً، ﻓﺈﻧﻨﺎ ﻻ ﻧﺮﻳﺪ ان ﻧﺠﺒﺮ اﻟﻤﺒﺮﻣﺞ ﻋﻠﻰ ادﺧﺎل رﻗﻢ ﻛﻞ ﺳﻴﺎرة،‬ ‫ﺑﻞ ﻳﻤﻜﻨﻪ ادﺧﺎل اﺳﻤﻬﺎ واﻟﺬي ﺳﻴﺘﻢ ﺗﺮﺟﻤﺘﻪ ﻻﺣﻘﺎ إﻟﻰ اﻟﺮﻗﻢ اﻟﻤﻨﺎﻇﺮ ﻟﻪ.‬ ‫ً‬‫421‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬   ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ C# ‫ﻛﻮد‬ enum cars { toyota = 0, nissan = 1, fiat = 2 } VB.NET ‫ﻛﻮد‬ Enum cars toyota = 0 nissan = 1 fiat = 2 End Enum‫ ﻻﺧﺘﺼﺎر اﻟﻤﺴﺎﺣﺔ اﻳﻀﺎ ، ﻳﻤﻜﻦ‬Enum ‫ﻳﻤﻜﻨﻨﺎ اﻳﻀﺎ ﺗﺤﺪﻳﺪ اﻟﻤﺴﺎﺣﺔ اﻟﺘﻲ ﻳﺘﻢ ﺗﺨﺰﻳﻦ ﻓﻴﻬﺎ ﻋﻨﺼﺮ ال‬ ً ً :‫ ﻛﻤﺜﺎل ﻋﻠﻰ ذﻟﻚ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬byte ‫ﺗﺤﺪﻳﺪ اﻟﻨﻮع‬ C# ‫ﻛﻮد‬ enum cars : byte { toyota = 0, nissan = 1, fiat = 2 } VB.NET ‫ﻛﻮد‬ Enum cars As Byte toyota = 0 nissan = 1 fiat = 2 End Enum125
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬‫اﻵن ﻳﻤﻜﻨﻨﺎ اﺳﺘﺨﺪام اﻻﺳﻤﺎء اﻟﺠﺪﻳﺪة ﻓﻲ اﻟﺒﺮﻣﺠﺔ ﺑﺪﻻ ﻣﻦ اﻻرﻗﺎم أو اﻟﺮﻣﻮز ﺑﻤﺎ ﻳﻜﻔﻞ ﻟﻨﺎ ﺳﻬﻮﻟﺔ‬ ‫ً‬ ‫اﻻﺳﺘﺨﺪام ، ﻟﻨﻔﺘﺮض ﻣﺜﻼ اﻧﻨﺎ ﻧﺮﻳﺪ ﺑﺮﻣﺠﺔ داﻟﺔ ﻟﻌﺮض ﺳﻌﺮ اي ﺳﻴﺎرة ﺑﻨﺎء ﻋﻠﻰ اﺳﻢ اﻟﺴﻴﺎرة.‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪static void printPrice(cars mycar‬‬ ‫{‬ ‫)‪if (mycar == cars.fiat‬‬ ‫;)"000,02"(‪Console.WriteLine‬‬ ‫)‪else if (mycar == cars.nissan‬‬ ‫;)"000,03"(‪Console.WriteLine‬‬ ‫‪else‬‬ ‫;)"000,04"(‪Console.WriteLine‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)‪Private Sub printPrice(ByVal mycar As cars‬‬ ‫‪If mycar = cars.fiat Then‬‬ ‫)"000,02"(‪Console.WriteLine‬‬ ‫‪ElseIf mycar = cars.nissan Then‬‬ ‫)"000,03"(‪Console.WriteLine‬‬ ‫‪Else‬‬ ‫)"000,04"(‪Console.WriteLine‬‬ ‫‪End If‬‬ ‫‪End Sub‬‬ ‫ﻫﻜﺬا ﻧﺠﺪ اﻧﻨﺎ ﻧﺴﺘﺨﺪم اﺳﻤﺎء واﺿﺤﺔ رﻏﻢ ان اﻟﻘﻴﻢ اﻟﻔﻌﻠﻴﺔ اﻟﻤﺨﺰﻧﺔ ﻫﻲ ﻣﻦ ﻧﻮع ‪.byte‬‬‫اوﺿﺢ ﻣﺎ ﻳﻤﻜﻨﻚ ﺗﺨﻴﻠﻪ ﻛﻔﺎﺋﺪة ﻟﻞ ‪ Enum‬ﻫﻲ دوال ‪ API‬اﻟﺨﺎﺻﺔ ﺑﺎﻟﻮﻳﻨﺪوز ، ﻓﻲ اﻟﻮاﻗﻊ اﻧﺖ‬‫ﺗﺮﺳﻞ ﺑﻴﺎﻧﺎت ﻣﺜﻞ 00  ‪ A127X‬ﻟﻠﺪوال ، ﻟﻜﻦ ﻓﻲ اﻟﻮاﻗﻊ ﺗﺠﺪ ﻧﻔﺴﻚ ﺗﺮﺳﻞ ﺑﻌﺾ اﻷﺳﻤﺎء اﻟﻮاﺿﺤﺔ‬‫ﻣﺜﻞ ‪ Local‬ﻛﺪﻻﻟﺔ ﻟﻤﺘﻐﻴﺮ ﻣﺎ ﺑﺪﻻ ﻣﻦ اﻟﺮﻣﻮز اﻟﻤﻌﻘﺪة واﻟﺘﻲ ﺳﻴﺼﻌﺐ ﻋﻠﻴﻚ ﻓﻬﻤﻬﺎ دون وﺟﻮد‬ ‫ً‬ ‫ﻗﺎﻣﻮس ﻟﺘﺮﺟﻤﺔ اﻟﺮﻣﻮز .‬‫621‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ ‫8. اﻟﺘﺮاﻛﻴﺐ ‪Structures‬‬‫ال ‪ Structure‬او ‪ Structs‬ﻫﻲ اﻧﻮاع ﻣﺨﺼﺼﺔ ﻣﻦ اﻟﺒﻴﺎﻧﺎت ﻳﻤﻜﻨﻚ اﻧﺸﺎءﻫﺎ ﺗﺴﺘﻄﻴﻊ ﺣﻤﻞ اي‬‫ﺧﺼﺎﺋﺺ ﻋﻠﻰ ﺷﻜﻞ ﻣﺘﻐﻴﺮات او ﺣﺘﻰ دوال وﺧﻼﻓﻪ ، اﺑﺴﻂ ﻣﺜﺎل ﻋﻠﻰ ‪ Struct‬ﻫﻮ ﻣﺜﺎل اﻟﺴﻴﺎرة ، ﻟﻜﻞ‬‫ﺳﻴﺎرة ﻧﺠﺪ ﻣﻮدﻳﻞ اﻟﺼﻨﻊ واﺳﻢ اﻟﻤﺎرﻛﺔ ورﻗﻢ اﻟﻠﻮﺣﺔ ﻣﺜﻼ ، ﻳﻤﻜﻨﻨﺎ ﻛﺘﺎﺑﺔ ال ‪ Struct‬ﺑﺎﻟﺸﻜﻞ‬ ‫ً‬ ‫اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪struct Car‬‬ ‫{‬ ‫;‪public int carNumber‬‬ ‫;‪public int year‬‬ ‫;‪public string factory‬‬ ‫;}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Structure Car‬‬ ‫‪Public carNumber As Integer‬‬ ‫‪Public year As Integer‬‬ ‫‪Public factory As String‬‬ ‫‪End Structure‬‬ ‫واﻵن ﻋﻨﺪﻣﺎ ﻧﺮﻳﺪ ﺗﻌﺮﻳﻒ ﻧﺴﺨﺔ ﻣﻦ )ﺳﻴﺎرة( ﻓﺈﻧﻨﺎ ﻧﻘﻮم ﺑﺘﻌﻴﻴﻦ ﺧﺼﺎﺋﺼﻬﺎ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)(‪Car ahmedcar = new Car‬‬ ‫;0001 = ‪ahmedcar.carNumber‬‬ ‫;"‪ahmedcar.factory = "Nissan‬‬ ‫;7002 = ‪ahmedcar.year‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)(‪Dim ahmedcar As New Car‬‬ ‫0001 = ‪ahmedcar.carNumber‬‬ ‫"‪ahmedcar.factory = "Nissan‬‬ ‫7002 = ‪ahmedcar.year‬‬‫ﻳﻤﻜﻦ ان ﻳﺤﺘﻮي ال ‪ struct‬ﻋﻠﻰ ﻋﻨﺼﺮ ﻫﻮ اﻵﺧﺮ ﺑﺪوره ‪ ، struct‬ﻟﻮ اﻓﺘﺮﺿﻨﺎ ‪struct‬‬‫ﻟﺮﺧﺼﺔ اﻟﺴﻴﺮ ﻳﺤﺘﻮي ﻋﻠﻰ اﺳﻢ اﻟﻤﺴﺘﺨﺪم واﻟﺴﻨﻮات اﻟﻤﺘﺒﻘﻴﺔ ﻻﻧﺘﻬﺎء اﻟﺮﺧﺼﺔ ﻣﺜﻼ ، ﻓﺴﻴﻜﻮن ذﻟﻚ‬ ‫ً‬ ‫ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬‫721‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬   ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ C# ‫ﻛﻮد‬ struct Licence { public string UserName; public int yearsToFinish; } VB.NET ‫ﻛﻮد‬ Structure Licence Public UserName As String Public yearsToFinish As Integer End Structure :‫واﻵن ﻟﻮ اردﻧﺎ ان ﻧﺠﻌﻞ رﺧﺼﺔ اﻟﺴﻴﺮ ﺟﺰء ﻣﻦ ﺧﺼﺎﺋﺺ اﻟﺴﻴﺎرة ، ﻓﺴﻴﺘﻢ ذﻟﻚ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ struct Car { public int carNumber; public int year; public string factory; public Licence carLicence; }; VB.NET ‫ﻛﻮد‬ Structure Car Public carNumber As Integer Public year As Integer Public factory As String Public carLicence As Licence End Structure :‫وﻟﺘﺤﺪﻳﺪ ﺧﺼﺎﺋﺺ اي ﺳﻴﺎرة ﺳﻨﻜﺘﺐ ﻛﻮد ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ Car ahmedcar = new Car(); ahmedcar.carNumber = 1000; ahmedcar.factory = "Nissan"; ahmedcar.year = 2007; ahmedcar.carLicence.UserName = "Ahmed Gamal"; ahmedcar.carLicence.yearsToFinish = 3;128
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬   ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ VB.NET ‫ﻛﻮد‬ Dim ahmedcar As New Car() ahmedcar.carNumber = 1000 ahmedcar.factory = "Nissan" ahmedcar.year = 2007 ahmedcar.carLicence.UserName = "Ahmed Gamal" ahmedcar.carLicence.yearsToFinish = 3 Struct ‫8. 1. اﻧﺸﺎء اﻟﺪوال داﺧﻞ ال‬،struct ‫ اﻧﺸﺎء داﻟﺔ ﻟﺘﻘﻮم ﺑﺒﻌﺾ اﻟﻌﻤﻠﻴﺎت ﻋﻠﻰ ﻫﺬا ال‬struct ‫ﻳﻤﻜﻨﻨﺎ ﻓﻲ داﺧﻞ اي‬‫ ﻟﺘﺠﺪﻳﺪ رﺧﺼﺔ اﻟﺴﻴﺮ، ﻳﻤﻜﻦ ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ‬renew ‫اﺑﺴﻂ ﻣﺜﺎل ﻋﻠﻰ ذﻟﻚ ﻟﻮ اردﻧﺎ ﻋﻤﻞ داﻟﺔ‬ :‫ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬struct‫ﻛﺘﺎﺑﺔ ال‬ C# ‫ﻛﻮد‬ struct Licence { public string UserName; public int yearsToFinish; public void renew(int periode) { yearsToFinish += periode; } } VB.NET ‫ﻛﻮد‬ Structure Licence Public UserName As String Public yearsToFinish As Integer Public Sub renew(ByVal periode As Integer) yearsToFinish += periode End Sub End Structure .‫وﻫﻜﺬا ﻳﻤﻜﻨﻨﺎ ﺗﺠﺪﻳﺪ ﻓﺘﺮة اﻟﺮﺧﺼﺔ ﻋﻦ ﻃﺮﻳﻖ اﻟﻮﺻﻮل إﻟﻰ ﻫﺬه اﻟﺪاﻟﺔ ﻣﺒﺎﺷﺮة‬129
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬   ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬‫ﻓﻲ اﻟﺘﻄﺒﻴﻘﺎت اﻟﻔﻌﻠﻴﺔ ﻓﻲ اﻟﻌﺎدة ﻻ ﻳﺴﻤﺢ ﻟﻚ ﺑﺎﻟﻮﺻﻮل إﻟﻰ اﻟﻌﻨﺎﺻﺮ ﻣﺒﺎﺷﺮة إﻻ ﻋﻦ ﻃﺮﻳﻖ داﻟﺔ‬‫ ﻣﺜﻼ‬struct ‫ ﻻﻧﺸﺎء ال‬Create ‫وذﻟﻚ ﻟﻤﻨﻊ ادﺧﺎل ﺑﻴﺎﻧﺎت ﻣﻐﻠﻮﻃﺔ ﻣﺜﻼ . ﻳﻤﻜﻦ ﻋﻤﻞ داﻟﺔ‬ً ً‫ ﻳﺘﻢ اﺳﺘﺪﻋﺎء ﻫﺬه اﻟﺪاﻟﺔ ﻟﻤﻠﺊ اﻟﺒﻴﺎﻧﺎت ﺣﻴﺚ ﻟﻦ ﻳﺴﻤﺢ ﻟﻚ‬struct ‫وﺑﻌﺪ اﻧﺸﺎء ﻧﺴﺨﺔ ﻣﻦ ال‬ .‫ﺑﺮؤﻳﺔ ﺑﺎﻗﻲ اﻟﻤﺘﻐﻴﺮات‬ ‫ او اﻟﻤﺸﻴﺪ ، ﺣﻴﺚ ﻳﻤﻜﻨﻚ وﻗﺖ اﻧﺸﺎء ﻧﺴﺨﺔ ﻣﻦ ال‬Constructor ‫ﻫﻨﺎك ﺣﻞ آﺧﺮ ﺑﺎﺳﺘﺨﺪام‬ :‫ ﺗﻤﺮﻳﺮ اﻟﺒﻴﺎﻧﺎت اﻟﻤﻄﻠﻮﺑﺔ ، ﻳﺘﻢ ﻛﺘﺎﺑﺔ اﻟﻤﺸﻴﺪ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬struct 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; } }; VB.NET ‫ﻛﻮد‬ 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 ‫ ﺑﺤﻴﺚ ﻻ ﻳﻤﻜﻦ اﻟﻮﺻﻮل ﻟﻪ ﺧﺎرج ال‬private ‫ﻻﺣﻆ اﻧﻨﺎ ﺣﻮﻟﻨﺎ اﻟﻮﺻﻮل إﻟﻰ اﻟﻤﺘﻐﻴﺮات ﻟﻴﻜﻮن‬‫ ﻟﺬا ﻻ ﺗﺘﻌﺠﻞ‬OOP ‫، ﻣﻌﺮﻓﺎت اﻟﻮﺻﻮل ﺳﺘﻜﻮن اﺣﺪ ﻣﻮاﺿﻴﻌﻨﺎ ﺣﻴﻨﻤﺎ ﻧﺪﺧﻞ ﻓﻲ ﻋﺎﻟﻢ ال‬struct130
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ ‫وﻟﻜﻦ ﻳﻜﻔﻲ ان ﺗﻌﻠﻢ ان ‪ public‬ﺗﺠﻌﻞ ﻗﺎﺑﻠﻴﺔ اﻟﻮﺻﻮل ﻣﻦ اي ﻣﻜﺎن إﻟﻰ اﻟﻤﺘﻐﻴﺮ او اﻟﺪاﻟﺔ ، اﻣﺎ‬ ‫‪ private‬ﻓﻼ ﻳﻤﻜﻦ اﻟﻮﺻﻮل ﻟﻬﺎ إﻻ ﻣﻦ داﺧﻞ ال ‪.struct‬‬ ‫9. اﻷﻧﻮاع ‪ Value‬و اﻷﻧﻮاع ‪Reference‬‬‫ﻟﻮ ﻋﺪﻧﺎ ﻣﺮة أﺧﺮى إﻟﻰ درس اﻧﻮاع اﻟﻤﺘﻐﻴﺮات ، ﺳﻨﺠﺪ ان ﻣﻌﻈﻢ اﻧﻮاع اﻟﺒﻴﺎﻧﺎت ﻣﺸﺘﻘﺔ‬‫ﻣﻦ ‪ ،Value Type‬ﻣﻌﻨﻰ ان ﻫﺬه اﻷﻧﻮاع ﻣﺸﺘﻘﺔ ﻣﻦ ‪ Value Type‬ان ﻛﻞ ﻣﺘﻐﻴﺮ ﻣﻨﻬﺎ ﻳﻤﺜﻞ ﻧﻔﺴﻪ، ﻓﻠﻮ‬ ‫اﻓﺘﺮﺿﻨﺎ ﻣﺜﺎﻻ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;5=‪int x‬‬ ‫;‪int y=x‬‬ ‫;81=‪y‬‬ ‫;)‪Console.WriteLine(x‬‬ ‫;)‪Console.WriteLine(y‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫5 = ‪Dim x As Integer‬‬ ‫‪Dim y As Integer = x‬‬ ‫81 = ‪y‬‬ ‫)‪Console.WriteLine(x‬‬ ‫)‪Console.WriteLine(y‬‬‫ﺳﻨﺠﺪ ان ﻛﻼ ﻣﻦ ‪ x‬و ‪ y‬ﻟﻪ ﻗﻴﻤﺔ ﺧﺎﺻﺔ ﺑﻪ ، ﺑﺮﻏﻢ اﻧﻨﺎ ﺳﺎوﻳﻨﺎ ﺑﻴﻨﻬﻢ ﻓﻲ اﻟﺒﺪاﻳﺔ ، اﻟﺴﺒﺐ اﻧﻨﺎ ﻓﻲ‬ ‫ً‬ ‫ﺟﻤﻠﺔ ‪ y=x‬ﻓﻬﻢ اﻟﻤﺘﺮﺟﻢ ان ﻳﻨﺸﺄ ﻣﺘﻐﻴﺮ ‪ y‬ﻳﺤﺼﻞ ﻋﻠﻰ ﻗﻴﻤﺔ ‪. x‬‬ ‫ﻧﻔﺲ ﻫﺬا اﻟﻨﻈﺎم ﻳﻨﻄﺒﻖ ﻋﻠﻰ اﻟﻤﺘﻐﻴﺮات اﻻﺳﺎﺳﻴﺔ ، ﻋﻠﻰ ال ‪ struct‬اﻳﻀﺎ...‬ ‫ً‬‫اﻷﻧﻮاع ﻣﻦ ﻧﻮع  ‪ Reference Types‬ﻣﺜﻞ ال ‪ Class‬ﻻ ﻳﻨﻄﺒﻖ ﻋﻠﻴﻬﺎ اﻟﻤﺜﺎل ، ﻟﻨﻔﺘﺮض ﻣﺜﺎل اﻟﺴﻴﺎرة‬ ‫ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬‫131‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬   ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ C# ‫ﻛﻮد‬ class car { int carNumber; string carName; } VB.NET ‫ﻛﻮد‬ Class car Private carNumber As Integer Private carName As String End Class :‫، ﺳﻴﻜﻮن اﻟﻤﺜﺎل ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬int ‫واﻵن ﺳﻨﻜﺘﺐ ﻧﻔﺲ اﻟﻤﺜﺎل اﻟﺴﺎﺑﻖ ﻣﻊ ال‬ C# ‫ﻛﻮد‬ Car x = new Car(); x.carNumber = 1; Car y = x; Console.WriteLine (x == y); VB.NET ‫ﻛﻮد‬ Dim x As New Car() x.carNumber = 1 Dim y As Car = x Console.WriteLine(x = y) ‫ ﻳﻤﻜﻨﻚ اﻟﺘﻌﺪﻳﻞ ﻋﻠﻴﻬﺎ ﻓﺄﻧﺖ ﻣﺨﻄﺎ، إذ ان‬Car ‫ ﻳﺤﺘﻮي ﻋﻠﻰ ﻧﺴﺨﺔ ﻣﻦ‬y ‫ﻟﻮ ﻛﻨﺖ ﺗﻈﻦ ان اﻟﻤﺘﻐﻴﺮ‬ ،‫ ﻳﺸﻴﺮون ﻟﻨﻔﺲ اﻟﻤﺘﻐﻴﺮ ، وﺑﺎﻟﺘﺎﻟﻲ ﻓﺄي ﺗﻌﺪﻳﻞ ﻓﻲ اﺣﺪﻫﻤﺎ ﺳﻴﺘﺴﺒﺐ ﻓﻲ ﺗﻌﺪﻳﻞ ﻟﻶﺧﺮ‬y ‫ و‬x ‫اﻟﻤﺘﻐﻴﺮ‬ :‫ﻳﻤﻜﻨﻚ اﻟﺘﺄﻛﺪ ﻣﻦ ذﻟﻚ ﻣﻦ ﺧﻼل ﻛﻮد ﻣﺜﻞ اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ Car x = newCar(); Car y = x; x.carNumber=1; y.carNumber =2; Console.WriteLine (x.carNumber); Console.ReadKey(); 132
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫)(‪Dim x As Car = newCar‬‬‫‪Dim y As Car = x‬‬‫1 = ‪x.carNumber‬‬‫2 = ‪y.carNumber‬‬‫)‪Console.WriteLine(x.carNumber‬‬‫)(‪Console.ReadKey‬‬‫ﻟﻌﻤﻞ ﻧﺴﺨﺔ ﺣﻘﻴﻘﺔ ﻣﻦ ال ‪ Class‬اﻟﻤﺴﻤﻰ ‪ Car‬ﻻ ﺑﺪ ﻣﻦ ﺗﻄﺒﻴﻖ ‪ ،Clone‬ﻗﻢ ﺑﺠﻌﻞ ‪Car‬‬ ‫‪ Class‬ﻳﻄﺒﻖ ال ‪ ICloneable Interface‬وﻗﻢ ﺑﻜﺘﺎﺑﺔ داﻟﺔ ال ‪.Clone‬‬ ‫01. اﻟﻤﻘﺎرﻧﺎت‬‫ﻟﻨﻌﺪ ﻣﺮة أﺧﺮى ﻟﻨﻘﻄﺔ اﻟﺒﺪاﻳﺔ ، ﺣﻴﺚ ﻳﺴﺘﺨﺪم اﻏﻠﺐ اﻟﻤﺒﺮﻣﺠﻴﻦ اﻟﻤﻌﺎﻣﻞ = أو اﻟﻤﻌﺎﻣﻞ == ﻓﻲ‬ ‫#‪ C‬ﻟﻠﻤﻘﺎرﻧﺔ، اﺑﺴﻂ اﻣﺜﻠﺔ ذﻟﻚ:‬‫#‪C‬‬ ‫ﻛﻮد‬‫)‪if (x == y‬‬‫{‬‫}‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫‪if x = y Then‬‬‫‪End if‬‬‫ﺗﻜﻮن اﻟﻘﻴﻤﺔ اﻟﻤﺤﺼﻠﺔ ‪ True‬ﻓﻲ ﺣﺎﻟﺔ اﻟﺘﺴﺎوي ﻓﻴﻤﺎ ﺗﻜﻮن ‪ False‬ﻓﻲ ﺣﺎﻟﺔ ﻋﺪم اﻟﺘﺴﺎوي ،‬‫وﻧﻘﺼﺪ ﺑﺎﻟﺘﺴﺎوي ﻫﻨﺎ اﻟﺘﺴﺎوي اﻟﻜﺎﻣﻞ ﻣﺜﻼ : 5=5 او 7=7 أو "‪ ،"Ahmed"="Ahmed‬وﻟﻜﻦ‬ ‫ً‬ ‫ﻫﺬا ﻳﻨﻄﺒﻖ ﻓﻘﻂ ﻋﻠﻰ اﻻﻧﻮاع اﻟﺒﺴﻴﻄﺔ.‬ ‫ﻣﻼﺣﻈﺔ‬ ‫اﻷﻧﻮاع اﻟﺒﺴﻴﻄﺔ ﻫﻲ اﻻﻧﻮع ﻣﺜﻞ ‪ Int , Long , String‬وﻏﻴﺮﻫﺎ...‬ ‫ﺳﻨﻮاﺻﻞ ﺷﺮﺣﻨﺎ ﻣﻊ اﻟﻤﺜﺎل اﻟﺘﺎﻟﻲ اﻳﻀﺎ:‬ ‫ً‬‫331‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬   ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬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.NET ‫ﻛﻮد‬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) :‫ اﻳﻀﺎ ، وﻟﻜﻦ ﻣﺎذا ﻟﻮ اﻛﻤﻠﻨﺎ اﻟﻜﻮد ﺑﺎﻷﺳﻄﺮ اﻟﺘﺎﻟﻴﺔ‬True ‫ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﺳﺘﻈﻞ اﻟﻨﺘﻴﺠﺔ‬ ًC# ‫ﻛﻮد‬object c = a;object d = b;Console.WriteLine(c == d);VB.NET ‫ﻛﻮد‬Dim c As Object = aDim d As Object = bConsole.WriteLine(c = d)‫ ، اﻟﺤﻞ ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﺑﺎﺳﺘﺨﺪام‬False ‫اﻟﺴﻄﺮ اﻟﺴﺎﺑﻖ ﺳﻴﺨﻴﺐ ﻇﻨﻚ ﻟﻼﺳﻒ ، ﻹن اﻟﻨﺎﺗﺞ ﺳﻴﻜﻮن‬ Equals ‫اﻟﻤﻌﺎﻣﻞ‬ C# ‫ﻛﻮد‬Console.WriteLine(c.Equals(d));VB.NET ‫ﻛﻮد‬Console.WriteLine(c.Equals(d)) :‫ ﻣﺜﻼ ، ﻟﻨﻔﺘﺮض اﻟﻤﺜﺎل اﻟﺘﺎﻟﻲ‬Structs ‫ ﻟﻠﻤﻘﺎرﻧﺔ ﺑﻴﻦ ال‬Equals ‫اﺳﺘﺨﺪام آﺧﺮ ﻟﻠﻤﻌﺎﻣﻞ‬ ًC# ‫ﻛﻮد‬struct car{ public int carNumber;};134
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬   ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ VB.NET ‫ﻛﻮد‬ public structure Car public carNumber As Integer End structure :‫واﻵن، ﻟﻮ ﻗﻤﻨﺎ ﺑﺘﻌﺮﻳﻒ اﻟﻤﺘﻐﻴﺮات اﻟﺘﺎﻟﻴﺔ‬ C# ‫ﻛﻮد‬ Car x = new Car(); x.carNumber=1; Car y=x; Console.WriteLine (x==y); VB.NET ‫ﻛﻮد‬ Dim x As New Car() x.carNumber = 1 Dim y As Car = x Console.WriteLine(x = y)‫ ؟؟؟ ﻟﻼﺳﻒ ﻫﻲ ﺣﺘﻰ‬True ‫ﻣﺎ ﻫﻮ اﻟﻨﺎﺗﺞ اﻟﺬي ﺗﺘﻮﻗﻌﻪ، اﻟﻤﻔﺘﺮض ان ﺗﻜﻮن اﻟﺮﺳﺎﻟﺔ اﻟﻤﻄﺒﻮﻋﺔ ﻫﻲ‬ .‫ ﻹن ﻫﺬا ﺳﻴﻌﻄﻴﻚ ﺧﻄﺄ‬False ‫ﻟﻴﺴﺖ‬ :‫ ﺑﺎﻟﻄﺮﻳﻘﺔ اﻟﺘﺎﻟﻴﺔ‬Equals ‫اﻟﺤﻞ اﻟﺼﺤﻴﺢ ﻫﻮ ﺑﺎﺳﺘﺨﺪام اﻟﻤﻌﺎﻣﻞ‬ C# ‫ﻛﻮد‬ Console.WriteLine (x.Equals(y)); VB.NET ‫ﻛﻮد‬ Console.WriteLine(x.Equals(y)) :‫ ، ﻳﻤﻜﻦ اﺳﺘﺨﺪام == اﻳﻀﺎ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬Classes ‫ﻓﻲ ﺣﺎﻟﺔ ﺗﻌﺮﻳﻒ‬ ً C# ‫ﻛﻮد‬ Console.WriteLine (Class1==Class2); VB.NET ‫ﻛﻮد‬ Console.WriteLine(Class1 = Class2)135
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ ‫أو ‪ Equals‬ﻛﻤﺎ ﻓﻲ اﻟﻤﺜﺎل اﻟﺴﺎﺑﻖ، ﻫﻞ ﺗﻌﺮف ﻟﻤﺎذا ﻳﻜﻮن‬ ‫اﻟﻨﺎﺗﺞ داﺋﻤﺎ ‪ True‬؟‬ ‫ً‬ ‫اﻻﺟﺎﺑﺔ اﻟﻤﻨﻄﻘﻴﺔ ﻟﻬﺬا اﻟﻤﻮﺿﻮع ﻫﻲ أﻧﻚ ﺳﺘﺨﺒﺮﻧﻲ ان‬ ‫اﻟﻜﺎﺋﻨﺎن ﻳﺸﻴﺮان ﻟﻨﻔﺲ اﻟﻤﻜﺎن ﻓﻲ اﻟﺬاﻛﺮة‬ ‫ﻟﺬا ﻛﺎن اﻟﻨﺎﺗﺞ ‪ True‬ﺑﺎﻟﺸﻜﻞ اﻟﻤﻘﺎﺑﻞ‬ ‫وﻫﺬا ﺻﺤﻴﺢ ، ﻟﻨﻔﺘﺮض اﻟﻤﺜﺎل اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)(‪Car x = new Car‬‬ ‫;)(‪Car y = new Car‬‬ ‫;1=‪x.carNumber‬‬ ‫;1 = ‪y.carNumber‬‬ ‫;)‪Console.WriteLine (x==y‬‬ ‫;)(‪Console.ReadKey‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)(‪Dim x As New Car‬‬ ‫)(‪Dim y As New Car‬‬ ‫1 = ‪x.carNumber‬‬ ‫1 = ‪y.carNumber‬‬ ‫)‪Console.WriteLine(x = y‬‬ ‫)(‪Console.ReadKey‬‬‫ﺳﺘﻜﻮن اﻟﻨﺘﻴﺠﺔ ﻫﻲ ... ‪ False‬ﺑﺮﻏﻢ ان اﻟﺨﺼﺎﺋﺺ اﻟﺪاﺧﻠﻴﺔ ﻟﻬﻤﺎ واﺣﺪة ، اﻟﺤﻞ ﺑﻜﺘﺎﺑﺔ داﻟﺔ‬ ‫ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)2‪bool isthesame(Car c1, Car c‬‬ ‫{‬ ‫)‪if (c1.carNumber == c2.carNumber‬‬ ‫;‪return true‬‬ ‫;‪return false‬‬ ‫}‬‫631‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪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‬‬ ‫ﻟﻜﻦ ﻣﺎذا ﻟﻮ ﻛﻨﺎ ﻧﺮﻏﺐ ﻓﻲ ﻋﻤﻞ ﻧﺴﺨﺔ ﺟﺪﻳﺪة ﻣﻦ اﻟﻤﺘﻐﻴﺮ ؟‬ ‫ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﻧﺴﺘﺨﺪم ﻣﺒﺪأ ‪ Clone‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)1‪Car doCopy(Car c‬‬ ‫{‬ ‫;)(‪Car newCar = new Car‬‬ ‫;‪newCar.carNumber = c1.carNumber‬‬ ‫//‬ ‫//‬ ‫;‪return newCar‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Private Function doCopy(ByVal c1 As Car) As Car‬‬ ‫)(‪Dim newCar As New Car‬‬ ‫‪newCar.carNumber = c1.carNumber‬‬ ‫‬ ‫‬ ‫‪Return newCar‬‬ ‫‪End Function‬‬‫ﻓﻲ ﻛﺜﻴﺮ ﻣﻦ اﻟﻌﻨﺎﺻﺮ اﻻﺳﺎﺳﻴﺔ ﺗﺠﺪ اﻟﺪاﻟﺔ ‪ Clone‬ﻣﻮﺟﻮدة ﺑﺼﻮرة اﻓﺘﺮاﺿﻴﺔ ، اي ﻓﺌﺔ ﻣﺸﺘﻘﺔ ﻣﻦ‬‫اﻟﻮاﺟﻬﺔ ‪ ICloneable‬ﺳﺘﺠﺪ ﻫﺬه اﻟﺪاﻟﺔ ﺟﺎﻫﺰة ﻟﻼﺳﺘﺨﺪام ﻣﺒﺎﺷﺮة، ﻟﻮ ﻛﻨﺖ اﻧﺖ ﻣﻦ ﺗﻘﻮم‬‫ﺑﺒﺮﻣﺠﺔ اﻟﻔﺌﺔ ‪ Class‬وﻗﻤﺖ ﺑﺎﺷﺘﻘﺎﻗﻬﺎ ﻣﻦ اﻟﻔﺌﺔ اﻟﺴﺎﺑﻘﺔ ﻓﺴﺘﺠﺪ اﻟﺪاﻟﺔ ‪ Clone‬ﻣﻮﺟﻮدة ﻟﺘﻘﻮم‬‫ﺑﺒﺮﻣﺠﺘﻬﺎ ﺑﺤﻴﺚ ﺗﻜﻮن اﻟﻔﺌﺔ اﻟﺨﺎﺻﺔ ﺑﻚ ﻋﻠﻰ اﻟﻤﻌﺎﻳﻴﺮ اﻟﻘﻴﺎﺳﻴﺔ ، ﺣﻴﺚ ﻳﺴﺘﻄﻴﻊ اي ﻣﺴﺘﺨﺪم‬ ‫ﻟﻔﺌﺘﻚ ﻣﻦ ﻋﻤﻞ ‪ Clone‬ﻟﻬﺎ ﻣﺒﺎﺷﺮة.‬ ‫11. ‪Nullable Types‬‬‫ﻓﻲ ﻋﺮف اﻟﻤﺘﻐﻴﺮات اﻟﺘﻘﻠﻴﺪﻳﺔ ﺗﻌﺪ اﻟﻘﻴﻤﺔ ‪ null‬ﻏﻴﺮ ﻣﻘﺒﻮﻟﺔ اﻃﻼﻗﺎً، ﻓﺎﻟﻤﺘﻐﻴﺮ ﻣﻦ‬‫ﻧﻮع ‪ Boolean‬ﻣﺜﻼ ﻻ ﺑﺪ ان ﻳﺤﺘﻮي ﻋﻠﻰ ‪ True‬أو ‪ ، False‬اﻟﻤﺘﻐﻴﺮ ‪ Short‬ﻻ ﺑﺪ ان ﻳﺤﺘﻮي‬ ‫ً‬‫731‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ ‫ﻋﻠﻰ ارﻗﺎم ﻣﺎ ﺑﻴﻦ اﻟﺼﻔﺮ و 76723 ﻣﺜﻼ ... وﻫﻜﺬا ، ﻓﻲ ﺣﻴﻦ ﻛﺎﻧﺖ اﻟﻘﻴﻢ اﻟﻨﺼﻴﺔ ﻣﺜﻼ ‪String‬‬ ‫ً‬ ‫ً‬ ‫ﺗﺴﺘﻄﻴﻊ اﺳﺘﻴﻌﺎب اﻟﻘﻴﻤﺔ ‪ null‬ﻹﻧﻬﺎ ﻣﻦ ﻧﻮع ‪.reference‬‬‫ﻟﻜﻨﻨﺎ ﻓﻲ ﺑﻌﺾ اﻻﺣﻴﺎن ﻧﻀﻄﺮ ﻷن ﻳﺤﻤﻞ ﻣﺘﻐﻴﺮ ﻣﻨﻄﻘﻲ ‪ Boolean‬ﻗﻴﻤﺔ )ﻻ ﻗﻴﻤﺔ - ‪(null‬‬‫ﺑﻤﻌﻨﻰ اﻧﻨﺎ ﻏﻴﺮ ﻗﺎدرﻳﻦ ﻋﻠﻰ ﺗﺤﺪﻳﺪ ﻓﻴﻤﺎ إذا ﻛﺎن ‪ True‬أو ‪ ، False‬اﺑﺴﻂ اﻣﺜﻠﺔ ذﻟﻚ ﻫﻲ‬‫اﻟﻤﺸﻜﻠﺔ اﻟﺘﻘﻠﻴﺪﻳﺔ اﻟﺘﻲ ﺗﻮاﺟﻪ اﻏﻠﺐ ﻣﺒﺮﻣﺠﻲ ﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت ﻓﻲ ﺣﺎﻟﺔ ﻋﺪم ادﺧﺎل اﻟﻤﺴﺘﺨﺪم ﻟﻘﻴﻤﺔ‬‫ﻓﻲ ﺣﻘﻞ ﻣﺎ وﻟﻴﻜﻦ ﺣﻘﻞ )ﻣﺘﺰوج(، وﻟﻨﻔﺮض ان اﻟﻤﺴﺘﺨﺪم ﻟﻢ ﻳﺤﺪد ﻛﻮن اﻟﺸﺨﺺ ﻣﺘﺰوﺟﺎ ﻣﻦ‬ ‫ً‬‫ﻋﺪﻣﻪ ، ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﺳﻴﻈﻞ اﻟﺤﻘﻞ ﻳﺤﺘﻔﻆ ﺑﻘﻴﻤﺔ ‪ ،null‬وﻫﻮ ﻣﺎ ﻛﺎن ﻳﺴﺘﻠﺰم ﻋﻤﻞ ‪Check‬‬ ‫ﻋﻠﻰ اﻧﻬﺎ ﻟﻴﺴﺖ ‪ null‬ﻗﺒﻞ وﺿﻌﻬﺎ ﻓﻲ اي ﻣﺘﻐﻴﺮ ﻣﻦ ﻧﻮع ‪ bool‬ﻣﺜﻼ.‬ ‫ً‬‫ﻟﻜﻦ وﻣﻊ اﻻﺻﺪارة اﻟﺜﺎﻧﻴﺔ ﻣﻦ ‪ .net  Framework‬اﺻﺒﺢ ﺑﺎﻻﻣﻜﺎن ﺗﻌﺮﻳﻒ ﻣﺘﻐﻴﺮ ﻣﺨﺼﺺ ﻟﻴﺴﻤﺢ‬ ‫ﺑﺘﻘﺒﻞ اﻟﻘﻴﻤﺔ ‪ null‬اﺿﺎﻓﺔ ﻟﻠﻘﻴﻢ اﻻﺳﺎﺳﻴﺔ ﻟﻪ ، ﻛﻤﺎ ﻓﻲ اﻟﻤﺜﺎل اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;‪bool? ismarried = null‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Dim ismarried As System.Nullable(Of Boolean) = Nothing‬‬‫ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﻳﻤﻜﻨﻨﺎ اﺳﻨﺎده ﻟﻘﺮاءة ﻗﻴﻤﺔ ﻣﺒﺎﺷﺮة ﻣﻦ ﻗﺎﻋﺪة اﻟﺒﻴﺎﻧﺎت دون اﻟﻘﻠﻖ ﻣﻦ ﻛﻮن اﻟﻘﻴﻤﺔ‬ ‫اﻟﺤﺎﻟﻴﺔ ﻫﻲ‪.null‬‬ ‫ﻫﻨﺎك ﻋﺪة ﻃﺮق اﺧﺮى ﻟﺘﻌﺮﻳﻒ ﻣﺘﻐﻴﺮ ﻳﻘﺒﻞ ‪ null‬ﻣﺜﻞ اﻟﻄﺮﻳﻘﺔ اﻟﺘﺎﻟﻴﺔ اﻳﻀﺎ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;‪Nullable<bool> nullableBool = null‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Dim ismarried As System.Nullable(Of Boolean) = Nothing‬‬‫ﺣﻴﺚ ان ? ﻫﻲ ﻓﻌﻠﻴﺎ اﺧﺘﺼﺎر ﻟﻞ ‪ Generic‬اﻟﻤﺴﻤﻰ >‪ ، System.Nullable<T‬وﻫﻮ ﻣﺎ ﺳﻨﺘﻌﺮف‬ ‫ً‬ ‫ﻋﻠﻰ ﻣﻌﻨﺎه ﻓﻲ أﺟﺰاء ﻗﺎدﻣﺔ ﻣﻦ اﻟﻜﺘﺎب. وﺑﻨﻔﺲ اﻟﻄﺮﻳﻘﺔ ﻓﻴﻤﺎ ﻟﻮ اردﻧﺎ ﺗﻌﺮﻳﻒ داﻟﺔ ﻳﻜﻮن ال‬ ‫‪ return‬ﻟﻬﺎ ‪ Nullable‬ﻓﺴﻴﻜﻮن ذﻟﻚ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬‫831‬
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬   ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ C# ‫ﻛﻮد‬ public bool? functionName() { } VB.NET ‫ﻛﻮد‬ Public Function functionName() As System.Nullable(Of Boolean) End Function Nullable ‫11. 1. ﺧﺼﺎﺋﺺ ال‬‫ واﻟﺘﻲ ﺗﺤﺪد ﻓﻴﻤﺎ إذا ﻛﺎن اﻟﻤﺘﻐﻴﺮ ﺑﻪ ﻗﻴﻤﺔ‬HasValue ‫ ﻫﻲ ﺧﺎﺻﻴﺔ‬nullable ‫اﻫﻢ ﺧﺼﺎﺋﺺ ال‬ :‫ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬null ‫ام اﻧﻪ ﻳﺤﺘﻔﻆ ﺑﻘﻴﻤﺔ‬ C# ‫ﻛﻮد‬ if (ismarried.HasValue) { } VB.NET ‫ﻛﻮد‬ If ismarried.HasValue Then End If :‫ﻳﻤﻜﻦ ﻛﺘﺎﺑﺘﻬﺎ ﺑﺎﺳﺘﺨﺪام وﺳﺎﺋﻞ اﻟﻤﻘﺎرﻧﺔ اﻳﻀﺎ != أو >< ﻓﻲ اﻟﻔﻴﺠﻮال ﺑﻴﺴﻚ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ ً C# ‫ﻛﻮد‬ if (ismarried != null) VB.NET ‫ﻛﻮد‬ If ismarried <> Nothing Then139
  • ‫ﻣﻜﻮﻧﺎت اﻟﻠﻐﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺴﺎﺑﻊ‬ ‫ﻣﻼﺣﻈﺔ‬ ‫ﻻ ﺗﻨﺲ أن ‪ nothing‬ﺧﺎﺻﺔ ﺑﺎﻟﻔﻴﺠﻮال ﺑﻴﺴﻚ ﺑﺪﻻ ﻣﻦ ‪ null‬ﻓﻲ اﻟﺴﻲ ﺷﺎرب‬ ‫ً‬ ‫11. 2. اﻟﻤﻌﺎﻣﻞ ؟؟‬‫ﻳﻤﻜﻦ اﺳﺘﺨﺪام اﻟﻤﻌﺎﻣﻞ ؟؟ ﻣﻊ اﻟﻘﻴﻢ ال ‪ nullable‬ﻟﻜﻲ ﻧﺨﺒﺮه ﺑﻮﺿﻊ ﻗﻴﻤﺔ ﻣﺎ ﻓﻲ ﺣﺎﻟﺔ‬‫وﺟﻮدﻫﺎ ب ‪ ،null‬ﻟﻨﻔﺘﺮض ﻣﺜﺎل ﺣﺎﻟﺔ اﻟﺰواج اﻟﺴﺎﺑﻖ ، وﺳﻨﻔﺘﺮض ان اي ﺷﺨﺺ ﻟﻢ ﻳﻘﻢ ﺑﺎدﺧﺎل‬‫ﺑﻴﺎﻧﺎت اﻟﺰواج ﻓﻬﻮ ﺷﺨﺺ اﻋﺰب ﺑﻤﻌﻨﻰ ان اﻟﻘﻴﻤﺔ ﺳﺘﺼﺒﺢ ‪ False‬ﻣﺒﺎﺷﺮة، ﺳﻨﻘﻮم ﺑﻜﺘﺎﺑﺔ اﻟﻜﻮد‬ ‫اﻟﺘﺎﻟﻲ ﻣﻦ اﺟﻞ ذﻟﻚ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;‪int? ismarried = returnvaluefromdatabase() ?? false‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Dim ismarried As System.Nullable(Of Integer) = IIf(returnvaluefromdatabase() Is‬‬ ‫)(‪Nothing, [False], returnvaluefromdatabase‬‬‫041‬
  • 141
  • ‫اﻟﺒﺎب‬ ‫8‬ ‫اﻟﻔﺌﺎت وﻣﻘﺪﻣﺔ إﻟﻰ‬ ‫اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬‫241‬
  • 143
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ ‫1. ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﻔﺌﺎت ‪Classes‬‬‫ﻛﻤﺎ ﻻﺣﻈﻨﺎ ﻓﻲ دروﺳﻨﺎ اﻟﺴﺎﺑﻘﺔ ، ﻓﺈن اﻟﺒﺮﻧﺎﻣﺞ اﻟﻤﻨﺸﺄ ﺗﺤﺖ ‪ Console Application‬ﻳﺤﺘﻮي ﻋﻠﻰ‬‫ﻓﺌﺔ واﺣﺪة ﻣﺴﻤﺎه ﺑﺎﺳﻢ ‪ Class Program‬ﺗﺤﺘﻮي ﺑﺪاﺧﻠﻬﺎ ﻋﻠﻰ دوال وﻣﺘﻐﻴﺮات واﺟﺮاءات وﻃﺮق ...‬ ‫ﻓﻲ اﻟﻮاﻗﻊ ﻓﺎﻟﺒﻨﻴﺔ اﻻﺳﺎﺳﻴﺔ ﻷي ﺑﺮﻧﺎﻣﺞ ﻳﻄﺒﻖ ﻣﺒﺎدئ ‪ OOP‬ﻫﻮ اﻟﻔﺌﺔ ‪.Class‬‬‫ﻳﻤﻜﻦ ان ﻳﺤﺘﻮي اﻟﺒﺮﻧﺎﻣﺞ ﻋﻠﻰ ﻋﺪة ﻓﺌﺎت ، وﻳﻤﻜﻦ ان ﺗﺤﺘﻮي اﻟﻔﺌﺔ اﻳﻀﺎ ﻋﻠﻰ ﻋﺪة ﻓﺌﺎت ﺑﺪاﺧﻠﻪ ، ﻓﻲ‬ ‫ً‬ ‫ﺣﺎﻟﺔ رﻏﺒﺘﻚ ﻓﻲ ﻋﻤﻞ ‪ Class‬ﻣﻨﻔﺼﻞ ﻳﻤﻜﻨﻚ اﺿﺎﻓﺔ ‪ New Class‬ﻣﻦ ‪.Project‬‬‫ﻳﺘﻢ ﺗﻌﺮﻳﻒ اﻟﻔﺌﺔ ﺑﺎﺳﺘﺨﺪام اﻟﻜﻠﻤﺔ اﻟﻤﺤﺠﻮزة ‪ class‬وﻣﻦ ﺛﻢ اﺳﻤﻪ ، ﻳﺘﻢ ﺗﻌﺮﻳﻒ ﻣﻜﻮﻧﺎﺗﻪ ﺑﻴﻦ }{‬‫ﻓﻲ اﻟﺴﻲ ﺷﺎرب أو ﻣﻦ ﺑﻌﺪ ﺟﻤﻠﺔ اﻟﺘﻌﺮﻳﻒ ﺣﺘﻰ ‪ End Class‬ﻓﻲ ‪ ،VB.net‬ﺳﻨﻘﻮم ﺑﺎدراج ﻓﺌﺔ ﺟﺪﻳﺪة‬ ‫وﻧﺴﻤﻴﻬﺎ ﺑﺎﺳﻢ ‪ ،Person‬ﺳﻨﺠﺪ اﻟﻜﻮد اﻟﺘﺎﻟﻲ ﻣﻮﺟﻮدًا ﺑﺼﻮرة اﻓﺘﺮاﺿﻴﺔ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫4‪namespace ConsoleApplication‬‬ ‫{‬ ‫‪class Person‬‬ ‫{‬ ‫}‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫4‪Namespace ConsoleApplication‬‬ ‫‪Class Person‬‬ ‫‪End Class‬‬ ‫‪End Namespace‬‬‫اﻟﺠﺰء اﻷول اﻟﺬي ﻳﺤﺪد ال ‪ namespace‬ﺿﺮوري ، ﺣﻴﺚ ﻳﻌﻨﻲ ﻫﺬا ان ﺟﻤﻴﻊ اﻟﻔﺌﺎت ‪Classes‬‬‫اﻟﻤﻮﺟﻮدة ﺗﺤﺖ ﻧﻔﺲ ال ‪ namespace‬ﻳﻤﻜﻨﻬﺎ رؤﻳﺔ ﺑﻌﻀﻬﺎ اﻵﺧﺮ ، ﻟﺬا ﺳﻨﺘﻤﻜﻦ ﻣﻦ اﻟﺘﻌﺎﻣﻞ ﻣﻊ‬ ‫اﻟﻔﺌﺔ اﻟﺠﺪﻳﺪة ﻣﻦ ﺧﻼل ‪ main‬اﻟﺨﺎﺻﺔ ﺑﻨﺎ ﻓﻲ اﻟﻔﺌﺔ اﻻﺳﺎﺳﻴﺔ اﻟﻤﺴﻤﺎه ‪.Program‬‬‫اﺑﺴﻂ ﻣﻜﻮﻧﺎت أي ﻓﺌﺔ ‪ Class‬ﻫﻲ اﻟﻤﺘﻐﻴﺮات ، ﻳﻤﻜﻨﻨﺎ ﻣﺜﻼ اﺿﺎﻓﺔ ﺑﻴﺎﻧﺎت اﻻﺳﻢ اﻷول واﻷﺧﻴﺮ‬ ‫ً‬ ‫واﻟﻌﻤﺮ داﺧﻞ اﻟﻔﺌﺔ ‪ Class‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬‫441‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬   ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ C# ‫ﻛﻮد‬ class Person { public string FirstName; public string LastName; public int Age; } VB.NET ‫ﻛﻮد‬ Class Person Public FirstName As String Public LastName As String Public Age As Integer End Class :‫ ﻣﻦ ﻫﺬه اﻟﻔﺌﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ‬Objects ‫اﻵن ﻳﻤﻜﻦ ﺗﻌﺮﻳﻒ ﻋﺪة ﻛﺎﺋﻨﺎت‬ ً 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.NET ‫ﻛﻮد‬ 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" :‫أو ﻳﻤﻜﻦ ﺗﻌﺮﻳﻔﻬﻢ ﻋﻠﻰ ﺷﻜﻞ ﻣﺼﻔﻮﻓﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ Person [] MyEmpolyee = new Person[3]; MyEmpolyee[0] = new Person(); MyEmpolyee[0].FirstName = "Ahmed"; MyEmpolyee[0].LastName = "Gamal"; MyEmpolyee[0].Age = 15;145
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫}{ )2(‪Dim MyEmpolyee As Person() = New Person‬‬ ‫)(‪MyEmpolyee(0) = New Person‬‬ ‫"‪MyEmpolyee(0).FirstName = "Ahmed‬‬ ‫"‪MyEmpolyee(0).LastName = "Gamal‬‬ ‫51 = ‪MyEmpolyee(0).Age‬‬‫ﻛﻤﺎ ﻗﻠﻨﺎ ﻓﻲ ﺣﺎﻟﺔ ال ‪ ،struct‬ﻓﺈن ﺑﺎﻣﻜﺎﻧﻨﺎ اﻳﻀﺎ ﺗﻌﺮﻳﻒ اﻟﺪوال داﺧﻞ اﻟﻔﺌﺔ ‪ ،Class‬ﺳﻨﻘﻮم‬ ‫ً‬ ‫ﺑﺒﺮﻣﺠﺔ داﻟﺔ ﺗﻌﻴﺪ ﻟﻨﺎ اﻻﺳﻢ اﻟﻜﺎﻣﻞ ﻟﺸﺨﺺ ﻣﻌﻴﻦ ، ﺳﺘﻜﻮن ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)(‪public string getFullName‬‬ ‫{‬ ‫;‪return FirstName + LastName‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Public Function getFullName() As String‬‬ ‫‪Return FirstName + LastName‬‬ ‫‪End Function‬‬ ‫1. 1. اﻟﻤﺸﻴﺪات ‪Constructors‬‬‫ﻋﻨﺪﻣﺎ ﻧﻘﻮم ﺑﺘﻌﺮﻳﻒ)(‪ new Person‬ﻓﺈن ﻫﺬا ﻳﻌﻨﻲ اﻧﻨﺎ ﻧﻘﻮم ﺑﺘﺸﻐﻴﻞ اﻟﺪاﻟﺔ ال‬‫‪ ،Constructor‬وﻫﻲ اﻟﺪاﻟﺔ اﻟﺘﻲ ﺗﻌﻤﻞ ﻣﻊ ﺗﺸﻐﻴﻞ اي ﻧﺴﺨﺔ ﻣﻦ اﻟﺒﺮﻧﺎﻣﺞ ، اﻓﺘﺮاﺿﻴﺎ ﺗﻜﻮن ﻫﺬه‬ ‫ً‬‫اﻟﺪاﻟﺔ ﺧﺎﻟﻴﺔ وﻳﻤﻜﻨﻨﺎ وﺿﻊ ﺑﻌﺾ اﻻواﻣﺮ ﻓﻴﻬﺎ اﻟﺘﻲ ﻧﺤﺘﺎﺟﻬﺎ وﻗﺖ اﻧﺸﺎء ﻧﺴﺨﺔ ، ﻟﻌﺮض ﻣﺜﻼ رﺳﺎﻟﺔ‬ ‫ً‬ ‫ﺗﺨﺒﺮﻧﺎ ﺑﺎﻧﺸﺎء ﻧﺴﺨﺔ ﺟﺪﻳﺪة ﻣﻦ اﻟﻔﺌﺔ ‪: Class‬‬ ‫ﻣﻼﺣﻈﺔ‬ ‫ﻓﻲ اﻟﺴﻲ ﺷﺎرب ﻳﺘﻢ ﻋﻤﻞ داﻟﺔ ﺑﻨﻔﺲ اﺳﻢ اﻟﻔﺌﺔ ، اﻣﺎ ﻓﻲ ﻓﻴﺠﻮال ﺑﻴﺴﻚ ﻓﻴﺘﻢ ﺗﺴﻤﻴﺔ اﻟﺪاﻟﺔ ﺑﺎﺳﻢ‬ ‫‪New‬‬‫641‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬   ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ C# ‫ﻛﻮد‬ public Person() { Console.WriteLine("new object"); } VB.NET ‫ﻛﻮد‬ Public Sub New() Console.WriteLine("new object") End Sub‫ ﻳﺴﺘﻘﺒﻞ اﻻﺳﻢ‬Constructor‫ ﺑﺎرﻣﻴﺘﺮس، ﻓﻤﺜﻼ ﻟﺠﻌﻞ ال‬Constructor ‫ﻳﻤﻜﻦ اﻳﻀﺎ ان ﻳﺴﺘﻘﺒﻞ ال‬ ً ً :‫اﻷول ﻣﻊ ﺗﻌﺮﻳﻒ اﻻوﺑﺠﻜﺖ اﻟﺠﺪﻳﺪ ، ﻓﺴﻴﻜﻮن ذﻟﻚ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ public Person(string userfirstname) { FirstName = userfirstname; } VB.NET ‫ﻛﻮد‬ Public Sub New(ByVal userfirstname As String) FirstName = userfirstname End Sub :‫وﻟﻌﻤﻞ ﻧﺴﺨﺔ ﺟﺪﻳﺪة ﺳﻴﺘﻮﺟﺐ ﻋﻠﻴﻨﺎ ﻛﺘﺎﺑﺔ اﻟﻜﻮد اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ Person MyEmpolyee = new Person("ahmed"); VB.NET ‫ﻛﻮد‬ Dim MyEmpolyee As New Person("ahmed") Destructor ‫1. 2. اﻟﻤﻬﺪﻣﺎت‬ Beep ‫، ﻻﺻﺪار ﺻﻮت‬Object ‫، ﻳﺘﻢ اﻃﻼق ﻫﺬا اﻟﺤﺪث ﻣﻊ اﻧﻬﺎء اﺳﺘﺨﺪام ال‬Constructor ‫ﻋﻜﺲ ال‬ :‫ﻣﺜﻼ ﻣﻊ اﻧﻬﺎء اﻟﺒﺮﻧﺎﻣﺞ‬ ً147
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)(‪~Person‬‬ ‫{‬ ‫;)(‪Console.Beep‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)(‪Protected Overrides Sub Finalize‬‬ ‫‪End Sub‬‬ ‫ﻧﺴﺘﻔﻴﺪ ﻣﻦ ال ‪ Destructor‬ﻓﻲ ﺗﻨﻔﻴﺬ ﺑﻌﺾ اﻟﻌﻤﻠﻴﺎت ﻗﺒﻞ ﺗﺪﻣﻴﺮ اﻟﻜﺎﺋﻦ ‪ Object‬ﺗﻤﺎﻣﺎً، اﺣﻴﺎﻧﺎ ﻣﺎ‬ ‫ً‬‫ﻧﺤﺘﺎج إﻟﻰ ﻣﺴﺢ ﺟﻤﻴﻊ اﻟﻤﺘﻐﻴﺮات اﻟﻤﺮﺗﺒﻄﺔ ﺑﻪ ﻓﻲ اﻟﺬاﻛﺮة وﻫﻮ اﻻﺳﺘﺨﺪام اﻻﺷﻬﺮ ﻟﻬﺬا اﻟﺤﺪث ،‬ ‫اﻳﻀﺎ ﻳﻤﻜﻦ اﺳﺘﺨﺪاﻣﻪ ﻟﺘﻐﻴﻴﺮ اﻟﻌﺪادات ﻣﺜﻼ واﻟﺘﻲ ﺗﻘﻮم ﺑﻌﺪ اﻟﻨﺴﺦ ﻣﻦ ﻓﺌﺔ ﻣﻌﻴﻨﺔ.‬ ‫ً‬ ‫ً‬ ‫2. ‪this‬‬‫ﻟﺘﻮﺿﻴﺢ ﻣﻔﻬﻮم اﻟﻜﻠﻤﺔ اﻟﻤﺤﺠﻮزة ‪ this‬ﻓﻲ اﻟﺴﻲ ﺷﺎرب، ﺳﻨﻌﻮد إﻟﻰ اﻟﻤﺜﺎل ﻓﻲ اﻟﺪرس‬ ‫اﻟﺴﺎﺑﻖ ﻣﺒﺎﺷﺮة ، واﻟﺬي ﻗﻤﻨﺎ ﻓﻴﻪ ﺑﻌﻤﻞ ‪ Constructor‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪public Person(string userfirstname‬‬ ‫{‬ ‫;‪FirstName = userfirstname‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)‪Public Sub New(ByVal userfirstname As String‬‬ ‫‪FirstName = userfirstname‬‬ ‫‪End Sub‬‬ ‫ﻟﻮ اﻓﺘﺮﺿﻨﺎ اﻵن اﻧﻨﺎ ﺳﻨﻘﻮم ﺑﺘﻐﻴﻴﺮ اﺳﻢ اﻟﺒﺎرﻣﻴﺘﺮ ﻟﻴﻜﻮن ‪ FirstName‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪public Person(string FirstName‬‬ ‫{‬ ‫;‪FirstName = FirstName‬‬ ‫}‬‫841‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)‪Public Sub New(ByVal FirstName As String‬‬ ‫‪FirstName = FirstName‬‬ ‫‪End Sub‬‬ ‫ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﻟﻼﺳﻒ ﺳﻴﻔﻬﻢ اﻟﻜﻮﻣﺒﺎﻳﻠﺮ اﻧﻚ ﺗﺠﻌﻞ ‪ FirstName‬اﻟﺒﺎرﻣﻴﺘﺮ ﻳﺴﺎوي ﻧﻔﺴﻪ ، وﻟﻦ‬ ‫ﻳﻨﻈﺮ إﻟﻰ ‪ FirstName‬ﻛﻤﺘﻐﻴﺮ ﺿﻤﻦ اﻻوﺑﺠﻜﺖ . ﻟﺘﻌﺮﻳﻒ اﻟﻜﻮﻣﺒﺎﻳﻠﺮ ﺑﺈﻧﻚ ﺗﻘﺼﺪ ان اﻟﻤﺘﻐﻴﺮ‬ ‫اﻟﻤﻮﺟﻮد ﻓﻲ اﻻوﺑﺠﻜﺖ = اﻟﺒﺎرﻣﻴﺘﺮ اﻟﻤﺮﺳﻞ ﺳﻨﺴﺘﺨﺪم اﻟﻜﻠﻤﺔ ‪ this‬ﻓﻲ #‪ C‬أو ‪ Me‬ﻓﻲ ‪VB.net‬‬ ‫واﻟﺘﻲ ﺳﺘﺸﻴﺮ إﻟﻰ اﻟﻤﺘﻐﻴﺮ اﻟﻤﻮﺟﻮد ﻓﻲ اﻻوﺑﺠﻜﺖ اﻟﺤﺎﻟﻲ‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪public Person(string FirstName‬‬ ‫{‬ ‫;‪this.FirstName = FirstName‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)‪Public Sub New(ByVal FirstName As String‬‬ ‫‪Me.FirstName = FirstName‬‬ ‫‪End Sub‬‬ ‫ﺣﺘﻰ ﻓﻲ اﻟﺤﺎﻟﺔ اﻟﺴﺎﺑﻘﺔ اﻟﺘﻲ ﺗﻄﺮﻗﻨﺎ ﻟﻬﺎ ﻓﻲ اﻟﺪرس اﻟﺴﺎﺑﻖ ، ﻓﺈن اﺳﺘﺨﺪام ‪ this‬ﺳﻴﻜﻮن ﻣﻨﺎﺳﺐ‬ ‫داﺋﻤﺎ ، اﺑﺴﻂ اﺳﺒﺎب ذﻟﻚ ﻫﻮ اﻇﻬﺎر ﻗﺎﺋﻤﺔ ﺑﺎﻟﻌﻨﺎﺻﺮ اﻟﻤﻮﺟﻮدة ﻓﻲ اﻻوﺑﺠﻜﺖ وﻗﺖ اﻟﺒﺮﻣﺠﺔ ﻣﻨﺬ‬ ‫ً‬ ‫اﻟﻠﺤﻈﺔ اﻟﺘﻲ ﺗﻜﺘﺐ ﻓﻴﻬﺎ ‪.this‬‬ ‫3. اﻟﺘﻌﺮف ﻋﻠﻰ ‪static‬‬ ‫ﻻﺣﻈﻨﺎ ﻓﻲ اﻟﺪاﻟﺔ ‪ main‬اﻟﻤﻮﺟﻮدة اﺳﺎﺳﺎً ﻓﻲ اﻟﺒﺮﻧﺎﻣﺞ اﻧﻨﺎ ﻧﺴﺘﺨﺪم اﻟﻜﻠﻤﺔ ‪ static‬ﻓﻲ ال‬ ‫ #‪C‬اﺿﺎﻓﺔ ﻟﻤﻨﺎﻇﺮﻫﺎ ‪ Shared‬ﻓﻲ ال ‪ ، VB.net‬ﻓﻤﺎ ﻣﻌﻨﻰ ﻫﺬه اﻟﻜﻠﻤﺔ ؟‬ ‫اﻟﻜﻠﻤﺔ ‪ static‬واﻟﺘﻲ ﻳﻤﻜﻦ اﺳﺘﺨﺪاﻣﻬﺎ ﻣﻊ اﻟﺪوال او اﻟﻔﺌﺎت او ﺣﺘﻰ اﻟﻤﺘﻐﻴﺮات ﺗﻌﻨﻲ ان‬ ‫ﻫﺬا اﻟﻤﺘﻐﻴﺮ او اﻟﺪاﻟﺔ ﻳﺘﻢ اﻟﻮﺻﻮل ﻟﻬﺎ ﻣﻦ ﻋﻠﻰ ﻣﺴﺘﻮى ال ‪ Class‬ﻣﺒﺎﺷﺮة وﻟﻴﺲ ﻣﻦ ﻣﺴﺘﻮى ال‬ ‫‪ ،object‬ﻟﻨﻔﺘﺮض اﻟﻤﺜﺎل اﻟﺘﺎﻟﻲ اﻟﺨﺎص ب ‪Person‬‬ ‫941‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬   ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ C# ‫ﻛﻮد‬ class Person { public string FirstName; public string LastName; public int Age; static public int counter; } VB.NET ‫ﻛﻮد‬ Class Person Public FirstName As String Public LastName As String Public Age As Integer Public Shared counter As Integer End Class :‫وﻟﻨﻔﺘﺮض اﻧﻨﺎ ﻛﺘﺒﻨﺎ اﻟﻜﻮد اﻟﺘﺎﻟﻲ ﻣﺜﻼ‬ ً C# ‫ﻛﻮد‬ Person MyEmpolyee = new Person(); MyEmpolyee.Age = 15; MyEmpolyee.counter = 3; VB.NET ‫ﻛﻮد‬ Dim MyEmpolyee As New Person() MyEmpolyee.Age = 15 MyEmpolyee.counter = 3‫ وﻟﺬا ﺗﺘﻢ ﻗﺮاءﺗﻪ‬static ‫ ﻫﻮ ﻣﺘﻐﻴﺮ‬counter ‫ﻟﻼﺳﻒ ﻟﻦ ﻳﻜﻮن ﻫﺬا اﻟﻜﻮد ﺻﺤﻴﺤﺎً ، ﺣﻴﺚ ان‬ :‫ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬Class ‫ﻣﺒﺎﺷﺮة ﻋﻠﻰ ﻣﺴﺘﻮى اﻟﻔﺌﺔ‬ C# ‫ﻛﻮد‬ Person MyEmpolyee = new Person(); MyEmpolyee.Age = 15; Person.counter = 3; VB.NET ‫ﻛﻮد‬ Dim MyEmpolyee As New Person() MyEmpolyee.Age = 15; Person.counter = 3;150
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬‫ﻟﻮ ﻗﻤﻨﺎ ﺑﺘﻌﺮﻳﻒ ‪ Object‬ﺟﺪﻳﺪ ﻣﻦ ﻧﻔﺲ اﻟﻔﺌﺔ ، وﻗﻤﻨﺎ ﺑﻌﺮض ﻗﻴﻤﺔ ال ‪ counter‬اﻟﺨﺎﺻﺔ‬‫ﺑﻪ ﻣﻦ داﺧﻞ اﻟﻔﺌﺔ ‪ Class‬ﺳﻨﺠﺪ اﻧﻬﺎ 3 ﻣﺒﺎﺷﺮة ، ذﻟﻚ ان اﻟﻤﺘﻐﻴﺮ ‪ static‬ﻳﺘﻢ ﺗﻌﺮﻳﻒ ﻧﺴﺨﺔ‬ ‫واﺣﺪة ﻣﻨﻪ ﻋﻠﻰ ﻣﺴﺘﻮى اﻟﻔﺌﺔ ‪ Class‬ﻟﺠﻤﻴﻊ اﻟﻜﺎﺋﻨﺎت ‪ objects‬اﻟﺘﻲ ﻳﺘﻢ ﻋﻤﻠﻬﺎ ﻣﻨﻪ.‬‫ﻣﺜﺎل ﻋﻠﻰ اﻻﺳﺘﻔﺎدة ﻣﻦ ﻫﺬه اﻟﺨﺎﺻﻴﺔ ﻫﻲ ﺧﺎﺻﻴﺔ اﻟﻌﺪادات، واﻟﺘﻲ ﺗﻘﻮم ﺑﻌﺪ اﻻوﺑﺠﻜﺘﺲ اﻟﺘﻲ ﻧﻨﺸﺄﻫﺎ‬‫ﻣﻦ ﻫﺬا اﻟﻔﺌﺔ ‪ ،Class‬ﺳﻨﻀﻊ اﻟﻜﻮد اﻻﺿﻔﺔ ﻓﻲ ال ‪ Constructor‬ﻓﻴﻤﺎ ﻧﻀﻊ ﻛﻮد اﻟﻨﻘﺺ ﻓﻲ‬ ‫‪:Destructor‬‬ ‫#‪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‬‬ ‫}‬ ‫}‬‫151‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬   ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ VB.NET ‫ﻛﻮد‬ 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 :‫واﻵن ﺳﻨﻘﻮم ﺑﺎﻧﺸﺎء ﻋﺪد ﻣﻦ اﻟﻜﺎﺋﻨﺎت ، وﻣﻦ ﺛﻢ ﻧﻘﻮم ﺑﻌﺮض ﻗﻴﻤﺔ اﻟﻌﺪاد‬ 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.NET ‫ﻛﻮد‬ Dim MyEmpolyee As New Person() Dim MyEmpolyee2 As New Person() Dim MyEmpolyee3 As New Person() Dim MyEmpolyee4 As New Person() Dim MyEmpolyee5 As New Person() Console.WriteLine(Person.counter) :‫واﻵن ﻟﻮ اﻓﺘﺮﺿﻨﺎ اﻟﻜﻮد اﻟﺘﺎﻟﻲ‬152
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬   ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ C# ‫ﻛﻮد‬ Person[] MyEmpolyee = new Person[5]; Console.WriteLine(Person.counter); VB.NET ‫ﻛﻮد‬ Dim MyEmpolyee As Person() = New Person(4) {} Console.WriteLine(Person.counter) ‫ﻻ ﺗﺘﻮﻗﻊ ان اﻟﻨﺎﺗﺞ ﺳﻴﻜﻮن 5 ، ﻟﻼﺳﻒ ﺗﻮﻗﻌﻚ ﻟﻴﺲ ﻓﻲ ﻣﺤﻠﻪ ، واﻟﺴﺒﺐ ان اﻳﺎ ﻣﻦ ﻧﺴﺦ‬ ً :5 ‫ ﻟﻢ ﻳﺘﻢ اﻧﺸﺎءه ﺑﻌﺪ، اﻟﺤﺎﻟﺔ اﻟﺘﺎﻟﻴﺔ ﻫﻲ ﻣﻦ ﺳﺘﻌﻄﻴﻚ اﻟﻨﺎﺗﺞ‬MyEmpolyee C# ‫ﻛﻮد‬ Person[] MyEmpolyee = new Person[5]; for (int i = 0; i < 5; i++) MyEmpolyee[0] = new Person(); Console.WriteLine(Person.counter); VB.NET ‫ﻛﻮد‬ 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 .1 .3Static Class ‫، وﺑﻄﺒﻴﻌﺔ اﻟﺤﺎل ﻓﺈن أي‬Static Class ‫. ﺗﻢ اﻋﺘﻤﺎد ﻣﺒﺪأ ال‬net Framewrok 2.0 ‫ﻣﻨﺬ‬‫، اﺿﻒ إﻟﻰ ذﻟﻚ ﻓﺈﻧﻪ ﻟﻴﺲ ﻣﻦ‬static ‫ﻻ ﺑﺪ ان ﺗﻜﻮن ﺟﻤﻴﻊ اﻟﻤﺘﻐﻴﺮات واﻟﺪوال ﻓﻴﻪ ﻣﻦ ﻧﻮع‬ .new‫ ﺑﺎﺳﺘﺨﺪام‬Class ‫ ﻣﻦ ﻫﺬا اﻟﻔﺌﺔ‬object ‫اﻟﻤﻨﻄﻘﻲ ﺗﻌﺮﻳﻒ‬ ‫ ﻫﻲ‬Class‫ ودواﻟﺔ ﻣﺒﺎﺷﺮة ، اﺑﺴﻂ اﻣﺜﻠﺔ ﻫﺬا ال‬Class ‫ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﻳﻤﻜﻦ اﺳﺘﺨﺪام اﻟﻔﺌﺔ‬ .‫ واﻟﺘﻲ ﻳﻤﻜﻦ اﺳﺘﺨﺪاﻣﻬﺎ ﻣﺒﺎﺷﺮة دون ﺗﻌﺮﻳﻒ ﻧﺴﺨﺔ ﻣﻨﻬﺎ‬MessageBox C# ‫ﻛﻮد‬ MessageBox.Show(“Welcome”);153
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)”‪MessageBox.Show(“Welcome‬‬ ‫4. اﻋﺎدة اﻟﺘﺤﻤﻴﻞ ‪OverLoading‬‬‫ﻣﻦ اﻫﻢ ﻣﺒﺎدئ ال ‪ OOP‬ﻫﻲ ﺗﻄﺒﻴﻖ ﻣﺒﺪئ ال ‪ ، Overloading‬ﺣﻴﺚ ﻳﻤﻜﻦ ﺗﺴﻤﻴﺔ ﻋﺪة ﻃﺮق او‬ ‫دوال ﺑﻨﻔﺲ اﻻﺳﻢ ﻣﺎ دام ﻫﻨﺎك ﺗﻐﻴﻴﺮ ﻓﻲ اﻟﺒﺎرﻣﻴﺘﺮات.‬ ‫اﺑﺴﻂ ﻣﺜﺎل ﻋﻠﻰ ﻋﻤﻠﻴﺎت ال ‪ Overloading‬ﻫﻲ داﻟﺔ)(‪ MessageBox.Show‬ﻓﻲ ال  ‪Windows‬‬ ‫‪Forms‬‬ ‫ﻟﻮ ﺟﺮﺑﺖ ﺳﺘﺠﺪ ﻫﺬه اﻷواﻣﺮ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)‪MessageBox.Show(string text‬‬ ‫;)‪MessageBox.Show(string text,string caption‬‬ ‫;)‪MessageBox.Show(string text, string caption, MessageBoxButtons buttons‬‬‫وﻏﻴﺮﻫﺎ اﻳﻀﺎ ﺿﻤﻦ 7 اواﻣﺮ ، ﻛﻞ واﺣﺪة ﻣﻨﻬﺎ ﻋﺒﺎرة ﻋﻦ داﻟﺔ ﺧﺎﺻﺔ وﻟﻬﻢ ﺟﻤﻴﻌﺎ ﻧﻔﺲ اﻻﺳﻢ ،‬ ‫ً‬ ‫ً‬ ‫ﻟﻨﺘﺼﻮر ﻟﻮ ﻟﻢ ﻳﻜﻦ ﻣﺒﺪأ ‪ Overloading‬ﻣﻮﺟﻮدًا ، ﻛﻨﺎ ﺳﻨﻀﻄﺮ ﻟﻜﺘﺎﺑﺔ دوال ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)‪MessageBox.ShowWithString(string text‬‬ ‫;)‪MessageBox.ShowStringAndCaption(string text,string caption‬‬ ‫,‪MessageBox.ShowStringAndCaptionAndButtons(string text, string caption‬‬ ‫;)‪MessageBoxButtons buttons‬‬ ‫أﻣﺎ اﻵن وﻟﺘﺴﻬﻴﻞ اﻻﺳﺘﺨﺪام ﺗﺠﺪﻫﻢ ﺟﻤﻴﻌﺎ ﺑﻨﻔﺲ اﻻﺳﻢ، وﻫﺬا ﻣﺎ ﻳﺴﺒﺐ ﺳﻬﻮﻟﺔ اﻻﺳﺘﺨﺪام.‬ ‫ً‬‫ﻟﺘﻄﺒﻴﻖ ﻣﺒﺪأ ال ‪ OverLoading‬ﻓﻲ دواﻟﻚ ﻳﻤﻜﻨﻚ ﻛﺘﺎﺑﺔ ﻛﻮد ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ - ﻟﻌﻤﻠﻴﺔ اﻟﺠﻤﻊ ﻣﺜﻼ‬‫ً‬ ‫ﻓﻲ ﺣﻴﻦ اﻧﻚ ﻻ ﺗﺪري ﻫﻞ ﻳﻤﺮر ﻟﻚ ﻓﻲ اﻟﻔﺌﺔ ‪ class‬ﻗﻴﻢ ﻣﻦ ﻧﻮع ‪ int‬او ﻣﻦ ﻧﻮع ‪double‬‬‫451‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬   ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ 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.NET ‫ﻛﻮد‬ 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‫ ، ﻓﻴﻤﻜﻨﻚ ﻋﻤﻞ ﻋﺪد ﻣﻨﻬﺎ ﺣﺴﺐ اﺣﺘﻴﺎج‬Constructor ‫ﻳﻤﻜﻦ ان ﻧﻌﻴﺪ اﻟﻜﺮة ﻣﺮة أﺧﺮى ﻣﻊ ال‬ :‫ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬Constructors ‫ ﻳﻤﻜﻦ ﺗﻌﺮﻳﻒ ال‬Person ‫اﻟﻤﺴﺘﺨﺪم ، ﻟﻮ ﻋﺪﻧﺎ ﻟﻤﺜﺎﻟﻨﺎ‬ C# ‫ﻛﻮد‬ class Person { public string FirstName; public string LastName; public int Age; public Person(){ Console.WriteLine("c1"); } 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"); } }155
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬   ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ VB.NET ‫ﻛﻮد‬ 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 :‫وﺑﻬﺬه اﻟﻄﺮﻳﻘﺔ ﻳﻤﻜﻨﻨﺎ اﻧﺸﺎء ﻛﺎﺋﻨﺎت ﺑﺄﺣﺪ اﻟﻄﺮق اﻟﺘﺎﻟﻴﺔ‬ C# ‫ﻛﻮد‬ Person MyEmpolyee = new Person(); Person MyEmpolyee = new Person("ahmed", "gamal"); Person MyEmpolyee = new Person("ahmed", "gamal", 22); VB.NET ‫ﻛﻮد‬ Dim MyEmpolyee As New Person() Dim MyEmpolyee As New Person("ahmed", "gamal") Dim MyEmpolyee As New Person("ahmed", "gamal", 22) 156
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ ‫5. ﻣﻌﺮﻓﺎت اﻟﻮﺻﻮل ‪Access Modifiers‬‬‫ﻓﻲ دروﺳﻨﺎ اﻟﺴﺎﺑﻘﺔ ، ﻛﺎن ﻣﻌﺮف اﻟﻮﺻﻮل اﻻﻓﺘﺮاﺿﻲ اﻟﺬي ﻧﻘﻮم ﺑﺎﺳﺘﺨﺪاﻣﻪ ﻫﻮ ‪،public‬‬‫وذﻛﺮﻧﺎ ان ﻫﺬا ﻳﺘﻴﺢ ﻟﻨﺎ اﻟﻮﺻﻮل إﻟﻰ ﻫﺬه اﻟﺪاﻟﺔ أو ﻫﺬا اﻟﻤﺘﻐﻴﺮ ﻣﺒﺎﺷﺮة ﻣﻦ ﺧﻼل ال ‪،Object‬‬‫ﻗﻠﻨﺎ اﻳﻀﺎ إﻧﻨﺎ ﻟﻮ اﺳﺘﺨﺪﻣﻨﺎ اﻟﻤﻌﺮف ‪ private‬ﻓﻠﻦ ﻧﺘﻤﻜﻦ ﻣﻦ رؤﻳﺔ ﻫﺬا اﻟﻤﺘﻐﻴﺮ او ﻫﺬه اﻟﺪاﻟﺔ‬ ‫ً‬ ‫ﺳﻮى ﻣﻦ داﺧﻞ اﻟﻔﺌﺔ ‪ class‬ﻧﻔﺴﻪ ﻓﻘﻂ‬ ‫ﻓﻲ ﻫﺬا اﻟﺪرس ﺳﻮف ﻧﺘﻌﺮف ﻋﻠﻰ اﻧﻮاع ﻣﻌﺮﻓﺎت اﻟﻮﺻﻮل اﻟﻤﺨﺘﻠﻔﺔ واﻟﻔﺮوﻗﺎت ﺑﻴﻨﻬﺎ.‬ ‫‪:Public‬‬‫ﻳﺘﻴﺢ ﻟﻚ ﻫﺬا اﻟﻤﻌﺮف اﻟﻮﺻﻮل إﻟﻰ اﻟﺪاﻟﺔ أو اﻟﻤﺘﻐﻴﺮ ﻣﻦ ال ‪ Object‬ﻣﺒﺎﺷﺮة ، اﻳﻀﺎ ﻟﻮ ﻗﺎم أﺣﺪ‬ ‫ً‬‫ﺑﺎﺷﺘﻘﺎق اﻟﻔﺌﺔ ‪ Class‬ﻓﺴﻴﺠﺪ ﻫﺬه اﻟﺪاﻟﺔ ‪ public‬ﻛﻤﺎ ﻫﻲ وﺳﻴﻤﻜﻦ ﻟﻞ ‪ objects‬ﻣﻦ اﻟﻔﺌﺔ‬ ‫‪ Class‬اﻟﺠﺪﻳﺪ اﻟﻮﺻﻮل ﻟﻬﺎ.‬ ‫‪:Private‬‬ ‫ﻳﻤﻜﻦ ﻓﻘﻂ رؤﻳﺘﻪ داﺧﻞ اﻟﻔﺌﺔ ‪ Class‬او ال ‪ Struct‬اﻟﺬي ﺗﻢ ﺗﻌﺮﻳﻔﻪ ﻣﻦ ﺧﻼﻟﻪ.‬ ‫‪:Protected‬‬‫ﻻ ﻳﻤﻜﻦ اﻟﻮﺻﻮل اﻟﻤﺒﺎﺷﺮ ﻟﻬﺎ ﻣﻦ ال ‪ Object‬وﻟﻜﻦ ﻳﻤﻜﻦ اﻟﻮﺻﻮل ﻟﻬﺎ ﻣﻦ اﻟﻔﺌﺔ ‪ Class‬اﻟﻤﺸﺘﻖ.‬ ‫‪:internal‬‬ ‫ﻳﻤﻜﻦ اﻟﻮﺻﻮل ﻟﻬﺎ داﺧﻞ اﻻﺳﻤﺒﻠﻲ اﻟﺤﺎﻟﻲ ﻓﻘﻂ.‬ ‫‪:protected internal‬‬‫ﻳﻤﻜﻦ اﻟﻮﺻﻮل ﻟﻬﺎ اﻳﻀﺎ ﻣﻦ ﺧﻼل اﻟﻔﺌﺔ ‪ Class‬اﻟﻤﺸﺘﻖ اﺿﺎﻓﺔ ﻟﻠﻮﺻﻮل ﻟﻬﺎ ﻣﻦ ﺧﻼل ﻧﻔﺲ ﻣﻠﻒ‬ ‫ً‬ ‫اﻻﺳﻤﺒﻠﻲ.‬‫751‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ ‫6. اﻟﻌﻨﺎﺻﺮ اﻷﺳﺎﺳﻴﺔ ﻓﻲ ال ‪OOP‬‬ ‫ﺟﻤﻴﻊ ﻟﻐﺎت اﻟﺒﺮﻣﺠﺔ اﻟﺘﻲ ﺗﻄﺒﻖ ﻣﺒﺎدئ ال ‪ OOP‬ﻻ ﺑﺪ ان ﺗﺘﻌﺮض ﻟﻠﻨﻘﺎط اﻟﺜﻼث اﻟﺘﺎﻟﻴﺔ:‬ ‫1. ‪Encapsulation‬‬ ‫2. ‪Inheritance‬‬ ‫3. ‪Polymorphism‬‬ ‫6. 1. ‪  Encapsulation‬‬‫ﻳﻘﺼﺪ ﺑﺎل ‪ Encapsulation‬ﻫﻮ اﺧﻔﺎء وﺿﻢ اﻟﺒﻴﺎﻧﺎت واﻷﻛﻮاد اﻟﻤﺨﺘﻠﻔﺔ واﻇﻬﺎرﻫﺎ ﻓﻲ اﻟﻨﻬﺎﻳﺔ‬‫ﻟﻠﻤﺴﺘﺨﺪم ﻋﻠﻰ ﺷﻜﻞ ‪ ، Black Box‬ﺣﻴﺚ ﺳﺘﺠﺪ ﻓﻲ اﻟﻨﻬﺎﻳﺔ داﻟﺔ ﺑﺎﺳﻢ ‪ ، PrintReport‬ﻓﻲ اﻟﻮاﻗﻊ‬‫ﻻ ﻳﻬﻤﻚ ﻣﺎ ﻫﻮ اﻟﻜﻮد اﻟﻤﻮﺟﻮد داﺧﻠﻬﺎ ، ﺣﻴﺚ ﻳﻜﻔﻴﻚ اﺳﺘﺪﻋﺎءﻫﺎ ﻟﺘﻌﻤﻞ ﻟﺪﻳﻚ داﻟﺔ ﻃﺒﺎﻋﺔ اﻟﺘﻘﺎرﻳﺮ.‬ ‫ﺗﺴﺘﻔﻴﺪ اﻳﻀﺎ ﻣﻦ ﻫﺬه اﻟﺨﺎﺻﻴﺔ ﻓﻲ ﺣﺎﻟﺔ اﻟﻌﻤﻞ اﻟﺠﻤﺎﻋﻲ ﻋﻠﻰ اﻟﻤﺸﺮوع ، ﻓﻲ اﻟﺤﺎﻟﺔ اﻟﻌﻤﻞ ﺑﺎﺳﻠﻮب‬ ‫ً‬‫‪ Structured‬ﺳﺘﺠﺪ ﺟﻤﻴﻊ اﻟﻜﻮد ﻓﻲ ﻣﻜﺎن واﺣﺪ ، اﻣﺎ ﻣﻊ ال ‪ Encapsulation‬ﻓﻲ ال ‪ OOP‬ﻓﺴﻴﻜﻮن‬‫ﻛﻞ ﺟﺰء ﻣﻦ اﻟﻌﻤﻞ ﻣﻐﻠﻘﺎ ﻋﻠﻰ ﻧﻔﺴﻪ وﻳﺘﻢ اﻟﺘﻮاﺻﻞ ﺑﻴﻨﻬﻢ اﻟﺒﻌﺾ ﻋﻦ ﻃﺮﻳﻖ ‪ Objects‬ﻣﺨﺘﻠﻔﺔ ،‬ ‫ً‬ ‫وﻫﺬا ﻣﺎ ﻳﺴﺎﻫﻢ ﻓﻲ ﺗﺴﻬﻴﻞ ﺗﺮﻛﻴﺐ اﻟﻌﻤﻞ ، ﺗﺴﻬﻴﻞ اﻛﺘﺸﺎف اﻷﺧﻄﺎء.‬ ‫6. 2. ‪  Inheritance‬‬‫أو اﻟﻮراﺛﺔ ، وﻳﻘﺼﺪ ﺑﻬﺎ ﻋﻤﻞ ﻧﺴﺨﺔ ﺟﺪﻳﺪة ﻣﻦ اﻟﻔﺌﺔ ‪ class‬ﺗﺤﺘﻮي ﻋﻠﻰ ﻧﻔﺲ ﺧﺼﺎﺋﺼﻪ‬‫ﻣﻦ اﺟﻞ ﺗﻄﻮﻳﺮﻫﺎ أو ﺗﻌﺪﻳﻞ ﺑﻌﺾ اﻟﺨﺼﺎﺋﺺ ، ﻟﻨﻔﺘﺮض ﻣﺜﻼ ان ﻟﺪﻳﻨﺎ ﻓﺌﺔ ‪) class‬ﺳﻴﺎرة( ﻳﺤﺘﻮي‬ ‫ً‬ ‫ﻋﻠﻰ اﺳﻢ اﻟﺴﻴﺎرة وﺗﺎرﻳﺦ ﺻﻨﻌﻬﺎ ﻣﺜﻼ.‬ ‫ً‬‫واﻵن ﻧﺮﻳﺪ اﻟﻘﻴﺎم ﺑﻌﻤﻞ ﻓﺌﺔ ‪ class‬ﻟﻠﺴﻴﺎرات ال ‪ BMW‬ﻣﺜﻼ ، ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﻣﻦ اﻟﺨﻄﺄ ان ﻧﻘﻮم‬ ‫ً‬‫ﺑﻌﻤﻞ ﻓﺌﺔ ‪ class‬ﻣﻨﻔﺼﻞ ﻟﻬﺎ ، وﻟﻜﻨﻨﺎ ﻧﺴﺘﻄﻴﻊ اﺷﺘﻘﺎق ﻓﺌﺔ ‪ class‬ﺟﺪﻳﺪ ﻣﻦ اﻟﻔﺌﺔ ‪class‬‬‫اﻟﻤﺴﻤﻰ ‪ Car‬ﻣﻊ اﺿﺎﻓﺔ ﺧﺎﺻﻴﺔ ‪ isSport‬ﻟﻠﻔﺌﺔ ‪ class‬اﻟﻤﺴﻤﺎه ‪ ، BMW‬اﻟﻬﺪف ﻣﻦ ذﻟﻚ اﻧﻨﺎ‬‫851‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ ‫ﺳﻨﺠﺪ ﺧﺼﺎﺋﺺ ﻣﺸﺘﺮﻛﺔ ﺑﻴﻦ ال‪ Car‬و ال ‪ ، BMW‬اﻳﻀﺎ ﺳﻨﻀﻄﺮ ﻳﻮﻣﺎ ﻻﺿﺎﻓﺔ ﻓﺌﺔ ﻟﻞ ‪ GMC‬واﻟﺬي‬ ‫ً‬ ‫ً‬ ‫ﺳﻴﺤﺘﻮي ﺑﺪوره ﻋﻠﻰ ﺑﻴﺎﻧﺎت ﻣﺸﺘﺮﻛﺔ.‬ ‫اﻟﺴﺒﺐ اﻵﺧﺮ ﻟﻮ ﻗﻤﻨﺎ ﺑﺎﺿﺎﻓﺔ ﻋﻨﺼﺮ ﺟﺪﻳﺪ ﻣﺜﻞ ‪ countofdoors‬ﻟﻜﻞ اﻟﺴﻴﺎرات ، ﻓﻬﻞ ﺳﻨﻘﻮم‬ ‫ﺑﺎﻟﺘﻌﺪﻳﻞ ﻓﻲ ﺟﻤﻴﻊ اﻟﻔﺌﺎت ، ﻓﻲ ﺣﺎﻟﺔ ﻗﻤﻨﺎ ﺑﻌﻤﻞ اﺷﺘﻘﺎق ﻣﻦ اﻟﻔﺌﺔ ‪ Car‬ﻓﺈﻧﻨﺎ ﻧﺴﺘﻄﻴﻊ اﻟﺘﻌﺪﻳﻞ ﻓﻴﻪ‬ ‫ﻓﻘﻂ ﻟﺘﻄﺒﻴﻖ اﻟﺘﻌﺪﻳﻼت.‬ ‫رﺑﻤﺎ ﻻ ﺗﻈﻬﺮ اﻷﻫﻤﻴﺔ ﻓﻲ اﻟﻔﺌﺎت اﻟﺼﻐﻴﺮة وﻟﻜﻦ ﺗﺴﺘﻄﻴﻊ ﺗﺨﻴﻞ ﺣﺠﻢ اﻟﻔﺎﺋﺪة ﻓﻲ ﺣﺎﻟﺔ وﺟﻮد ﻛﻢ‬ ‫ﻛﺒﻴﺮ ﻣﻦ اﻟﺒﻴﺎﻧﺎت.‬ ‫ﻳﺘﻢ ﺗﻌﺮﻳﻒ اﻟﻌﻼﻗﺔ ‪ Inheritance‬ﺑﺎﺳﻢ ‪ ، is a‬ﺣﻴﺚ ان ‪ ، BMW is a Car‬اﻳﻀﺎ ﻓﻲ ﺣﺎﻟﺔ وﺟﻮد ﻓﺌﺔ‬ ‫ً‬ ‫ﻟﻼﺷﻜﺎل وﻓﺌﺔ أﺧﺮى ﻟﻠﺪاﺋﺮة ﻣﺜﻼ ﻓﺈن ‪. Circle is a Shape‬‬ ‫ً‬ ‫ﻫﻨﺎك ﻧﻮع آﺧﺮ ﻣﻦ اﻟﻌﻼﻗﺎت ﺑﻴﻦ ال ‪ Classes‬وﻫﻲ ﻋﻼﻗﺔ  ‪ has a‬وﺗﺴﻤﻰ ﺑﺎﺳﻢ ‪ ،Aggregation‬ﻓﻲ‬ ‫ﻫﺬه اﻟﺤﺎﻟﺔ ﺗﻜﻮن اﻟﻔﺌﺔ اﻟﺜﺎﻧﻴﺔ ﻣﺤﺘﻮﻳﺔ ﻋﻠﻰ اﻟﻔﺌﺔ اﻷوﻟﻰ ، ﻣﺜﻼ ﻟﻮ ﻛﺎن ﻟﺪﻳﻨﺎ ﻓﺌﺔ ﻣﻦ اﺟﻞ ﻋﺠﻼت‬ ‫ً‬ ‫اﻟﺴﻴﺎرة ﺑﺎﺳﻢ ‪ ،Wheel‬ﺳﺘﻜﻮن ‪. Car has a Wheel‬‬ ‫6. 3. ‪  Polymorphism‬‬ ‫اﻟﻤﺒﺪأ اﻷﺧﻴﺮ ﻣﻦ ﻣﺒﺎدئ ‪ OOP‬ﻫﻮ اﻟﺴﻤﺎح ﺑﻜﺘﺎﺑﺔ ﻓﺌﺔ ﺑﺪواﻟﻬﺎ ﺑﺪون أي ‪،Implementation‬‬ ‫واﻟﺴﺒﺐ ﻫﻮ اﺟﺒﺎر اي ﻣﺴﺘﺨﺪم ﻳﻘﻮم ﺑﺎﺷﺘﻘﺎق اﻟﻔﺌﺔ ﺑﻌﻤﻞ ‪ implementation‬ﻟﻬﺬه اﻟﺪوال ﺑﻤﺎ ﻳﻀﻤﻦ‬ ‫ﺗﺸﺎﺑﻪ اﻻﺳﻤﺎء ، اﺑﺴﻂ ﻣﺜﺎل ﻋﻠﻰ ذﻟﻚ ﻓﺌﺔ ‪ Class‬ﻟـ ‪ ، Shape‬ﺣﻴﺚ ﻳﻤﻜﻨﻨﺎ ﺗﻌﺮﻳﻔﻪ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪class Shape‬‬ ‫{‬ ‫)(‪public void Draw‬‬ ‫{‬ ‫}‬ ‫)(‪public void GetSize‬‬ ‫{‬ ‫}‬ ‫}‬ ‫951‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫‪Class Shape‬‬ ‫)(‪Public Sub Draw‬‬ ‫‪End Sub‬‬ ‫)(‪Public Sub GetSize‬‬ ‫‪End Sub‬‬‫‪End Class‬‬ ‫ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﻳﻌﺮف ال ‪ Class‬ﺑﺎﺳﻢ ‪ ،Abstract  Class‬ﺗﻮﻓﺮ #‪ C‬و ‪ VB.net‬اﻳﻀﺎ ﻣﺒﺪأ ال‬ ‫ً‬ ‫‪ Interface‬واﻟﺬي ﻳﺸﺒﻪ ﻛﺜﻴﺮًا ال ‪ Abstract Class‬وﻟﻜﻦ ﻣﻊ ﻓﺮوﻗﺎت ﺳﻨﺘﻌﺮف ﻋﻠﻴﻬﺎ ﻓﻲ ﺣﻴﻨﻬﺎ.‬‫ﻓﻲ اﻟﻔﺌﺔ اﻟﺴﺎﺑﻖ ﻓﺈن ﻛﻞ ﻓﺌﺔ )داﺋﺮة ، ﻣﺮﺑﻊ ، ﻣﺜﻠﺚ( ﺳﻴﺘﻢ اﺷﺘﻘﺎﻗﻪ ﻣﻦ ﻫﺬا اﻟﻔﺌﺔ ﺳﻴﻜﻮن ﻣﺠﺒﺮًا‬ ‫ﻋﻠﻰ ﻛﺘﺎﺑﺔ اﻛﻮاد اﻟﺮﺳﻢ وﺣﺴﺎب اﻟﻤﺴﺎﺣﺔ ﻟﻜﻞ ﻣﻨﻬﻢ .‬ ‫ﻳﻤﻜﻦ ﻋﻤﻞ ذﻟﻚ ﺑﻄﺮﻳﻘﺔ أﺧﺮى ﻋﺒﺮ ال ‪ OverRidding‬وﻟﻜﻦ ﻣﻊ اﻻﺧﺘﻼف ﻓﻲ اﺣﺘﻤﺎﻟﻴﺔ وﺟﻮد‬ ‫‪.Default Implementation‬‬ ‫7. ‪Encapsulation‬‬‫ﻳﻬﺪف ﻣﺒﺪأ ال ‪ Encapsulation‬واﻟﺬي ﺳﺒﻖ ﺷﺮﺣﻪ ﺑﺎﺧﺘﺼﺎر إﻟﻰ اﺧﻔﺎء اﻟﺘﻔﺎﺻﻴﻞ اﻟﺪاﺧﻠﻴﺔ‬‫ﻷي ﻓﺌﺔ ﻋﻦ اﻋﻴﻦ ﺑﺎﻗﻲ اﻟﻤﺒﺮﻣﺠﻴﻦ ، ﺑﺎﺧﺘﺼﺎر ﺷﺪﻳﺪ ﻟﻨﻔﺘﺮض ﻧﻈﺎم ﻣﺤﺎﺳﺒﻲ ﻳﺘﻀﻤﻦ ﻧﻈﺎم ﻻدارة‬ ‫اﻟﻤﺨﺎزن ، وآﺧﺮ ﻟﻠﺼﻴﺎﻧﺔ ، وﺛﺎﻟﺚ ﻣﻦ اﺟﻞ اﻟﻤﺒﻴﻌﺎت.‬‫ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﻳﺪﻋﻮك ﻣﺒﺪأ ال ‪ Encapsulation‬ﻟﻴﻜﻮن ﻟﻜﻞ واﺣﺪ ﻣﻦ ﻫﺬه اﻟﻨﻈﻢ ﻋﺪد ﻣﺤﺪد ﻣﻦ‬‫اﻟﺪوال ﻟﻠﺪﺧﻮل واﻟﺨﺮوج ﻣﻦ ﻫﺬا اﻟﻨﻈﺎم واﻟﺘﻲ ﻳﻤﻜﻦ ﻟﻠﻨﻈﻢ اﻟﺜﻼﺛﺔ اﻟﺘﻮاﺻﻞ ﻣﻦ ﺧﻼﻟﻬﺎ ، ﻓﻤﺜﻼ ﻓﻲ‬ ‫ً‬‫ﻧﻈﻜﺎم اﻟﻤﺒﻴﻌﺎت ﺗﺠﺪ )اﺿﺎﻓﺔ ﻋﻤﻠﻴﺔ ﻣﺒﻴﻌﺎت( ) اﺿﺎﻓﺔ ﻣﺸﺘﺮﻳﺎت ( ) ﺧﺼﻢ ( ... اﻟﺦ ﻓﻲ ﻣﺠﻤﻮﻋﺔ‬ ‫ﻣﺤﺪودة ﺟﺪًا ﻣﻦ اﻟﺪوال.‬‫ﻃﺒﻌﺎ ﻟﻮ ﻻﺣﻈﺖ ان ﻋﻤﻠﻴﺔ ﻣﺜﻞ اﺿﺎﻓﺔ ﻋﻤﻠﻴﺔ ﻣﺒﻴﻌﺎت ﺗﺘﻄﻠﺐ ﻃﺎﺑﻮرًا ﻣﻦ اﻷواﻣﺮ ، ﻳﺘﻀﻤﻦ ﻓﺘﺢ ﻗﺎﻋﺪة‬ ‫ً‬‫اﻟﺒﻴﺎﻧﺎت واﻟﺘﺄﻛﺪ ﻣﻦ ان اﻟﺒﻴﺎﻧﺎت اﻟﻤﺪﺧﻠﺔ ﺻﺤﻴﺤﺔ واﻟﺘﺄﻛﺪ ﻣﻦ وﺟﻮد اﻟﻜﻤﻴﺔ وﻣﻦ ﺛﻢ ﺗﺨﺰﻳﻦ‬‫اﻟﻨﺎﺗﺞ ﻓﻲ ﻗﺎﻋﺪة اﻟﺒﻴﺎﻧﺎت ، ﺗﻢ ﺗﺠﻤﻴﻌﻬﺎ ﻓﻲ اﻟﻨﻬﺎﻳﺔ ﻋﻠﻰ ﺷﻜﻞ أﻣﺮ واﺣﺪ ﻳﻘﻮم زﻣﻴﻠﻚ اﻵﺧﺮ اﻟﺬي‬ ‫ﻳﻘﻮم ﺑﺒﺮﻣﺠﺔ واﺟﻬﺎت اﻟﻤﺴﺘﺨﺪم إﻟﻰ اﺳﺘﺨﺪاﻣﻪ ﺑﺪﻻ ﻣﻦ اﻟﻐﻮص ﻓﻲ ﻛﻞ ﻫﺬه اﻟﺘﻔﺎﺻﻴﻞ اﻟﻔﻨﻴﺔ.‬ ‫ً‬‫061‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬‫ﻛﻤﺎ ﻻﺣﻈﺖ ، ﻳﻔﻴﺪ ﻫﺬا اﻟﻤﻮﺿﻮع اﻷﺷﺨﺎص اﻟﺘﻲ ﺗﻌﻤﻞ ﻓﻲ ﻣﺠﻤﻮﻋﺎت اوﻻ ، ﺣﻴﺚ ﻟﻦ اﻛﻮن‬ ‫ً‬‫ﻣﻀﻄﺮًا ﻟﻔﻬﻢ ﻛﻮدك ﺑﺎﻟﻜﺎﻣﻞ وﻳﻜﻔﻴﻨﻲ ان اﻋﺮف ﻛﻴﻒ اﺗﻌﺎﻣﻞ ﻣﻌﻚ ، ﻛﻤﺎ ان اﻟﻜﻮد ﺳﻴﻜﻮن ﻣﺼﻤﻤﺎ‬‫ً‬‫ﻋﻠﻰ ﺷﻜﻞ ﻫﺮم ﺣﻴﺚ ﻛﻞ أﻣﺮ ﻳﺴﺘﺘﺒﻌﻪ ﻣﺠﻤﻮﻋﺔ ﻣﻦ اﻷواﻣﺮ ، ﻟﻜﻦ ﺳﻴﻜﻮن زﻣﻴﻠﻚ اﻟﻤﺒﺮﻣﺞ ﻗﺎدرًا‬‫ﻓﻘﻂ ﻟﻠﻮﺻﻮل إﻟﻰ رأس اﻟﻬﺮم وﻫﻮ ﻣﺎ ﻳﻘﻠﻞ ﻛﺜﻴﺮًا ﻣﻦ اﻷﺧﻄﺎء ، ﻛﻤﺎ ﻳﺤﻤﻲ ﻣﺘﻐﻴﺮاﺗﻚ اﻟﺨﺎﺻﺔ‬ ‫ﻣﻦ اﻟﻌﺒﺚ ﺑﻬﺎ ﻋﻦ ﻃﺮﻳﻖ اﻟﺨﻄﺄ ﻣﻦ اﻟﻤﺒﺮﻣﺠﻴﻦ اﻵﺧﺮﻳﻦ.‬‫ﻫﺬا اﻟﻤﻔﻬﻮم اﻟﺬي ﺗﺤﺎول ان ﺗﻮﺻﻠﻪ ﻟﻚ ﻛﻞ ﻟﻐﺎت ﺑﺮﻣﺠﺔ ‪ ،OOP‬وﻟﺘﻄﺒﻴﻖ ﻫﺬا اﻟﻤﻔﻬﻮم ﻫﻨﺎك‬ ‫اﻟﻌﺪﻳﺪ ﻣﻦ اﻟﻨﻘﺎط اﻟﺘﻲ ﺳﻨﺘﻄﺮق ﻟﻬﺎ ﻓﻲ ﻫﺬا اﻟﺪرس.‬‫ﻗﺒﻞ ان ﻧﻮاﺻﻞ ، اول ﻧﻘﻄﺔ ﻻ ﺑﺪ ان ﺗﻀﻌﻬﺎ ﻓﻲ ذﻫﻨﻚ اﻧﻚ ﻣﺒﺮﻣﺞ وﻫﻨﺎك ﻣﺒﺮﻣﺞ آﺧﺮ ﻫﻮ‬‫اﻟﻤﺴﺘﺨﺪم ... ﺑﻤﻌﻨﻰ ﻣﺜﻼ اﻧﻚ ﺗﻘﻮم ﺑﺒﺮﻣﺠﺔ ﻓﺌﺔ وﻳﻘﻮم زﻣﻴﻠﻚ اﻟﻤﺒﺮﻣﺞ ﺑﺎﺳﺘﺨﺪام ﻫﺬ اﻟﻔﺌﺔ‬ ‫ً‬ ‫ﻛﺠﺰء ﻣﻦ اﻟﻤﺸﺮوع.‬ ‫‪private‬‬ ‫ﻟﻠﻮﺻﻮل إﻟﻰ ﻣﺘﻐﻴﺮات‬ ‫‪public‬‬ ‫7. 1. اﺳﺘﺨﺪام دوال‬‫ﻟﻨﻔﺘﺮض اﻟﻤﺜﺎل اﻟﺘﺎﻟﻲ ﺑﺨﺼﻮص ال ‪ Person‬اﻟﺬي ﻗﻤﻨﺎ ﺑﺎﻧﺸﺎءه ﻋﺪة ﻣﺮات ﻋﻠﻰ ﻣﺴﺘﻮى‬ ‫اﻟﺪروس اﻟﺴﺎﺑﻘﺔ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪class Person‬‬ ‫{‬ ‫;‪public int Age‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Class Person‬‬ ‫‪Public Age As Integer‬‬ ‫‪End Class‬‬‫وﻹن زﻣﻴﻠﻚ اﻟﻌﺰﻳﺰ ﻓﻲ اﻟﻔﺮﻳﻖ اﻟﺨﺎص ﺑﺎدﺧﺎل ﺑﻌﺾ اﻟﺒﻴﺎﻧﺎت ﺑﺸﺮ - وﺟﻞ ﻣﻦ ﻻ ﻳﺴﻬﻮ - ﻗﺎم ﺑﻜﺘﺎﺑﺔ‬ ‫اﻟﺠﻤﻠﺔ اﻟﺘﺎﻟﻴﺔ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)(‪Person Ahmed = new Person‬‬ ‫;999999999999 = ‪Ahmed.Age‬‬‫161‬
  • ‫ت و ﻣﻘﺪﻣﺔ إإﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ﻛ‬ ‫اﻟﻔﺌﺎت‬ ‫ ‬ ‫اﻟﺒﺎب ﻣﻦ‬ ‫اﻟﺜﺎﻣ‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)(‪Dim Ahme As New Person‬‬ ‫‪ed‬‬ ‫999999999999 = ‪Ahmed.Ag‬‬ ‫‪ge‬‬‫ﻬﻮ ﻓﻲ رﻗﻢ ﺑﻬﺬا اﻟﺤﺠﻢ ﻳﻌﺪ ﺷﺒﻪ ﻣﺴﺘﺤﻴﻞ ، ﻜﻨﻨﺎ ﻗﺪ ﺮض ﻟﻬﺬه ﻟﻤﺸﻜﻠﺔ ﻓﻲ‬ ‫اﻟ‬ ‫ﻧﺘﻌﺮ‬ ‫ﻟﻜ‬ ‫ﻣ‬ ‫وﻟﻮ ان اﻟﺴﻬ‬ ‫و‬‫اﺷﻴﺎء ﻗﺮب ﻟﻠﻮاﻗﻊ ، واﺑﺴﻂ ﻣﻦ ذﻟﻚ ﻮ اﻧﻪ ﻳﻘﻮم ﺑﻘﺮاءة ﻴﻤﺔ ﻣﻦ ﻤﺴﺘﺨﺪم ﺮﺳﻠﻬﺎ ﻟﻚ‬ ‫ﻟﻴﺮ‬ ‫اﻟﻤ‬ ‫اﻟﻘﻴ‬ ‫ﻟﻮ‬ ‫ﻣ‬ ‫اﻗ‬ ‫ﻓﺈن ﻣﺜﻞ ﻫﺬه اﻟﻤﺪﺧﻼت ﺗﻌﺪ أﻣﺮًا ﻃﺒﻴﻌﻴﺎً.‬ ‫ﻃ‬ ‫د ﻣﺴﺘﺨﺪم - ﻏﻠﺲ -‬ ‫ﻣﺒﺎﺷﺮة ، وﻓﻲ وﺟﻮد‬‫ﻚ ﻣﺒﺮﻣﺞ‬ ‫ﺒﺐ اﻟﺪﻣﺎر ﻟﻌﺎﺟﻞ ﻟﻠﻔﺌﺔ اﻟﺬي ﻗﻤﺖ ﺑﻌﻤﻠﻬﺎ ، ﻛﻤﺎ ان زﻣﻴﻠﻚ‬ ‫ﻛ‬ ‫اﻟ‬ ‫ﻃﺒﻌﺎ ﻫﺬا ﻤﺪﺧﻞ ﺳﻴﺴﺒ‬ ‫اﻟﻤ‬ ‫ﻃ ً‬‫ء ﺑﺮﻣﺠﺔ ﻣﺮ اﻟﺘﺤﻘﻖ ﻣﻦ اﻻدﺧﺎل ، ﻟﺬا ﻲ اﻟﻨﺼﻴﺤﺔ‬ ‫ﺗﺄﺗﻲ‬ ‫ل‬ ‫اﻣ‬ ‫ﻒ ﻧﻔﺴﻪ ﻋﻨﺎء‬ ‫ﺷﺎﺷﺎت اﻻدﺧﺎل ﻤﺎ ﻟﻦ ﻳﻜﻠﻒ‬ ‫رﺑﻤ‬ ‫ﺮ - وﺿﻊ ﺑﺪﻻ ﻣﻨﻬﺎ ل ﻟﻘﺮاءﺗﻬﺎ‬ ‫دوال‬ ‫ﻻً‬ ‫ﺨﺪﻣﻬﺎ - ﻤﺒﺮﻣﺞ اﻵﺧﺮ‬ ‫اﻟﻤ‬ ‫ﺮاﺗﻚ ﻣﻦ ﻟﻈﻬﻮر ﻟﻤﺴﺘﺨ‬ ‫اﻟ‬ ‫اﻟﺪاﺋﻤﺔ ، اﻣﻨﻊ ﻣﺘﻐﻴﺮ‬ ‫ﺑﺔ إﻟﻴﻬﺎ ﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫ﺑﺎﻟﺸ‬ ‫او اﻟﻜﺘﺎﺑ‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪class pe‬‬ ‫‪erson‬‬ ‫{‬ ‫;‪vate int Age‬‬ ‫‪priv‬‬ ‫‪publ‬‬ ‫)‪lic string SetAge(in x‬‬ ‫‪nt‬‬ ‫{‬ ‫)1 < ‪if (x > 100 || x‬‬ ‫‪nt edit ag like th‬‬ ‫‪return "you can‬‬ ‫‪ge‬‬ ‫;"‪hat‬‬ ‫;‪Age = x‬‬ ‫;"‪return "done‬‬ ‫}‬ ‫)(‪lic int GetAge‬‬ ‫‪publ‬‬ ‫{‬ ‫;‪return Age‬‬ ‫}‬ ‫}‬‫261‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬   ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ VB.NET ‫ﻛﻮد‬ Class person Private Age As Integer Public Function SetAge(ByVal x As Integer) As String If x > 100 OrElse x < 1 Then Return "you cant edit age like that" End If Age = x Return "done" End Function Public Function GetAge() As Integer Return Age End Function End Class‫ ﻳﻨﺒﻐﻲ ان ﺗﺄﺧﺬ اﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬Set ‫ ﻫﻮ ﺧﻄﺎ ﻛﻤﺎ اﺗﻔﻘﻨﺎ ﺳﺎﺑﻘﺎ ، داﻟﺔ‬x ‫ﻃﺒﻌﺎ ﺗﺴﻤﻴﺔ اﻟﻤﺘﻐﻴﺮات ﺑﺎﺳﻢ‬ ً ً :‫ﻣﺜﻼ‬ ً C# ‫ﻛﻮد‬ public string SetAge(int Age) { if (Age > 100 || Age < 1) return "you cant edit age like that"; this.Age = Age; return "done"; } VB.NET ‫ﻛﻮد‬ Public Function SetAge(ByVal Age As Integer) As String If Age > 100 OrElse Age < 1 Then Return "you cant edit age like that" End If Me.Age = Age Return "done" End Function ...‫ ﻓﻲ اﻟﺪرس اﻟﺴﺎﺑﻖ‬Me ‫ أو‬this ‫وذﻟﻚ ﺣﺴﺒﻤﺎ ﺗﻌﻠﻤﻨﺎ ﻣﻦ ﺧﺼﺎﺋﺺ‬‫رﺑﻤﺎ ﻳﺒﺪو ﻟﻚ اﻷﻣﺮ ﻣﻤﻼ او ﻃﻮﻳﻼ ، ﻟﻜﻨﻪ ﻣﺜﻞ ﻫﺬه اﻷﻣﻮر ﻓﻲ اﻟﻤﺸﺎرﻳﻊ اﻟﺠﺪﻳﺔ ﺗﻌﺪ ﻧﻘﺎﻃﺎ ﺣﻴﻮﻳﺔ‬ ً ً ً .‫ﻻ ﻳﻤﻜﻦ اﻻﺳﺘﻐﻨﺎء ﻋﻨﻬﺎ ﻹﻧﻬﺎ ﻗﺪ ﺗﺘﺴﺒﺐ ﻓﻲ ﺳﻘﻮط ﻟﻠﻤﺸﺮوع ﻳﻜﻠﻒ ﻋﺪة ﻣﻼﻳﻴﻦ ﺑﺴﺒﺐ ﺧﻄﺄ ﺑﺴﻴﻂ‬ ‫ﻣﻼﺣﻈﺔ‬ Mutator ‫ ﻓﺘﺴﻤﻰ ﺑﺎﺳﻢ‬SetAge ‫ أﻣﺎ اﻟﺪاﻟﺔ‬Accessor ‫ ﻳﻄﻠﻖ ﻋﻠﻴﻬﺎ اﺳﻢ‬GetAge ‫اﻟﺪاﻟﺔ‬163
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ ‫7. 2. ارﺳﺎل اﻟﻘﻴﻢ ﻛﺠﺰء ﻣﻦ ال ‪Constructor‬‬‫ﻃﺮﻳﻘﺔ أﺧﺮى ﻳﻤﻜﻨﻚ اﺳﺘﺨﺪاﻣﻬﺎ ﻛﺒﺪﻳﻞ او ﻣﻊ اﻟﻄﺮﻳﻘﺔ اﻟﺴﺎﺑﻘﺔ ، وﻫﻲ اﺗﺎﺣﺔ اﻟﻔﺮﺻﺔ‬‫ﻟﻠﻤﺴﺘﺨﺪم ﻟﺘﻤﺮﻳﺮ ﺑﺎرﻣﻴﺘﺮات ﻗﻴﻢ اﻟﻤﺘﻐﻴﺮات ﺿﻤﻦ اﻟﻤﺸﻴﺪ ‪ ،Constructor‬ﻓﻲ اﻟﻔﺌﺎت اﻟﻜﺒﻴﺮة‬ ‫ﺳﻴﻜﻮن ﻟﺰاﻣﺎ ﻋﻠﻴﻚ اﺳﺘﺨﺪام اﻟﻄﺮﻳﻘﺔ اﻷوﻟﻰ إﻟﻰ ﺟﺎﻧﺐ ﻫﺬه اﻟﻄﺮﻳﻘﺔ ﺣﻴﺚ اﻧﻚ ﻟﻦ ﺗﺘﺼﻮر‬ ‫ً‬ ‫اﻟﻤﺴﺘﺨﺪم ﻳﻘﻮم ﺑﺘﻤﺮﻳﺮ ﻗﻴﻢ ﻛﻞ اﻟﻤﺘﻐﻴﺮات ﻟﺤﻈﺔ اﻧﺸﺎء ‪ Object‬ﻣﻦ ال ‪Class‬‬ ‫ﻣﺜﺎل ﻫﺬه اﻟﻄﺮﻳﻘﺔ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪class Person‬‬ ‫{‬ ‫;‪private int Age‬‬ ‫)‪public Person(int Age‬‬ ‫{‬ ‫)1 < ‪if (Age > 100 || Age‬‬ ‫;"‪return "you cant edit age like that‬‬ ‫;‪this.Age = Age‬‬ ‫;"‪return "done‬‬ ‫}‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Class Person‬‬ ‫‪Private Age As Integer‬‬ ‫)‪Public Sub New(ByVal Age As Integer‬‬ ‫‪If Age > 100 OrElse Age < 1 Then‬‬ ‫"‪Return "you cant edit age like that‬‬ ‫‪End If‬‬ ‫‪Me.Age = Age‬‬ ‫"‪Return "done‬‬ ‫‪End Sub‬‬ ‫‪End Class‬‬‫461‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ ‫7. 3. اﺳﺘﺨﺪام ال  ‪Type Property‬‬‫ﺑﻨﻔﺲ اﻟﻄﺮﻳﻘﺔ اﻟﺴﺎﺑﻘﺔ ، وﻟﻜﻦ ﺑﻄﺮﻳﻘﺔ اﺧﺮى واﻋﺘﻤﺎدًا ﻋﻠﻰ ﺗﺤﻮﻳﻞ اﻟﻤﺘﻐﻴﺮ إﻟﻰ ﺧﺎﺻﻴﺔ ﻟﻜﻞ‬ ‫ﻣﻨﻬﺎ داﻟﺘﺎن ‪ Set‬و ‪ ، Get‬ﻳﺘﻢ ﻛﺘﺎﺑﺔ ذﻟﻚ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪class Person‬‬ ‫{‬ ‫‪public int Age‬‬ ‫{‬ ‫} ;‪get { return Age‬‬ ‫‪set‬‬ ‫{‬ ‫))1 < ‪if (!(value > 100 || value‬‬ ‫;‪Age = value‬‬ ‫}‬ ‫}‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Class Person‬‬ ‫‪Public Property Age() As Integer‬‬ ‫‪Get‬‬ ‫‪Return Age‬‬ ‫‪End Get‬‬ ‫)‪Set(ByVal value As Integer‬‬ ‫‪If Not (value > 100 OrElse value < 1) Then‬‬ ‫‪Age = value‬‬ ‫‪End If‬‬ ‫‪End Set‬‬ ‫‪End Property‬‬ ‫‪End Class‬‬‫واﻵن ﻳﻤﻜﻨﻚ اﻟﻮﺻﻮل اﻟﻤﺒﺎﺷﺮ إﻟﻰ ‪ ، Age‬وﻟﻜﻦ ﻗﺒﻞ ﺗﻄﺒﻴﻖ اي ﺷﻲء ﺳﻴﺘﻢ اﺳﺘﺪﻋﺎء ‪ ، Set‬وﻓﻲ‬‫ﺣﺎﻟﺔ ﻃﻠﺐ ﺷﻲء ﺳﻴﺘﻢ اﻟﺤﺼﻮل ﻋﻠﻴﻪ ﻣﻦ ‪ ، Get‬وﻫﻮ ﻣﺎ ﻳﺘﻴﺢ ﻟﻚ اﻟﺘﺄﻛﺪ ﻣﻦ ﺑﻴﺎﻧﺎت اﻻدﺧﺎل او‬ ‫ﻋﻤﻞ ﺑﻌﺾ اﻟﻌﻤﻠﻴﺎت ﻋﻠﻰ ﻋﻤﻠﻴﺎت اﻻﺧﺮاج.‬‫ﻟﻌﻠﻚ ﻻﺣﻈﺖ اﻳﻀﺎ أن ‪ Set‬و ‪ Get‬ﻫﻤﺎ ‪ public‬ﻻن اﻟﺨﺎﺻﻴﺔ )وﻟﻴﺲ اﻟﻤﺘﻐﻴﺮ ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ(‬ ‫ً‬‫اﻟﻤﺴﻤﺎه ‪ Age‬ﻫﻲ ‪ ، public‬وﻟﻜﻦ ﻣﻨﺬ  0.2  ‪ .net‬اﺻﺒﺢ ﺑﺎﻣﻜﺎﻧﻚ اﻟﺘﻌﺪﻳﻞ ﻓﻲ ﻣﻌﺮف اﻟﻮﺻﻮل‬ ‫اﻟﺨﺎص ب ‪ Set‬او ‪ Get‬ﻋﻠﻰ ﺣﺪة ، ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬‫561‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬   ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬C# ‫ﻛﻮد‬public int Age{ get { return Age; } protected set { Age = value; }}VB.NET ‫ﻛﻮد‬Public Property Age() As Integer Get Return Age End Get Protected Set(ByVal value As Integer) Age = value End SetEnd Property‫، أﻣﺎ ﻟﻮ اردت اﻟﻌﻜﺲ‬Set ‫ ﻓﻴﻤﻜﻨﻚ ازاﻟﺔ اﻟﺨﺎﺻﻴﺔ‬Read Only Property  ‫إذا ﻛﻨﺖ ﺗﺮﻏﺐ ﻓﻲ ﻋﻤﻞ‬ : Read Only Property‫، ﻫﺬا اﻟﻤﺜﺎل ل‬Get ‫ ﻓﺄزل اﻟﺨﺎﺻﻴﺔ‬Write Only Property ‫ﻟﻌﻤﻞ‬C# ‫ﻛﻮد‬public int Age{ get { return Age; }}VB.NET ‫ﻛﻮد‬Public ReadOnly Property Age() As Integer Get Return Age End GetEnd Property Inheritance ‫8. اﻟـﻮراﺛـﺔ‬ ‫ ﻟﻬﺎ ﺛﻼث ﻋﻨﺎﺻﺮ اﺳﺎﺳﻴﺔ ، ﻗﻤﻨﺎ ﺑﺸﺮح اﻟﻤﻔﻬﻮم اﻷول‬OOP ‫ذﻛﺮﻧﺎ ﻓﻲ درس ﺳﺎﺑﻖ ان‬ . Inheritance ‫ ﻓﻲ دروس ﺳﺎﺑﻘﺔ ، واﻵن ﻣﻮﻋﺪﻧﺎ ﻣﻊ ال‬Encapsulation :‫اﻵن ﺳﻨﺒﺪأ ﺑﻌﻤﻞ ﻣﺜﺎل ﻧﺘﺎﺑﻊ ﻣﻌﻪ اﻟﻌﻤﻞ ، ﻟﻨﻔﺘﺮض اﻟﻤﺜﺎل اﻟﺴﺎﺑﻖ اﻟﺬي ﺷﺮﺣﻨﺎه اﻟﺨﺎص ﺑﺎﻟﻌﺮﺑﺔ‬166
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬   ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ 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.NET ‫ﻛﻮد‬ 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 .‫ﺳﻨﺒﺪأ ﺑﻬﺬا اﻟﻤﺜﺎل اﻟﺒﺴﻴﻂ ، وﻧﺘﺎﺑﻊ اﻟﻌﻤﻞ ﻋﻠﻰ ﺗﻄﻮﻳﺮه وﺗﺤﺴﻴﻨﻪ ﺧﻼل ﻣﺮاﺣﻞ ﻫﺬا اﻟﺪرس‬ is‐a ‫8. 1. ﺗﻌﺮﻳﻒ اﻟﻌﻼﻗﺔ‬‫ ، ﺳﻨﺤﺎول‬has‐a ‫ وﻗﺪ ﺗﻜﻮن‬is‐a ‫ﻛﻤﺎ ذﻛﺮﻧﺎ ﻓﻲ اﻟﺪرس اﻟﺴﺎﺑﻊ ﻋﺸﺮ ، ﻓﺈن اﻟﻌﻼﻗﺔ ﻗﺪ ﺗﻜﻮن‬، ‫اﻵن ﺷﺮح اﻟﻨﻮع اﻷول ﻣﻦ اﻟﻌﻼﻗﺎت واﻟﺬي ﻳﻌﻨﻲ ان اﻟﻔﺌﺔ اﻟﻤﺸﺘﻘﺔ ﻫﻮ ﻣﻦ ﻧﻮع اﻟﻔﺌﺔ اﻟﺮﺋﻴﺴﻴﺔ‬ BMW ‫ﺳﻨﻔﺘﺮض ﺳﻴﺎرة‬ C# ‫ﻛﻮد‬ class BMW : Car { }167
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫‪Class BMW‬‬ ‫‪Inherits Car‬‬‫‪End Class‬‬‫ﻫﻜﺬا ﻧﺴﺘﻄﻴﻊ ان ﻧﻘﻮل ان اﻟﻔﺌﺔ اﻟﺒﻨﺖ ‪ BMW‬ﻳﺤﺘﻮي ﻋﻠﻰ ﻧﻔﺲ ﺧﺼﺎﺋﺺ اﻟﻔﺌﺔ اﻷم ‪ Car‬وﻧﻔﺲ‬‫دواﻟﻪ وﻃﺮﻗﻪ ال ‪ public‬ﻓﻘﻂ ، وﻟﻜﻦ ﻟﻨﻔﺘﺮض اﻧﻨﺎ ﻓﻲ اﻟﻔﺌﺔ اﻻﺑﻦ ﻧﺤﺎول اﻟﻮﺻﻮل اﻟﻤﺒﺎﺷﺮ إﻟﻰ‬ ‫اﻟﺨﺎﺻﻴﺔ ‪ carName‬ﻓﻠﻦ ﻧﺘﻤﻜﻦ ﻣﻦ ذﻟﻚ ، ﻫﺬا اﻟﻤﺜﺎل ﻳﻮﺿﺢ ﻫﺬه اﻟﻨﻘﻄﺔ:‬‫#‪C‬‬ ‫ﻛﻮد‬‫;)(‪BMW ahmedcar = new BMW‬‬‫;"‪ahmedcar.carName = "anyname‬‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫)(‪Dim ahmedcar As New BMW‬‬‫"‪ahmedcar.carName = "anyname‬‬‫ﺣﺘﻰ ﻟﻮ ﻗﻤﻨﺎ ﺑﺘﻌﺮﻳﻒ ﺑﻌﺾ اﻟﺪوال داﺧﻞ اﻟﻔﺌﺔ اﻟﻤﺸﺘﻘﺔ ﺑﺤﻴﺚ ﺗﺴﺘﻄﻴﻊ اﻟﻮﺻﻮل إﻟﻰ ﻫﺬه اﻟﺨﺎﺻﻴﺔ ،‬ ‫ﻟﻨﻔﺘﺮض اﻧﻨﺎ اﻋﺪﻧﺎ ﺻﻴﺎﻏﺔ اﻟﻔﺌﺔ ‪ BMW‬ﻟﻴﻜﻮن ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬‫#‪C‬‬ ‫ﻛﻮد‬‫‪class BMW: Car‬‬‫{‬ ‫)‪public void changeCarName (string value‬‬ ‫{‬ ‫;‪carName = value‬‬ ‫}‬‫}‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫‪Class BMW‬‬ ‫‪Inherits Car‬‬ ‫)‪Public Sub changeCarName (ByVal value As String‬‬ ‫‪carName = value‬‬ ‫‪End Sub‬‬‫‪End Class‬‬‫ﻟﻼﺳﻒ ﻟﻦ ﻳﻜﻮن ﻫﺬا ﺻﺤﻴﺤﺎً ﺗﻤﺎﻣﺎ ، ﺣﻴﺚ اﻧﻚ ﺑﺎﻟﺮﺟﻮع إﻟﻰ درس ﻣﻌﺮﻓﺎت اﻟﻮﺻﻮل ﺳﺘﻜﺸﺘﻒ ان‬ ‫ً‬‫ﻣﻌﺮف اﻟﻮﺻﻮل ‪ private‬ﻻ ﻳﻤﻜﻦ اﻟﻮﺻﻮل ﻟﻪ ﻣﻦ اﻟﻔﺌﺔ اﻟﻤﺸﺘﻘﺔ، ﻣﻦ اﺟﻞ ﻫﺬا ﻧﺴﺘﺨﺪم ﻣﻌﺮف‬‫861‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬   ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬‫ ﻓﻲ ﻛﻮﻧﻪ ﻻ ﻳﻤﻜﻦ اﻟﻮﺻﻮل اﻟﻤﺒﺎﺷﺮ ﻟﻪ ﻣﻦ‬private ‫ ﺣﻴﺚ اﻧﻪ ﻳﺸﺒﻪ ال‬protected ‫اﻟﻮﺻﻮل‬‫ ، ﻟﻜﻨﻪ ﻓﻲ اﻟﻤﻘﺎﺑﻞ ﻳﻤﻜﻦ اﻟﻮﺻﻮل إﻟﻴﻪ ﻣﻦ داﺧﻞ اﻟﻔﺌﺔ اﻟﻤﺸﺘﻘﺔ ، ﻟﻮ اﻓﺘﺮﺿﻨﺎ‬object ‫ﺧﻼل ال‬ : ‫ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬Car ‫ﻣﺜﺎل اﻟﻔﺌﺔ‬ C# ‫ﻛﻮد‬ class Car { protected string carName; protected int carModel; } VB.NET ‫ﻛﻮد‬ Class Car Protected carName As String Protected carModel As Integer End Class‫ ﺗﻘﻮم ﺑﻘﺮاءة ﻫﺬه اﻟﻤﺘﻐﻴﺮات ، ﻟﺬا‬BMW ‫ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﻳﻤﻜﻨﻨﺎ ﺗﻌﺮﻳﻒ داﻟﺔ داﺧﻞ اﻟﻔﺌﺔ اﻟﻤﺸﺘﻘﺔ‬ :ً‫ﺳﻮف ﻳﻜﻮن اﻟﻜﻮد اﻟﺘﺎﻟﻲ ﺻﺤﻴﺤﺎ‬ C# ‫ﻛﻮد‬ class BMW: Car { public void changeCarName(string value) { carName = value; } } VB.NET ‫ﻛﻮد‬ Class BMW Inherits Car Public Sub changeCarName(ByVal value As String) carName = value End Sub End Class169
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ ‫‪NotInheritable - sealed‬‬ ‫8. 2. اﻟﻜﻠﻤﺔ اﻟﻤﺤﺠﻮزة‬ ‫ﻳﻌﻨﻲ اﺳﺘﺨﺪام ﻫﺬه اﻟﻜﻠﻤﺔ ان ﻫﺬا اﻟﻔﺌﺔ ﻻ ﻳﻤﻜﻦ اﻻﺷﺘﻘﺎق ﻣﻨﻪ ، ﻳﺘﻢ ذﻟﻚ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪sealed class Car‬‬ ‫{‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪NotInheritable Class Car‬‬ ‫‪End Class‬‬ ‫ﻣﻼﺣﻈﺔ‬ ‫اﻟﻜﻠﻤﺔ ‪ NotInheritable‬ﺗﻘﺎﺑﻞ ‪ sealed‬ﻓﻲ #‪C‬‬ ‫ ‬ ‫8. 3. اﻟﻮراﺛﺔ اﻟﻤﺘﻌﺪدة‬ ‫ﻻ ﺗﻮﻓﺮ ﻟﻐﺔ اﻟﺴﻲ ﺷﺎرب او ال  ‪ VB.net‬ﻣﺒﺪأ اﻟﻮراﺛﺔ اﻟﻤﺘﻌﺪدة ، ﻓﻲ ﺣﻴﻦ ﺗﻄﺒﻘﻪ ﻓﻘﻂ‬‫ ++‪ ،managed  c‬ﻣﻌﻨﻰ ﻛﻠﻤﺔ اﻟﻮراﺛﺔ اﻟﻤﺘﻌﺪدة ان ﺑﺎﻣﻜﺎن ﻓﺌﺔ ﻣﺎ ان ﺗﺸﺘﻖ ﻣﻦ اﻛﺜﺮ ﻣﻦ ﻓﺌﺔ ،‬‫ﻟﻨﻔﺘﺮض ﻟﺪﻳﻨﺎ ﻓﺌﺔ ﺷﺎﺣﻨﺔ وﻓﺌﺔ ﺳﻴﺎرة ، ﻓﻲ ﺣﺎﻟﺔ دﻋﻢ ﻟﻐﺔ ﻣﺎ ﻟﻠﻮراﺛﺔ اﻟﻤﺘﻌﺪدة ﻓﺈﻧﻨﺎ ﻧﺴﺘﻄﻴﻊ ﻋﻤﻞ‬‫ﻧﻮع ﺟﺪﻳﺪ ﻳﺤﺘﻮي ﻋﻠﻰ ﺧﺼﺎﺋﺺ اﻟﺸﺎﺣﻨﺔ واﻟﺴﻴﺎرة اﻟﻌﺎدﻳﺔ ، وﻟﻜﻦ ﻫﺬا ﻣﺎ ﻻ ﺗﻮﻓﺮه ﻛﻞ ﻣﻦ اﻟﺴﻲ‬ ‫ﺷﺎرب او ال ‪. VB.net‬‬‫وﻛﺒﺪﻳﻞ ﻟﺬﻟﻚ ، ﺗﻘﺪم اﻟﻠﻐﺘﺎن دﻋﻢ ﻟﻌﻤﻞ ‪ Implementation‬ﻻﻛﺜﺮ ﻣﻦ ‪ ، interface‬وﻫﻮ‬ ‫ﻣﺎ ﺳﻨﺘﻌﺮف ﻋﻠﻴﻪ ﺣﻴﻨﻤﺎ ﻧﺼﻞ إﻟﻰ ﻫﺬا اﻟﺠﺰء.‬ ‫أﻣﺎ ﻟﻤﺎذا ﻟﻢ ﺗﻘﺪم ﻣﺎﻳﻜﺮوﺳﻮﻓﺖ دﻋﻢ اﻟﻮراﺛﺔ اﻟﻤﺘﻌﺪدة ﻓﻲ #‪ C‬و ‪ ، VB.net‬إﻟﻴﻚ ﻫﺬا اﻟﺮاﺑﻂ:‬‫071‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ ‫راﺑﻂ‬ ‫‪http://blogs.msdn.com/csharpfaq/archive/2004/03/07/85562.aspx‬‬ ‫8. 4. اﻟﺘﻌﺪﻳﻞ ﻓﻲ اﻟﻔﺌﺎت اﻟﻤﺸﺘﻘﺔ‬‫ﻛﻤﺎ رأﻳﻨﺎ ﻓﻲ اﻟﺪروس اﻟﺴﺎﺑﻘﺔ ، ﻳﻤﻜﻨﻨﺎ اﻟﺘﻌﺪﻳﻞ ﻣﺒﺎﺷﺮة ﻋﻠﻰ ﺧﺼﺎﺋﺺ وﻃﺮق وأﺣﺪاث‬‫ودوال اﻟﻔﺌﺔ اﻟﺠﺪﻳﺪة ، ﻓﻲ اﻟﻤﺜﺎل اﻟﺴﺎﺑﻖ ﻗﻤﻨﺎ ﺑﺎﺿﺎﻓﺔ داﻟﺔ ﺗﺴﻤﺢ ﻟﻨﺎ ﺑﺘﻐﻴﻴﺮ اﻻﺳﻢ ، ﻳﻤﻜﻨﻨﺎ اﺿﺎﻓﺔ‬‫ﺧﺎﺻﻴﺔ ﺟﺪﻳﺪة ﻟﻠﻔﺌﺔ ‪ BMW‬ﺗﺤﺘﻮي ﻋﻠﻰ ﻋﺪد أﺟﻬﺰة اﻟﺘﻠﻔﺰﻳﻮن داﺧﻞ اﻟﺴﻴﺎرة ﻛﻤﻴﺰة اﺿﺎﻓﻴﺔ ﻓﻲ‬ ‫اﻟﺴﻴﺎرات ﻣﻦ ﻧﻮع ‪ ،BMW‬وﻫﻜﺬا...‬ ‫ﻳﻤﻜﻨﻨﺎ ﻋﻤﻞ ﻓﺌﺔ أﺧﺮى ﻟﻌﺮﺑﺔ ﻓﻴﺮاري ، ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﻳﻤﻜﻨﻨﺎ اﺿﺎﻓﺔ ﻋﺪد اﻟﻔﺘﺤﺎت اﻟﺠﺎﻧﺒﻴﺔ‬ ‫ﻟﻠﻤﺤﺮك . ﻟﻜﻦ ﻟﻮ اﺣﺘﺠﻨﺎ ﻓﻲ ﻣﺮﺣﻠﺔ اﻟﻰ ﺗﻌﺮﻳﻒ ﺧﺎﺻﻴﺔ ‪ maxSpeed‬ﻟﺠﻤﻴﻊ اﻟﺴﻴﺎرات ﻓﻴﻜﻔﻲ‬ ‫اﺿﺎﻓﺘﻬﺎ ﻓﻲ اﻟﻔﺌﺔ اﻻﺳﺎﺳﻴﺔ ‪ Car‬وﺳﺘﺠﺪﻫﺎ ﻣﻮﺟﻮدة ﺗﻠﻘﺎﺋﻴﺎ ﻓﻲ اﻟﻔﺌﺎت اﻷﺑﻨﺎء ﺟﻤﻴﻌﺎ.‬ ‫ً‬ ‫ً‬‫ﻣﻦ ﻫﻨﺎ ﻧﺴﺘﻄﻴﻊ ان ﻧﻼﺣﻆ ان واﺣﺪة ﻣﻦ اﻟﻔﻮاﺋﺪ اﻟﺮﺋﻴﺴﻴﺔ ﻟﻌﻤﻠﻴﺔ اﻟﻮراﺛﺔ ﻫﻲ وﺿﻊ ﻗﺎﻋﺪة ﻋﺎﻣﺔ‬‫ﻟﻠﻌﻨﺎﺻﺮ اﻟﻤﺘﺸﺎﺑﻬﺔ ، وﻋﻤﻞ ﻧﺴﺦ ﻻﺿﺎﻓﺔ ﻧﻘﺎط اﻻﺧﺘﻼف ﻓﻘﻂ ﺑﺪﻻ ﻣﻦ اﻋﺎدة ﺗﻜﺮار ﻛﻞ ﻣﻨﻬﺎ ﻋﺪة‬ ‫ً‬ ‫ﻣﺮات ، رﺑﻤﺎ ﻟﻦ ﺗﺠﺪ اﻟﻔﺮق ﻛﺒﻴﺮًا ﻓﻲ اﻟﻤﺜﺎل اﻟﺴﺎﺑﻖ ﺣﻴﺚ اﻧﻨﺎ ﻧﻌﻤﻞ ﻣﻊ 3 او 4 ﺧﺼﺎﺋﺺ ﻓﻘﻂ ،‬‫وﻟﻜﻦ ﻓﻲ ﻣﺜﺎل ﺣﻘﻴﻘﻲ ﻣﻊ ﻋﺪة اواﻣﺮ ﻟﻠﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻤﺴﺘﺨﺪم وﻟﻠﺤﻔﻆ ﻓﻲ ﻗﺎﻋﺪة اﻟﺒﻴﺎﻧﺎت واﻟﻄﺒﺎﻋﺔ‬ ‫واﻟﻌﺮض واﻟﻌﻤﻠﻴﺎت اﻟﺤﺴﺎﺑﻴﺔ ﺳﺘﺴﺘﻄﻴﻊ ان ﺗﺪرك اﻟﻔﺎرق ﺑﻴﻦ اﺳﺘﺨﺪام ﻣﻔﻬﻮم اﻟﻮراﺛﺔ وﻋﺪﻣﻪ.‬ ‫8. 5. اﻟﻌﻼﻗﺔ ﻣﻦ ﻧﻮع ‪has‐a‬‬‫ﻛﻤﺎ اوﺿﺤﻨﺎ ﻓﻲ اول درﺳﻨﺎ ﻓﻬﺬا ﻫﻮ اﻟﻨﻮع اﻟﺜﺎﻧﻲ ﻣﻦ اﻟﻌﻼﻗﺎت ﺑﻴﻦ اﻟﻔﺌﺎت اﻟﻤﺨﺘﻠﻔﺔ، ﻫﺬا‬ ‫اﻟﻨﻮع ﻳﻌﻨﻲ ان اﻟﻔﺌﺔ ﺗﺤﺘﻮي ﻋﻠﻰ ﻓﺌﺔ أﺧﺮى ، ﻟﻮ اﻓﺘﺮﺿﻨﺎ ﻣﺜﺎل ﻓﺌﺔ اﻟﻌﺠﻼت ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪class Tires‬‬ ‫{‬ ‫;‪int TiresType‬‬ ‫;‪int TiresSize‬‬ ‫}‬‫171‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Class Tires‬‬ ‫‪Private TiresType As Integer‬‬ ‫‪Private TiresSize As Integer‬‬ ‫‪End Class‬‬ ‫ﻧﻌﺮف ﻳﻘﻴﻨﺎ ان اﻻﻃﺎرات ﻟﻴﺴﺖ ﻣﻦ ﻧﻮع ﺳﻴﺎرة ‪ Tire is not a Car‬وﻟﻜﻨﻬﺎ ﺟﺰء ﻣﻦ اﻟﺴﻴﺎرة ‪Car‬‬ ‫‪ ،has a Tire‬ﻟﺬا ﻳﻤﻜﻨﻨﺎ ﺗﻌﺮﻳﻒ ﻓﺌﺔ اﻟﺴﻴﺎرة ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ :‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪class Car‬‬ ‫{‬ ‫;)(‪Tires carTires = new Tires‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Class Car‬‬ ‫)(‪Private carTires As New Tires‬‬ ‫‪End Class‬‬ ‫ﻣﻼﺣﻈﺔ‬ ‫ﻻ ﺗﻨﺲ ان ﺑﺎﻣﻜﺎﻧﻚ ﺗﻌﺮﻳﻔﻬﺎ ﻛـ ‪ private‬او ‪ protected‬وﻋﻤﻞ ﺧﺎﺻﻴﺔ ﻟﻬﺎ ﻣﻦ اﺟﻞ اﻟﻘﺮاءة‬ ‫واﻟﻜﺘﺎﺑﺔ إﻟﻴﻬﺎ‬ ‫ ‬ ‫8. 6. اﻟﺘﺤﻮﻳﻼت ‪Casting‬‬ ‫ﻳﻘﺼﺪ ﺑﺎل ‪ Casting‬ﻋﻤﻮﻣﺎ ﻫﻮ اﻟﺘﺤﻮﻳﻞ ﻣﻦ ﻧﻮع إﻟﻰ آﺧﺮ ، ﺗﻢ ﺷﺮح اﻟﻤﻔﻬﻮم اﻟﻌﺎم ﻟﻪ‬ ‫ً‬ ‫واﻧﻮاﻋﻪ ﻓﻲ درس ﺳﺎﺑﻖ .‬ ‫واﻵن ﺳﻨﺤﺎول ﺗﻄﺒﻴﻖ ﻧﻔﺲ اﻟﻤﻔﺎﻫﻴﻢ ﻋﻠﻰ ال ‪ ،Classes‬اﻟﻄﺮﻳﻘﺔ اﻷوﻟﻰ ﻟﻠﺘﺤﻮﻳﻞ ﻫﻲ اﺳﺘﺨﺪام‬ ‫"‪  "cast‬اﻟﻌﺎدﻳﺔ ، ﻣﺜﻼ ﻟﻮ ﻗﻤﻨﺎ ﺑﺘﻌﺮﻳﻒ ﺳﻴﺎرة ‪:BMW‬‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)(‪BMW ahmedCar = new BMW‬‬ ‫271‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)(‪Dim ahmedCar As New BMW‬‬‫وﻗﻤﻨﺎ ﺑﺎرﺳﺎل اﻟﻤﺘﻐﻴﺮ إﻟﻰ داﻟﺔ ﺗﻘﻮم ﺑﺎﺳﺘﻘﺒﺎل ‪ BMW‬ﻓﺴﻮف ﺗﻌﻤﻞ ﺑﺼﻮرة ﺻﺤﻴﺤﺔ ، اﻳﻀﺎ ﻟﻮ ﻗﻤﻨﺎ‬ ‫ً‬‫ﺑﺎرﺳﺎﻟﻬﺎ إﻟﻰ داﻟﺔ ﺗﺴﺘﻘﺒﻞ ‪ Car‬ﻓﺴﻴﻜﻮن ﻫﺬا ﺻﺤﻴﺤﺎ ﻹن ﻛﻞ ‪ BMW‬ﻫﻲ ﻓﻲ اﻟﺤﻘﻴﻘﺔ ‪ ، Car‬ﺑﻴﻨﻤﺎ‬ ‫اﻟﻌﻤﻠﻴﺔ اﻟﻌﻜﺴﻴﺔ ﻟﻴﺴﺖ ﺻﺤﻴﺤﺔ .‬ ‫اﻟﻨﻘﻄﺔ اﻟﺜﺎﻧﻴﺔ ﻟﻮ ﻗﻤﻨﺎ ﺑﺘﻌﺮﻳﻒ ‪ BMW‬ﺑﺎﻟﺼﻮرة اﻟﺘﺎﻟﻴﺔ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)(‪Car ahmedCar = new BMW‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)(‪Dim ahmedCar As Car = New BMW‬‬‫ﻫﺬا اﻟﻤﻮﺿﻮع ﺻﺤﻴﺢ ﻓﻌﻼ وﻫﻮ ﻣﺎ ﻳﺪﻋﻰ ﺑﺎﺳﻢ ‪ ، implicit cast‬واﻵن ﻳﻤﻜﻦ ارﺳﺎل اﻟﻤﺘﻐﻴﺮ ﻣﺒﺎﺷﺮة‬ ‫ً‬ ‫إﻟﻰ ﺗﻠﻚ اﻟﺪاﻟﺔ اﻟﺘﻲ ﺗﺴﺘﻘﺒﻞ ‪.Car‬‬ ‫ﻟﻨﻔﺘﺮض ﻣﺜﺎﻻ آﺧﺮ ﻗﻤﻨﺎ ﻓﻴﻪ ﺑﺘﻌﺮﻳﻒ ‪ BMW‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)(‪Object ahmedCar = new BMW‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)(‪Dim ahmedCar As Object = New BMW‬‬‫ﻫﺬا ﺻﺤﻴﺢ اﻳﻀﺎ ﻹن ﻛﻞ ﻓﺌﺔ ﻫﻮ ‪ Object‬اﻳﻀﺎ ، ﻟﻜﻦ ﻟﻮ ﻗﻤﻨﺎ ﺑﺎرﺳﺎل اﻟﻤﺘﻐﻴﺮ إﻟﻰ اﻟﺪاﻟﺔ اﻟﺘﻲ‬ ‫ً‬ ‫ً‬ ‫ﺗﺴﺘﻘﺒﻞ ‪ Car‬ﻓﺴﻮف ﺗﻈﻬﺮ رﺳﺎﻟﺔ ﺧﻄﺎ ، ﻟﺬا ﻧﻘﻮم ﺑﻌﻤﻞ ‪ cast‬ﺑﺄﺣﺪ اﻻﺷﻜﺎل اﻟﺘﺎﻟﻴﺔ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)‪functionname((Car)ahmedCar‬‬ ‫;)‪functionname((BMW)ahmedCar‬‬‫371‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫))‪functionname(DirectCast(ahmedCar, Car‬‬ ‫))‪functionname(DirectCast(ahmedCar, BMW‬‬ ‫8. 7. اﻟﻜﻠﻤﺔ اﻟﻤﺤﺠﻮزة ‪is‬‬ ‫ﺗﻘﻮم ﻫﺬه اﻟﻜﻠﻤﺔ ﺑﺎﺧﺘﺒﺎر ﻓﻴﻤﺎ إذا ﻛﺎن اﻟﻄﺮف اﻻول ﻫﻮ ﻣﻦ اﻟﻄﺮف اﻟﺜﺎﻧﻲ ، ﻣﺜﺎل‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪if (ahmedCar is BMW‬‬ ‫{‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪If TypeOf ahmedCar Is BMW Then‬‬ ‫‪End If‬‬‫ﺗﻔﻴﺪك ﻫﺬه اﻟﻜﻠﻤﺔ ﻓﻲ ﺣﺎﻟﺔ وﺟﻮد ﻋﺪة ﻣﺘﻐﻴﺮات ﻣﻦ ﻋﺪة اﻧﻮع ﻣﺸﺘﻘﺔ ﻣﻦ ﻧﻔﺲ اﻟﻔﺌﺔ ، وﻧﺮﻳﺪ ان‬ ‫ﻧﻌﺮف ﻓﻴﻤﺎ إذا ﻛﺎﻧﺖ ﻣﻦ ﻧﻮع ‪ BMW‬او ﻓﻴﺮاري ﻣﺜﻼ.‬ ‫ً‬ ‫8. 8.  ‪Visual Studio Class Diagram‬‬‫ﻳﻮﻓﺮ ﻟﻚ اﻟﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ اﺑﺘﺪاء ﻣﻦ اﻻﺻﺪار 5002 اداة ﻟﻌﻤﻞ ال  ‪ ، Class Diagram‬ﻫﺬا‬ ‫ﻣﺜﺎل ﻋﻠﻴﻬﺎ:‬‫471‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ ‫اﻟﺼﻮرة 8. 1. ‪  Visual Studio Class Designer‬‬ ‫ﻳﻤﻜﻨﻚ اﺿﺎﻓﺘﻬﺎ ﻣﻦ ‪ ، new ‐> class diagram‬وﻣﻦ ﺛﻢ اﻟﻌﻤﻞ ﻋﻠﻴﻬﺎ ﻣﺒﺎﺷﺮة ، او ﻋﺮض اﻟﻔﺌﺎت اﻟﺘﻲ‬ ‫ﻟﺪﻳﻚ ، ﻳﻤﻜﻨﻚ اﻧﺸﺎء اﻟﻌﻼﻗﺎت اﻟﻤﺨﺘﻠﻔﺔ ﻓﻲ ﻫﺬا اﻟﻮﺿﻊ .‬ ‫9. اﻟـ ‪Polymorphism‬‬ ‫ﺗﻌﺮﻓﻨﺎ ﻓﻲ درس ﺳﺎﺑﻖ ﻋﻠﻰ ﻣﻌﻨﻰ ال ‪ polymorphism‬ﺑﺸﻜﻞ ﻋﺎم ، اﻵن ﺳﻨﺘﻌﺮف ﻋﻠﻴﻪ ﺑﺼﻮرة أﻛﺜﺮ‬ ‫ﺗﻔﺼﻴﻼ ...‬ ‫ً‬ ‫اﻟﺘﻌﺮﻳﻒ اﻟﻤﺎﺿﻲ واﻟﺬي ﻳﺴﻤﺢ ﻟﻚ ﺑﺘﻌﺮﻳﻒ ‪ class‬ﺑﺪون اي ‪ ، implementation‬ﻳﻮﻓﺮ ﻟﻚ اﻳﻀﺎ‬ ‫ً‬ ‫ﻛﺘﺎﺑﺔ ﻛﻮد وﻟﻜﻦ ﻓﻲ اﻟﻤﻘﺎﺑﻞ ﻳﺴﻤﺢ ﻟﻚ ﺑﺘﻐﻴﻴﺮ ال‪ implementation‬اﻟﺨﺎص ﺑﺎﻟﺪاﻟﺔ ﺑﻴﻦ اﻟﻔﺌﺔ‬ ‫واﻷﺧﺮى ، وﻫﻮ ﻣﺎ ﻳﻌﺮف ﺑﺎﺳﻢ ‪.Overriding‬‬ ‫571‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬‫ﻟﻨﻔﺘﺮض ﻣﺜﺎل اﻟﺴﻴﺎرة اﻟﺨﺎص ﺑﻨﺎ ، ﻟﻮ اﻓﺘﺮﺿﻨﺎ وﺟﻮد اﻟﺪاﻟﺔ اﻟﺘﺎﻟﻴﺔ اﻟﺨﺎﺻﺔ ﺑﺤﺴﺎب اﻟﻤﺴﺎﻓﺔ‬ ‫اﻟﻤﺘﺒﻘﻴﺔ ﻟﻠﺴﻴﺎرة ﻗﺒﻞ ان ﻳﻨﻔﺪ اﻟﺒﻨﺰﻳﻦ ، وﺣﻴﺚ ان اﻟﺴﻴﺎرة )ﻣﺜﻼ( ﺗﺼﺮف ﺟﺎﻟﻮﻧﺎ ﻟﻜﻞ 01 ﻛﻴﻠﻮﻣﺘﺮ.‬ ‫ً‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪public int calc(int fuel‬‬ ‫{‬ ‫;01 * ‪return fuel‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Public Function calc(ByVal fuel As Integer) As Integer‬‬ ‫01 * ‪Return fuel‬‬ ‫‪End Function‬‬‫وﻟﻜﻦ ﺑﻌﺪ ﻋﻤﻠﻨﺎ ﻟﻠﺴﻴﺎرة ‪ BMW‬اﻛﺘﺸﻔﻨﺎ ان ﻫﺬه اﻟﺴﻴﺎرة ﻻ ﺗﺴﻴﺮ ﻋﻠﻰ ﻧﻔﺲ اﻟﻘﺎﻋﺪة ، إذ اﻧﻬﺎ ﺗﺼﺮف‬‫ﺟﺎﻟﻮﻧﺎ ﻟﻜﻞ 5 ﻛﻴﻠﻮﻣﺘﺮات ﻓﻘﻂ ، ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﻧﺤﻦ ﺑﺤﺎﺟﺔ إﻟﻰ اﻋﺎدة ﺗﻌﺮﻳﻒ اﻟﺪاﻟﺔ ‪ calc‬ﻓﻲ‬ ‫ً‬ ‫اﻟﻔﺌﺔ اﻟﻤﺸﺘﻘﺔ ، ﻫﺬا ﻫﻮ ﻣﺎ ﻳﻌﺮف ﺑﺎﺳﻢ اﻋﺎدة اﻟﻘﻴﺎدة ‪ Overriding‬وﻫﻮ اﺣﺪ ﻣﺒﺎدئ ال‬ ‫‪ .polymorphism‬ﻳﺘﻢ ذﻟﻚ ﻋﻦ ﻃﺮﻳﻖ ﺗﻌﺮﻳﻒ اﻟﺪاﻟﺔ اﻻﺳﺎﺳﻴﺔ ﻓﻲ ال ‪ base  class‬ﻣﻦ ﻧﻮع‬ ‫‪ virtual‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪public virtual int calc(int fuel‬‬ ‫{‬ ‫;01 * ‪return fuel‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Public Overridable Function calc(ByVal fuel As Integer) As Integer‬‬ ‫01 * ‪Return fuel‬‬ ‫‪End Function‬‬‫ال‪ virtual‬او ال ‪ overriddeable‬ﺗﻌﻨﻲ ان ﻫﺬه اﻟﺪاﻟﺔ ﻳﻤﻜﻦ اﻋﺎدة ﺗﻌﺮﻳﻔﻬﺎ ﻓﻲ اﻟﻔﺌﺔ‬ ‫اﻟﻤﺸﺘﻘﺔ ، ﻛﻤﺎ ﻳﻤﻜﻦ ﻋﺪم ﺗﻌﺮﻳﻔﻬﺎ اﻳﻀﺎ ، ﻻﻋﺎدة ﺗﻌﺮﻳﻔﻬﺎ ﻧﻜﺘﺐ اﻟﻜﻮد اﻟﺘﺎﻟﻲ ﻓﻲ اﻟﻔﺌﺔ اﻟﻤﺸﺘﻘﺔ :‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪public override int calc(int fuel‬‬ ‫{‬ ‫;5 * ‪return fuel‬‬ ‫}‬‫671‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Public Overloads Overrides Function calc(ByVal fuel As Integer) As Integer‬‬ ‫5 * ‪Return fuel‬‬ ‫‪End Function‬‬‫اﻳﻀﺎ ﻳﻤﻜﻨﻚ ﺗﺮك ال ‪ implementation‬ﻓﺎرﻏﺎ ﻓﻲ اﻟﻔﺌﺔ اﻟﺮﺋﻴﺴﻴﺔ وﻣﻦ ﺛﻢ ﻗﻢ ﺑﺒﺮﻣﺠﺘﻬﺎ ﻓﻲ اﻟﻔﺌﺎت‬ ‫ً‬ ‫ً‬‫اﻷﺑﻨﺎء ، ﺗﻌﺮف اﻟﻔﺌﺔ اﻟﻔﺎرغ ﻣﻦ ال ‪ implementation‬ﺑﺎﺳﻢ ‪ Abstract class‬وﻫﻮ ﻏﻴﺮ ال‪interface‬‬ ‫اﻟﺬي ﺳﻨﺘﻌﺮف ﻋﻠﻴﻪ ﻓﻲ ﻣﺮﺣﻠﺔ ﻗﺎدﻣﺔ.‬ ‫01. اﻟـ ‪Abstract‬‬‫ﻓﻲ اﻟﺪرس اﻟﺴﺎﺑﻖ ﺗﻌﺮﻓﻨﺎ ﻋﻠﻰ ﻣﻌﻨﻰ ﻛﻠﻤﺔ ‪ ، Abstract  class‬وﻋﺮﻓﻨﺎ اﻧﻬﺎ ﻣﺠﺮد ﻓﺌﺔ ﻋﺎدﻳﺔ‬‫ﺑﺪون ‪ ،implementation‬ﻟﻜﻦ ﻟﻜﻲ ﻧﺠﺒﺮ اﻧﻔﺴﻨﺎ ﻋﻠﻰ ﻋﻤﻞ ﻧﺴﺨﺔ ﻣﻨﻪ ﻗﺒﻞ اﺳﺘﺨﺪاﻣﻪ ، ﻧﺴﺘﺨﺪم‬ ‫اﻟﻜﻠﻤﺔ اﻟﻤﺤﺠﻮزة ‪ abstract‬ﻟﺘﻌﺮﻳﻔﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪abstract partial class Car‬‬ ‫{‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Partial MustInherit Class Car‬‬ ‫‪End Class‬‬ ‫ﻣﻼﺣﻈﺔ‬ ‫اﻟﻜﻠﻤﺔ اﻟﻤﺤﺠﻮزة ‪ MustInherit‬ﻓﻲ ‪ vb.net‬ﻫﻲ ﻣﻨﺎﻇﺮ ﻛﻠﻤﺔ ‪ abstract‬ﻓﻲ #‪C‬‬ ‫ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﺳﻮف ﻳﻌﻄﻴﻨﺎ ﻫﺬا اﻟﺘﻌﺮﻳﻒ ﺧﻄﺄ :‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)(‪Car ahmedCar = new Car‬‬‫771‬
  • ‫اﻟﻔﺌﺎت و ﻣﻘﺪﻣﺔ إﻟﻰ اﻟﺒﺮﻣﺠﺔ ﻛﺎﺋﻨﻴﺔ اﻟﺘﻮﺟﻪ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻣﻦ‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)(‪Dim ahmedCar As Car=new Car‬‬ ‫01. 1. ‪Abstract Method‬‬‫ذﻛﺮﻧﺎ ﻓﻲ اﻟﺪرس اﻟﺴﺎﺑﻖ اﻳﻀﺎ اﻧﻨﺎ ﻧﻘﻮم ﺑﺘﻌﺮﻳﻒ اﻟﺪوال ‪ virtual‬ﻟﻜﻞ ﻧﻘﻮم ﺑﻌﻤﻞ ‪overriding‬‬ ‫ً‬‫ﻟﻬﺎ ﻓﻲ اﻟﻔﺌﺔ اﻟﻤﺸﺘﻘﺔ ﻻﺣﻘﺎ ، وﻫﺬا ﻣﺎ ﻳﻌﻄﻴﻨﺎ اﻟﺤﻖ ﻓﻲ اﻋﺎدة ﻛﺘﺎﺑﺔ اﻟﻜﻮد اﻟﺨﺎص ﺑﻬﺎ او ﺗﺠﺎﻫﻠﻪ،‬ ‫ً‬‫ﻟﻜﻦ ﻟﻮ اردﻧﺎ اﺟﺒﺎر اﻟﻤﺒﺮﻣﺞ ﻋﻠﻰ اﻋﺎدة اﻟﻘﻴﺎدة ‪ overriding‬ﻧﻘﻮم ﺑﺬﻟﻚ ﺑﺘﻌﺮﻳﻒ‪Abstract method‬‬ ‫ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)‪public abstract int calc(int fuel‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Public MustOverride Function calc(ByVal fuel As Integer) As Integer‬‬‫871‬
  • 179
  • ‫اﻟﺒﺎب‬ ‫9‬ ‫اﻟﻮاﺟﻬﺎت ‪Interfaces‬‬‫081‬
  • 181
  • Interfaces ‫اﻟﻮاﺟﻬﺎت‬   ‫اﻟﺒﺎب اﻟﺘﺎﺳﻊ‬ Interface ‫1. ﺗﻌﺮﻳﻒ ال‬‫ ﻳﻤﻜﻦ ﻋﻤﻞ‬abstract  methods  and  members ‫ ﻳﺤﺘﻮي ﻋﻠﻰ‬abstract  class ‫ ﻫﻮ‬interface ‫ال‬‫ ، ﻛﻤﺎ ﻳﺘﻤﻴﺰ ﺑﺎﻣﻜﺎﻧﻴﺔ ﻋﻤﻞ‬inheritance ‫ ﺑﺪﻻ ﻣﻦ‬implementation ‫ﻧﺴﺨﺔ ﻣﻨﻪ ﺑﺎﺳﺘﺨﺪام ﺑﻤﻔﻬﻮم‬ ًmultiple ‫ ﻓﻲ اﻟﻤﺮة اﻟﻮاﺣﺪة وﻫﻮ اﻟﺒﺪﻳﻞ ﻋﻦ ﻣﻔﻬﻮم‬interface ‫ ﻻﻛﺜﺮ ﻣﻦ‬implement . inheritance :‫ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ‬interface ‫ﻳﻤﻜﻦ ﺗﻌﺮﻳﻒ‬ ًC# ‫ﻛﻮد‬public interface ICar{ int carMaxSpeed { get; set; } void AddItem(string Item);}VB.NET ‫ﻛﻮد‬Public Interface ICar Property carMaxSpeed() As Integer Sub AddItem(ByVal Item As String)End Interface :‫ ﻣﻦ آﺧﺮ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ‬interface ‫ﻻ ﺗﻨﺴﻰ ان ﺑﺎﻣﻜﺎﻧﻚ اﺷﺘﻘﺎق‬ ًC# ‫ﻛﻮد‬public interface ICar : IDisposable{ int carMaxSpeed { get; set; } void AddItem(string Item);}VB.NET ‫ﻛﻮد‬Public Interface ICar Inherits IDisposable Property carMaxSpeed() As Integer Sub AddItem(ByVal Item As String)End Interface182
  • ‫اﻟﻮاﺟﻬﺎت ‪Interfaces‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺘﺎﺳﻊ‬ ‫وﻟﻌﻤﻞ ‪ implements‬ﻻي ‪ interface‬ﻧﻘﻮم ﺑﻜﺘﺎﺑﺔ اﻟﻜﻮد اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪public class BMW : ICar‬‬ ‫{‬ ‫}‬ ‫‪public class BMW2 : ICar, ITruck‬‬ ‫{‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Public Class BMW‬‬ ‫‪Implements ICar‬‬ ‫‪End Class‬‬ ‫2‪Public Class BMW‬‬ ‫‪Implements ICar, ITruck‬‬ ‫‪End Class‬‬‫اﻵن ﻳﻤﻜﻨﻚ اﻋﺎدة ﻛﺘﺎﺑﺔ اﻟﺪوال اﻟﻤﻮﺟﻮدة . اﺿﺎﻓﺔ دوال ﺟﺪﻳﺪة ، وﻣﻦ ﺛﻢ اﺳﺘﺨﺪام اﻟﻔﺌﺔ ﻛﻤﺎ ﻗﻤﻨﺎ‬ ‫ﺑﺬﻟﻚ ﻗﺒﻼ.‬ ‫ً‬ ‫ﻫﺬه ﺑﻌﺾ اﻟﻨﻘﺎط اﻟﺘﻲ ﻻ ﻳﻤﻜﻨﻚ ﻋﻤﻠﻬﺎ ﻣﻊ اﻟﻮاﺟﻬﺎت‬ ‫- ﺑﺪاﻳﺔ ، ال ‪ Interface‬ﻻ ﻳﻤﻜﻦ ﻋﻤﻞ اي ‪ Object‬ﻣﻨﻪ ﻟﺬا ﻓﻤﺜﻞ ﻫﺬه اﻟﺠﻤﻠﺔ ﺧﺎﻃﺌﺔ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)(‪ICar x = new ICar‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)(‪Dim x As New ICar‬‬ ‫- ﻻ ﻳﻤﻜﻦ ﺗﻌﺮﻳﻒ ﻣﺘﻐﻴﺮ ﻋﺎدي ﻓﻲ ال ‪ ،Interface‬ﻟﺬا ﻣﺜﻞ ﻫﺬه اﻟﺠﻤﻠﺔ داﺧﻞ ال ‪ Interface‬ﺧﺎﻃﺌﺔ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;‪int number‬‬‫381‬
  • Interfaces ‫اﻟﻮاﺟﻬﺎت‬   ‫اﻟﺒﺎب اﻟﺘﺎﺳﻊ‬ VB.NET ‫ﻛﻮد‬ Dim number as integer :‫ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬get ‫ و‬set ‫اﻟﺒﺪﻳﻞ ، ﻫﻮ ﻋﻤﻞ ﺧﺎﺻﻴﺔ‬ C# ‫ﻛﻮد‬ int x { set; get; } VB.NET ‫ﻛﻮد‬ Private Property x() As Integer Get End Get Set(ByVal value As Integer) End Set End Property .interface ‫- ﺑﺎﻟﻄﺒﻊ ﻻ ﻳﻤﻜﻨﻚ ﻛﺘﺎﺑﺔ أي ﺳﻄﺮ ﻛﻮد داﺧﻞ ال‬ .interface ‫ ﻟﻞ‬constructor ‫- ﻛﻤﺎ ﻻ ﻳﻤﻜﻦ ﻋﻤﻞ‬ Names Clashes .2‫ ، ورﺑﻤﺎ‬interface ‫ ﻻﻛﺜﺮ ﻣﻦ‬implements ‫ ﻣﺎ ﺑﻌﻤﻞ‬struct ‫ او‬class ‫اﺣﻴﺎﻧﺎ ﻣﺎ ﻳﻘﻮم‬ ً :‫ﻳﺤﺪث ﻣﺸﺎﻛﻞ ﻓﻲ ﺗﺸﺎﺑﻪ اﻷﺳﻤﺎء ، ﻟﻨﻔﺘﺮض اﻟﻤﺜﺎل اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ public interface ICar { void move(); } public interface ITruck { void move(); } public class BMW : ITruck, ICar { }184
  • Interfaces ‫اﻟﻮاﺟﻬﺎت‬   ‫اﻟﺒﺎب اﻟﺘﺎﺳﻊ‬ VB.NET ‫ﻛﻮد‬ Public Interface ICar Sub move() End Interface Public Interface ITruck Sub move() End Interface Public Class BMW Implements ITruck Implements ICar End Class ‫ ﻓﻲ اﻟﻔﺌﺔ اﻟﺠﺪﻳﺪة‬move() ‫ ﻟﻠﺪاﻟﺔ‬implementation ‫رﺑﻤﺎ ﻟﻦ ﺗﺠﺪ ﻣﺸﻜﻠﺔ ﻓﻴﻤﺎ ﻟﻮ ﻗﻤﺖ ﺑﻌﻤﻞ‬ :BMW C# ‫ﻛﻮد‬ public class BMW : ITruck, ICar { void move() { // do something. } } VB.NET ‫ﻛﻮد‬ Public Class BMW Implements ITruck Implements ICar Private Sub move() do something. End Sub End Class move()‫ واﺧﺮى ﻟﻠﺪاﻟﺔ‬Car ‫ ﻣﻦ‬move() ‫ ﻟﻠﺪاﻟﺔ‬implementation ‫وﻟﻜﻦ ﻣﺎذا ﻟﻮ أردت ﻋﻤﻞ‬ :‫ ، ﻧﻘﻮم ﺑﺬﻟﻚ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬Truck ‫ﻣﻦ‬185
  • Interfaces ‫اﻟﻮاﺟﻬﺎت‬   ‫اﻟﺒﺎب اﻟﺘﺎﺳﻊ‬ C# ‫ﻛﻮد‬ public class BMW : ITruck, ICar { void ICar.move() { // do something. } void ITruck.move() { // do something. } } VB.NET ‫ﻛﻮد‬ 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‫، ﻳﻤﻜﻦ ﺗﺤﺪﻳﺪ اي واﺣﺪة ﻣﻦ اﻟﺪاﻟﺘﻴﻦ ﻳﺘﻢ اﺳﺘﺪﻋﺎءﻫﺎ ﺑﺎﻟﺸﻜﻞ‬BMW ‫ ﻣﻦ اﻟﻔﺌﺔ‬object ‫وﺑﻌﺪ ﻋﻤﻞ‬ :‫اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ BMW ahmedCar=new BMW(); ICar temp= (ICar)ahmedCar; temp.move(); VB.NET ‫ﻛﻮد‬ Dim ahmedCar As New BMW() Dim temp As ICar = DirectCast(ahmedCar, ICar) temp.move()186
  • ‫اﻟﻮاﺟﻬﺎت ‪Interfaces‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺘﺎﺳﻊ‬ ‫3. ‪IEnumerable Interface‬‬‫ﻧﻮاﺻﻞ اﻵن دروﺳﻨﺎ ﻣﻊ ال ‪ ، interfaces‬ﺳﻨﺘﻌﺮض اﻵن وﻟﺜﻼث دروس ﻗﺎدﻣﺔ ﻋﻦ ﻛﻴﻔﻴﺔ‬‫ﻋﻤﻞ ﻓﺌﺔ أو ‪ Class‬ﻳﻘﻮم ﺑﻌﻤﻞ ‪ implement‬ﻟﻞ ‪ interface‬ﻣﻌﻴﻦ، ﻓﻲ ﻫﺬا اﻟﺪرس ﺳﻨﺒﺪأ ب‬ ‫‪ interface‬اﻟﻤﺴﻤﻰ ‪ IEnumerable‬وﻣﺎ ﻫﻲ اﻟﻔﺎﺋﺪة اﻟﻤﺮﺟﻮة وراء ذﻟﻚ.‬ ‫ﻣﻼﺣﻈﺔ‬ ‫أرﺟﻮ ﻣﻨﻚ أن ﺗﺮﻛﺰ ﺟﻴﺪً ﻓﻲ ﻫﺬا اﻟﺪرس ، ﻓﻬﺬا واﺣﺪ ﻣﻦ اﻟﺪروس اﻟﺘﻲ ﺳﺘﻼﺣﻘﻨﺎ ﻛﺜﻴﺮًا أﺛﻨﺎء ﺗﻄﺒﻴﻖ ﻣﺒﺎدئ‬ ‫ا‬ ‫‪LINQ‬‬ ‫ﻟﻨﻔﺘﺮض ان ﻟﺪﻳﻨﺎ ﻓﺌﺔ ﻣﺼﻔﻮﻓﺔ أﺳﻤﺎء ﺗﺤﺘﻮي ﻋﻠﻰ ﻋﺪة ﺑﻴﺎﻧﺎت ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;} "‪string[] users = { "Ahmed", "Mohammed‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫}"‪Dim users As String() = {"Ahmed", "Mohammed‬‬‫واﻵن ﻟﻘﺮاءة ﻣﺤﺘﻮﻳﺎت اﻟﻤﺼﻔﻮﻓﺔ ﻛﻨﺎ ﻧﺴﺘﺨﺪم اﻟﻜﻮد اﻟﺘﺎﻟﻲ ﺑﺎﺳﺘﺨﺪام ‪ for each‬ﻛﻤﺎ ﺗﻌﻠﻤﻨﺎ‬ ‫ﺳﺎﺑﻘﺎ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪foreach (string us in users‬‬ ‫{‬ ‫;)‪Console.WriteLine(us‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪For Each us As String In users‬‬ ‫)‪Console.WriteLine(us‬‬ ‫‪Next‬‬‫ﻫﺬا ﻟﻮ ﻛﻨﺎ ﻧﻌﺘﻤﺪ ﻋﻠﻰ ‪ ،array‬ﺗﺠﺪ اﻧﻨﺎ ﻧﺴﺘﺨﺪم داﻟﺔ ﻟﻠﺪوران ﻋﻠﻰ ﻛﺎﻓﺔ اﻟﻌﻨﺎﺻﺮ ، ﺳﻨﻘﻮم ﺑﺘﻮﺳﻴﻊ‬ ‫اﻟﻤﺜﺎل ﻧﻮﻋﺎ ﻟﻴﻜﻮن ذﻟﻚ ﺑﺎﻻﻋﺘﻤﺎد ﻋﻠﻰ ﻓﺌﺔ ، ﺳﻨﻔﺘﺮض ﻓﺌﺔ اﻟﻤﻮﻇﻔﻴﻦ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫ً‬‫781‬
  • Interfaces ‫اﻟﻮاﺟﻬﺎت‬   ‫اﻟﺒﺎب اﻟﺘﺎﺳﻊ‬ C# ‫ﻛﻮد‬ public class employee { int emp_number; string emp_name; } VB.NET ‫ﻛﻮد‬ Public Class employee Private emp_number As Integer Private emp_name As String End Class‫وﻟﻴﻜﻦ ﻟﺪﻳﻨﺎ ﻓﺌﺔ أﺧﺮى ﻳﺤﺘﻮي ﻋﻠﻰ ﺑﻴﺎﻧﺎت اﻟﻤﺴﺘﺨﺪﻣﻴﻦ ، ﺣﻴﺚ ان اﻟﻤﺴﺘﺨﺪم ﻫﻮ ﻋﺒﺎرة ﻋﻦ‬ :‫ﻣﺠﻤﻮﻋﺔ ﻣﻦ اﻟﻤﻮﻇﻔﻴﻦ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ‬ ً 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.NET ‫ﻛﻮد‬ 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 :‫ اﻳﻀﺎ ﺑﺎﺳﺘﺨﺪام ﺟﻤﻠﺔ ﻛﺎﻟﺘﺎﻟﻲ‬for each ‫ﻳﻤﻜﻨﻨﺎ اﺳﺘﻌﺮاض اﻟﺴﻴﺎرات اﻳﻀﺎ ﺑﺎﺳﺘﺨﺪام‬ ً ً C# ‫ﻛﻮد‬ foreach (employee e in emp) { }188
  • Interfaces ‫اﻟﻮاﺟﻬﺎت‬   ‫اﻟﺒﺎب اﻟﺘﺎﺳﻊ‬ VB.NET ‫ﻛﻮد‬ For Each e As employee In emp Next.IEnumerable‫ ﺳﻴﺘﻢ ﻃﺒﺎﻋﺔ ﻋﻨﺼﺮ ﻣﻌﻴﻦ، ﻫﺬا ﻫﻮ اﻟﻤﺒﺪأ اﻟﺬي ﺳﻨﺴﻌﻰ إﻟﻴﻪ ﻣﻊ ال‬loop ‫ﻣﻊ ﻛﻞ‬ :IEnumerable ‫ اﻟﻤﺴﻤﻰ‬interface ‫اﻟﺸﻜﻞ اﻻﺳﺎﺳﻲ ﻟﻞ‬ C# ‫ﻛﻮد‬ public interface IEnumerable { IEnumerator GetEnumerator(); } VB.NET ‫ﻛﻮد‬ Public Interface IEnumerable Function GetEnumerator() As IEnumerator End Interface‫ ﺑﺎﻟﺸﻜﻞ‬IEnumerator ‫ ﻣﻦ ﻧﻮع‬interface ‫وﻛﻤﺎ ﺗﺮى ﻓﻲ اﻟﻤﺜﺎل اﻟﺴﺎﺑﻖ ، ﻳﻘﻮم ﺑﺘﻌﺮﻳﻒ واﺟﻬﺔ‬ ‫اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ public interface IEnumerator { bool MoveNext(); object Current { get; } void Reset(); } VB.NET ‫ﻛﻮد‬ Public Interface IEnumerator Function MoveNext() As Boolean ReadOnly Property Current() As Object Sub Reset() End Interfaceinterface ‫ ﻟﻬﺬه اﻟﻮاﺟﻬﺔ‬implements ‫ ﺗﻘﻮم ﺑﻌﻤﻞ‬users ‫ﻟﺬا ﻟﻮ ﻛﻨﺎ ﻧﺮﻏﺐ ﻓﻲ ان ﻧﺠﻌﻞ ﻓﺌﺔ‬ :‫ ، ﺳﻴﻜﻮن ذﻟﻚ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬GetEnumerator() ‫ ﻟﻠﺪاﻟﺔ‬implement ‫ﺳﻨﻀﻄﺮ ﻟﻌﻤﻞ‬189
  • Interfaces ‫اﻟﻮاﺟﻬﺎت‬   ‫اﻟﺒﺎب اﻟﺘﺎﺳﻊ‬ C# ‫ﻛﻮد‬ public class users : IEnumerable { employee[] emp = new employee[4]; users() { emp[0] = new employee(10, "Ahmed"); emp[1] = new employee(20, "Khaled"); emp[2] = new employee(30, "Ali"); emp[3] = new employee(40, "Sami"); } public IEnumerator GetEnumerator() { return emp.GetEnumerator(); } } VB.NET ‫ﻛﻮد‬ 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 :‫ﻳﻤﻜﻨﻨﺎ اﻟﻘﻴﺎم ﺑﺬﻟﻚ ﻳﺪوﻳﺎ اﻳﻀﺎ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ ً ً C# ‫ﻛﻮد‬ IEnumerator i = emp.GetEnumerator(); i.MoveNext(); employee myCar = (employee)i.Current; VB.NET ‫ﻛﻮد‬ Dim i As IEnumerator = emp.GetEnumerator() i.MoveNext() Dim myCar As employee = DirectCast(i.Current, employee)190
  • ‫اﻟﻮاﺟﻬﺎت ‪Interfaces‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺘﺎﺳﻊ‬ ‫ﻣﺎذا ﻧﺴﺘﻔﻴﺪ ﻣﻦ ﻫﺬه اﻟﻄﺮﻳﻘﺔ ؟‬‫ﻓﻲ اﻟﻮاﻗﻊ ﻓﺄي ﻣﺒﺮﻣﺞ ﻟﻘﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت ﻳﺴﺘﻄﻴﻊ ان ﻳﺴﺘﻨﺘﺞ اﻟﻌﻼﻗﺔ ﺑﺴﻬﻮﻟﺔ ، إن ﻣﺎ ﻧﺤﻦ‬‫ﺑﺼﺪده ﻫﻨﺎ ﻫﻮ ﻣﺜﺎل ﻋﻦ ﻓﺌﺔ ﺗﺤﺘﻮي ﻋﻠﻰ ﻣﺠﻤﻮﻋﺔ ﻣﻦ اﻟﺒﻴﺎﻧﺎت اﺷﺒﻪ ﺑﻘﺎﻋﺪة ﺑﻴﺎﻧﺎت ، واﺻﺒﺢ‬ ‫ﺑﺎﺳﺘﻄﺎﻋﻨﺎ اﻵن اﻟﻘﺮاءة ﻣﻨﻬﺎ واﻟﺘﻨﻘﻞ ﻓﻴﻬﺎ ﺑﺎﺳﺘﺨﺪام ‪. moveNext‬‬ ‫- اﺳﺘﺨﺪام ‪yield‬‬ ‫ﺑﺪﻻ ﻣﻦ اﻟﻜﻮد اﻟﺴﺎﺑﻖ ﻗﻢ ﺑﻜﺘﺎﺑﺔ اﻟﻜﻮد اﻟﺘﺎﻟﻲ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)(‪public IEnumerator GetEnumerator‬‬ ‫{‬ ‫;]0[‪yield return emp‬‬ ‫;]1[‪yield return emp‬‬ ‫;]2[‪yield return emp‬‬ ‫;‪yield break‬‬ ‫}‬‫ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ وﻣﻊ اول اﺳﺘﺪﻋﺎء ﻟﻠﺪاﻟﺔ ﺳﻴﺘﻢ اﻋﺎدة اﻟﻘﻴﻤﺔ اﻷوﻟﻰ ، ﺛﻢ اﻟﺜﺎﻧﻴﺔ ﻓﺎﻟﺜﺎﻟﺜﺔ وﻫﻜﺬا ﺣﺘﻰ‬ ‫ﻧﺼﻞ إﻟﻰ. ‪yield break‬‬‫ﻧﺴﺘﻌﺮف ﻋﻠﻰ واﺣﺪة ﻣﻦ أﻫﻢ اﻻﺳﺘﺨﺪاﻣﺎت اﻟﻔﻌﻠﻴﺔ ﻋﻨﺪﻣﺎ ﻧﺼﻞ إﻟﻰ ‪ ، LINQ‬وﺣﺘﻰ ذﻟﻚ اﻟﺤﻴﻦ‬ ‫أﺗﻤﻨﻰ أﻻ ﺗﻐﻔﻞ ﻋﻴﻨﻚ ﻋﻦ ﻫﺬه اﻟﻮاﺟﻬﺔ .‬ ‫4. ‪ICloneable Interface‬‬ ‫ﻋﻤﻠﻴﺔ ال ‪ clone‬ﻳﻘﺼﺪ ﺑﻬﺎ ﻋﻤﻠﻴﺔ اﻟﻨﺴﺦ ﻟﻠﻜﺎﺋﻦ ، ﺑﻤﻌﻨﻰ اﻧﻨﺎ ﻋﻨﺪﻣﺎ ﻧﻜﺘﺐ اﻟﻜﻮد اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;5 = ‪int x‬‬ ‫;‪int y = x‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫5 = ‪Dim x As Integer‬‬ ‫‪Dim y As Integer = x‬‬‫191‬
  • ‫اﻟﻮاﺟﻬﺎت ‪Interfaces‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺘﺎﺳﻊ‬ ‫ﻓﺈﻧﻨﺎ ﻓﻌﻠﻴﺎ ﻧﻘﻮم ﺑﻨﻘﻞ ﻗﻴﻤﺔ ‪ x‬إﻟﻰ ‪ ، y‬وﻟﻜﻦ ﻓﻲ ﺣﺎﻟﺔ ﺗﻌﺎﻣﻠﻨﺎ ﻣﻊ اﻟﻔﺌﺎت ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)"‪Car x = new Car("BMW‬‬ ‫;‪Car y = x‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)"‪Dim x As New Car("BMW‬‬ ‫‪Dim y As Car = x‬‬‫ﻓﻲ اﻟﻮاﻗﻊ ان ﻗﻴﻤﺔ ‪ x‬ﻻ ﺗﻨﺘﻘﻞ إﻟﻰ ‪ ، y‬ﺑﻞ إن ‪ y‬ﻳﺼﺒﺢ ﻳﺸﻴﺮ إﻟﻰ اﻟﻤﻜﺎن اﻟﺬي ﻓﻴﻪ ﻗﻴﻤﺔ ‪ ، x‬وﻟﺬا‬ ‫ﻓﺈن اي ﺗﻌﺪﻳﻞ ﻓﻲ ﻗﻴﻤﺔ ‪ x‬ﺳﻴﻌﺪل ﻗﻴﻤﺔ ‪ y‬واﻟﻌﻜﺲ ﺑﺎﻟﻌﻜﺲ.‬ ‫ﻣﻦ ﻫﻨﺎ ﻛﺎﻧﺖ ﻋﻤﻠﻴﺔ ال ‪ clone‬ﻣﻦ اﺟﻞ ﻋﻤﻞ ﻧﺴﺨﺔ ﺟﺪﻳﺪة ﻓﻲ اﻟﻘﻴﻤﺔ ووﺿﻌﻬﺎ ﻓﻲ اﻟﻤﺘﻐﻴﺮ اﻵﺧﺮ.‬‫اﻟﻮاﺟﻬﺔ ‪ ICloneable‬اﻟﺘﻲ ﺗﺤﺘﻮي ﻋﻠﻰ اﻟﺪاﻟﺔ ‪ ،clone‬ﻳﻤﻜﻦ اﺳﺘﺨﺪاﻣﻬﺎ ﻟﻬﺬا اﻟﻐﺮض، ﺣﻴﺚ‬ ‫ﻳﻤﻜﻨﻨﺎ ﻛﺘﺎﺑﺔ ﻛﻮد ﻛﺎﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)(‪public object Clone‬‬ ‫{‬ ‫;)‪return new Car(this.carName‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Public Function Clone() As Object‬‬ ‫)‪Return New Car(Me.carName‬‬ ‫‪End Function‬‬ ‫اﻵن اﺻﺒﺢ ﺑﺎﻣﻜﺎﻧﻚ ﻋﻤﻞ ﻧﺴﺨﺔ ﺟﺪﻳﺪة ﺑﺎﺳﺘﺨﺪام ‪ Clone‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)"‪Car x = new Car("BMW‬‬ ‫;)(‪Car y = (Car)x.Clone‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)"‪Dim x As New Car("BMW‬‬ ‫)‪Dim y As car = DirectCast(x.Clone(), Car‬‬‫291‬
  • ‫اﻟﻮاﺟﻬﺎت ‪Interfaces‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺘﺎﺳﻊ‬ ‫5. ‪IComparable Interface‬‬‫ﻛﻤﺎ ﻫﻮ واﺿﺢ ﻣﻦ اﻻﺳﻢ ، ﻳﺴﺘﺨﺪم ﻫﺬا ال ‪ interface‬ﻟﻠﻤﻘﺎرﻧﺔ ، وﻟﺬا ﻣﻦ اﻟﻄﺒﻴﻌﻲ ان ﻳﻜﻮن ﺷﻜﻞ‬ ‫ﻫﺬا ال ‪ interface‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪public interface IComparable‬‬ ‫{‬ ‫;)‪int CompareTo(object o‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Public Interface IComparable‬‬ ‫‪Function CompareTo(ByVal o As Object) As Integer‬‬ ‫‪End Interface‬‬‫ﻳﻤﻜﻨﻚ ﻣﻼﺣﻈﺔ ان اﻟﺪاﻟﺔ ﺗﻌﻴﺪ ﻗﻴﻤﺔ رﻗﻤﻴﺔ، ﻓﻌﻠﻴﺎ ﻫﻲ ﺗﻌﻴﺪ ﻓﻲ اﻟﻤﻌﺘﺎد اﻟﻘﻴﻢ 0 ﻓﻲ ﺣﺎﻟﺔ اﻟﺘﺴﺎوي ،‬ ‫ً‬ ‫اﻟﻘﻴﻤﺔ 1 ﻓﻲ ﺣﺎﻟﺔ ﻛﻮن اﻟﻄﺮف اﻷول اﻛﺒﺮ ، و -1 ﻓﻲ ﺣﺎﻟﺔ ﻛﻮن اﻟﻄﺮف اﻷول أﺻﻐﺮ.‬‫ﻃﺒﻌﺎ ﻻ داﻋﻲ ﻣﻦ اﻋﺎدة ﺗﺬﻛﻴﺮك ﺑﺄن اﻟﻜﺎﺋﻨﻴﻦ ﻳﻜﻮﻧﺎن ﻣﺘﺴﺎوﻳﺎن ﻟﻴﺲ ﻻﻋﺘﺒﺎرات ﺗﺴﺎوي ﻗﻴﻤﻬﻢ‬ ‫ً‬‫اﻟﺪاﺧﻠﻴﺔ ﺑﻞ اﻟﻨﻘﻄﺔ ﻓﻲ اﺷﺎرﺗﻬﻢ ﻟﻨﻔﺲ اﻟﻤﻜﺎن ﻓﻲ اﻟﺬاﻛﺮة ، وﻫﻮ ﻣﺎ ﻟﻦ ﻧﺤﺘﺎﺟﻪ ، ﺣﻴﺚ اﻧﻨﺎ ﻧﺤﺘﺎج‬ ‫ﻟﻤﻘﺎرﻧﺔ ﻓﻌﻠﻴﺔ . وﻫﺬا ﻣﺎ ﻗﻤﻨﺎ ﺑﻪ ﻣﻦ ﺧﻼل اﻟﺪاﻟﺔ ‪.Equals‬‬‫اﻣﺎ اﻟﻨﻘﻄﺔ اﻟﺘﻲ ﻟﺪﻳﻨﺎ ﻫﻨﺎ ﻓﻠﺴﻨﺎ ﺑﺤﺎﺟﺔ ﻟﻤﻌﺮﻓﺔ ﻫﻞ ﻳﺴﺎوي ﻫﺬا اﻟﻜﺎﺋﻦ ذاك ام ﻻ ، ﺑﻞ ﻧﺤﻦ ﻓﻲ ﺣﺎﺟﺔ‬ ‫إﻟﻰ ﻣﻌﺮﻓﺔ اﻳﻬﻤﺎ اﻛﺒﺮ او اﺻﻐﺮ ، وﻟﻨﻔﺘﺮض ﺗﺎرﻳﺦ ﺻﻨﻊ اﻟﺴﻴﺎرة ﺿﻤﻦ اﻟﻔﺌﺔ اﻟﺨﺎﺻﺔ ﺑﻬﺎ.‬‫ﺑﺒﺴﺎﻃﺔ ﻛﻤﺎ ﻗﻤﻨﺎ ﻓﻲ اﻟﺪرس اﻟﺴﺎﺑﻖ ، ﺳﻨﺠﻌﻞ اﻟﻔﺌﺔ اﻟﺨﺎﺻﺔ ﺑﻨﺎ ﺗﻄﺒﻖ اﻟﻔﺌﺔ ‪ ،IComparable‬ﺛﻢ‬ ‫ﻧﻜﺘﺐ ﺑﻌﺾ اﻻﻛﻮاد ﻓﻲ اﻟﺪاﻟﺔ ‪ ،CompareTo‬ﻟﻨﻔﺘﺮض اﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪int IComparable.CompareTo(object obj‬‬ ‫{‬ ‫;‪Car temp = (Car)obj‬‬ ‫)‪if (this.year > temp.year‬‬ ‫;1 ‪return‬‬ ‫)‪if (this.year < temp.year‬‬ ‫;1- ‪return‬‬ ‫‪else‬‬ ‫;0 ‪return‬‬ ‫}‬‫391‬
  • ‫اﻟﻮاﺟﻬﺎت ‪Interfaces‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺘﺎﺳﻊ‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪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‬‬ ‫1 ‪Return‬‬ ‫‪End If‬‬ ‫‪If Me.year < temp.year Then‬‬ ‫1- ‪Return‬‬ ‫‪Else‬‬ ‫0 ‪Return‬‬ ‫‪End If‬‬ ‫‪End Function‬‬‫ﻃﺒﻌﺎ ﻻ داﻋﻲ ﻟﺘﺬﻛﻴﺮك ﺑﺎﻧﻚ ﺗﺴﺘﻄﻴﻊ اﻋﺎدة -001 و 0 و 49 ﺑﺪﻻ ﻣﻦ -1 و 0 و 1 ، ﻟﻜﻦ ﻫﺬا‬ ‫ً‬ ‫ً‬ ‫ﻟﺘﺴﻬﻴﻞ اﻟﻤﻔﻬﻮم ، اﻟﺪاﻟﺔ ﺗﻌﻤﻞ ﺑﺪﻻﻟﺔ رﻗﻢ ﺳﺎﻟﺐ ﻳﻌﻨﻲ اﺻﻐﺮ ، ﺻﻔﺮ ﻳﻌﻨﻲ اﻟﺘﺴﺎوي ورﻗﻢ ﻣﻮﺟﺐ‬ ‫ﻳﻌﻨﻲ اﻛﺒﺮ ﻓﻘﻂ دون ان ﻳﻌﻨﻴﻬﺎ ﻗﻴﻤﺔ ﻫﺬا اﻟﺮﻗﻢ اﻟﻔﻌﻠﻴﺔ.‬ ‫اﻟﺪاﻟﺔ ‪Sort‬‬‫ﻟﻨﻔﺘﺮض ان ﻟﺪﻳﻨﺎ ﻣﺼﻔﻮﻓﺔ ‪ array‬ﻣﻦ اﻻرﻗﺎم ﺑﺎﺳﻢ ‪ ،myNumbers‬ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﻟﻮ ﻗﻤﻨﺎ‬ ‫ﺑﻜﺘﺎﺑﺔ اﻷﻣﺮ اﻟﺘﺎﻟﻲ ﻟﻜﺎن اﻟﻜﻮد ﻣﻔﻬﻮﻣﺎ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)‪Array.Sort(myNumbers‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)‪Array.Sort(myNumbers‬‬‫وﻟﻜﻦ ﻟﻮ ﻛﺎن ﻟﺪﻳﻨﺎ ﻣﺼﻔﻮﻓﺔ ﻣﻦ اﻟﺴﻴﺎرات ، وﻛﺘﺒﻨﺎ ﻫﺬا اﻟﻜﻮد ﻟﺘﺮﺗﻴﺒﻬﺎ ﻓﺈن ﻫﺬا ﺑﺎﻟﺘﺄﻛﻴﺪ ﺳﻴﺤﺪث‬ ‫ﺧﻄﺄ.‬‫ﻟﻜﻦ ﻓﻲ ﺣﺎﻟﺔ ﻛﻮن اﻟﻔﺌﺔ ‪ car‬ﺗﻄﺒﻖ ال ‪ ،IComparable interface‬ﻓﻔﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﺳﻴﻤﻜﻨﻚ‬‫اﺳﺘﺨﺪام ﻫﺬا اﻟﺪاﻟﺔ ﺑﺒﺴﺎﻃﺔ ﻹﻧﻬﺎ ﺳﻮف ﺗﻘﻮم ﺑﺎﻟﻤﻘﺎرﻧﺔ اﻋﺘﻤﺎدًا ﻋﻠﻰ داﻟﺔ ‪ CompareTo‬اﻟﺘﻲ ﻗﻤﺖ‬‫اﻧﺖ ﺑﺒﺮﻣﺠﺘﻬﺎ ، رﺑﻤﺎ ﻳﻜﻮن ﻫﺬا ﺳﺒﺒﺎ ﻛﺎﻓﻴﺎ ﻟﺘﻘﻮم ﺑﺘﻄﺒﻴﻖ ﻫﺬا ال ‪ interface‬وﻛﺘﺎﺑﺔ ﻛﻮد اﻟﺪاﻟﺔ‬ ‫ً‬ ‫ً‬‫ﺑﺪﻻ ﻣﻦ ﻛﺘﺎﺑﺔ داﻟﺔ ﺑﺎﺳﻢ ‪ check‬ﻣﺜﻼ او اي اﺳﻢ آﺧﺮ ﻟﻠﻘﻴﺎم ﺑﻨﻔﺲ اﻟﻤﻬﻤﺔ . ﻫﺬا ﻃﺒﻌﺎ ﺑﺎﻻﺿﺎﻓﺔ‬ ‫ً‬ ‫ً‬ ‫ً‬ ‫ﻟﺘﺴﻬﻴﻞ اﺳﺘﺨﺪام اﻟﻔﺌﺔ اﻟﺨﺎﺻﺔ ﺑﻜﻞ ﻻﺣﻘﺎ ووﺿﻮﺣﻬﺎ ﻷي ﻣﺒﺮﻣﺞ آﺧﺮ.‬ ‫ً‬‫491‬
  • 195
  • ‫اﻟﺒﺎب‬ ‫01‬ ‫اﻷﺧﻄﺎء واﻗﺘﻨﺎﺻﻬﺎ‬‫691‬
  • 197
  • ‫اﻷﺧﻄﺎء و ﻣﻌﺎﻟﺠﺘﻬﺎ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﻌﺎﺷﺮ‬‫ﺳﻨﺘﻌﺮف ﻓﻲ درﺳﻨﺎ ﻫﺬا ﻋﻠﻰ اﻷﺧﻄﺎء وﻛﻴﻔﻴﺔ اﻗﺘﻨﺎﺻﻬﺎ وﺗﻔﺎدﻳﻬﺎ ، ﻣﻌﺎﻧﻲ رﺳﺎﺋﻞ اﻟﺨﻄﺄ واﺷﻬﺮ‬ ‫اﻻﺧﻄﺎء وﺧﻼﻓﻪ ، وﻟﻜﻦ ﻗﺒﻞ اﻟﺒﺪاﻳﺔ ﻧﺤﺘﺎج ﻹن ﻧﻮﺿﺢ أﻗﺴﺎم اﻷﺧﻄﺎء اﻟﺘﻲ ﺗﺤﺼﻞ ﻓﻲ اي ﺑﺮﻧﺎﻣﺞ:‬ ‫1. اﻷﺧﻄﺎء اﻟﻨﺤﻮﻳﺔ ‪Syntax Errors‬‬‫ﻫﺬا اﻟﻨﻮع ﻣﻦ اﻻﺧﻄﺎء ﻫﻮ اﻻﺳﻬﻞ ، وﻓﻲ ‪ Advanced Programming Environments‬ﻣﺜﻞ‬‫ال‪ ،Visual Studio , NetBeans ... etc‬ﻳﺘﻢ اﻛﺘﺸﺎف ﻫﺬه اﻷﺧﻄﺎء ﻓﻮرﻳﺎ ، ﻣﺜﺎل ﻫﺬا اﻟﺨﻄﺄ ﻛﺘﺎﺑﺔ‬ ‫ً‬ ‫اﻟﺠﻤﻠﺔ اﻟﺘﺎﻟﻴﺔ:‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪if x.Nome = somevalue‬‬‫ﺑﺎﻟﻄﺒﻊ ﺳﺘﺠﺪ رﺳﺎﻟﺔ ﺧﻄﺄ ﻗﺒﻞ اﻟﺘﻨﻔﻴﺬ ﺗﺨﺒﺮك ﺑﺄن اﻟﺨﺎﺻﻴﺔ ‪ Nome‬ﻏﻴﺮ ﻣﻮﺟﻮدة، ﻣﺜﻞ ﻫﺬه اﻷﺧﻄﺎء‬‫ﻫﻲ اﻻﺳﻬﻞ وﻳﺘﻢ اﻛﺘﺸﺎﻓﻬﺎ ﻣﻦ ﺧﻼل ﺑﻴﺌﺔ ﻟﻐﺔ اﻟﺒﺮﻣﺠﺔ اﻟﺘﻲ ﺗﻌﻤﻞ ﻋﻠﻴﻬﺎ، وﻓﻲ  ‪Visual Studio .net‬‬ ‫8002 اﺻﺒﺤﺖ رﺳﺎﺋﻞ اﻟﺨﻄﺎ واﺿﺤﺔ ﻟﻠﻐﺎﻳﺔ وﻳﻤﻜﻦ ﺗﻔﺴﻴﺮﻫﺎ ﺑﺴﻬﻮﻟﺔ وﺣﻠﻬﺎ ﺑﻬﺬه اﻟﻄﺮﻳﻘﺔ .‬ ‫2. اﻷﺧﻄﺎء اﻟﻤﻨﻄﻘﻴﺔ ‪Logical Errors‬‬‫ﻫﺬا اﻟﻨﻮع ﻣﻦ اﻷﺧﻄﺎء ﻫﻮ اﻷﺻﻌﺐ، ﻓﻌﻠﻰ ﺻﻌﻴﺪ ﻛﺘﺎﺑﺔ اﻟﻜﻮد رﺑﻤﺎ ﻻ ﻳﻮﺟﺪ ﺧﻄﺄ ﻧﺤﻮي وﻟﻜﻨﻪ ﺧﻄﺎ‬ ‫ﻣﻨﻄﻘﻲ ﻳﻈﻬﺮ ﻋﻨﺪ اﻟﺘﻨﻔﻴﺬ، اﺑﺴﻂ ﻣﺜﺎل ﻋﻠﻰ ﻫﺬا اﻟﺨﻄﺄ ﻫﻮ ﻛﺘﺎﺑﺔ ﻛﻮد ﻛﺎﻟﺘﺎﻟﻲ:‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫000001 =‪Dim x as Byte‬‬‫ﻃﺒﻌﺎ ﺗﻌﺮف ان ﺣﺪود اﻟﻨﻮع ‪ Byte‬اﺻﻐﺮ ﻣﻦ ﻫﺬا اﻟﺤﺪ، وﻟﻜﻦ ﻓﻲ اﻻﺻﺪارات اﻟﻘﺪﻳﻤﺔ ﻟﻢ ﻳﻜﻦ ﻫﺬا‬ ‫ً‬ ‫ﻟﻴﻈﻬﺮ ﺧﻄﺄ ﺣﻴﺚ ان اﻟﺠﻤﻠﺔ ﻣﻜﺘﻮﺑﺔ ﻧﺤﻮﻳﺎ ﻛﻤﺎ ﺗﺮى .‬ ‫ً‬ ‫اﻣﺜﻠﺔ ﻋﻠﻰ ﻫﺬا اﻟﺨﻄﺄ اﺳﻨﺎد ﻗﻴﻤﺔ ل ‪ object‬ﻗﺒﻞ ﻋﻤﻞ ‪ new‬ﻟﻪ .. اﻟﺦ.‬‫ﻟﻜﻦ ﻣﻊ اﺻﺪارات ﻓﻴﺠﻮال ﺳﺘﻮدﻳﻮ اﻟﺠﺪﻳﺪة ، اﺻﺒﺤﺖ ﻣﺜﻞ ﻫﺬه اﻷﺧﻄﺎء ﺗﻈﻬﺮ ﻣﺒﺎﺷﺮة ، ﺑﻞ ان ﻫﻨﺎك‬‫اﻧﻮاﻋﺎ اﺻﻌﺐ ﻣﻦ ال ‪ Logic  Errors‬اﺻﺒﺢ اﻟﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ ﻗﺎدر ﻋﻠﻰ اﻛﺘﺸﺎﻓﻬﺎ ﻋﻠﻰ ﺷﻜﻞ‬ ‫ً‬ ‫‪.warnings‬‬‫891‬
  • ‫اﻷﺧﻄﺎء و ﻣﻌﺎﻟﺠﺘﻬﺎ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﻌﺎﺷﺮ‬ ‫ﻟﻦ ﻧﺬﻫﺐ ﺑﻌﻴﺪًا ، ﺳﻨﺒﺪأ ﺑﺘﻘﺴﻴﻢ ال ‪ Logical Errors‬وﻫﻲ اﻷﺧﻄﺎء اﻷﻫﻢ إﻟﻰ ﺛﻼﺛﺔ أﻧﻮاع اﺳﺎﺳﻴﺔ:‬ ‫- ‪User Error‬‬‫أﺧﻄﺎء ﺗﻨﺘﺞ ﻣﻦ اﺳﺘﺨﺪام اﻟﺒﺮﻧﺎﻣﺞ ، ﻟﻮ اﻓﺘﺮﺿﻨﺎ اﻟﻤﺜﺎل اﻟﺴﺎﺑﻖ ل ‪ Byte‬ﻧﻘﻮم ﻓﻴﻪ ﺑﺘﺨﺰﻳﻦ ﻋﻤﺮ‬‫اﻟﻤﺴﺘﺨﺪم ، ﻟﻜﻦ اﻟﻤﺴﺘﺨﺪم ﻗﺎم ﺑﺎدﺧﺎل رﻗﻢ 01 اﻻف ، ﻫﺬا اﻟﺨﻄﺄ ﻣﻦ اﻟﻤﺴﺘﺨﺪم ﺳﻴﺘﺴﺒﺐ ﻓﻲ‬‫اﻟﻤﺸﺎﻛﻞ ﻟﻚ ﻓﻴﻤﺎ ﻟﻮ ﻟﻢ ﺗﻜﻦ ﻗﺪ اﺿﻔﺖ ﺷﺮط اﻟﺘﺄﻛﺪ ﻣﻦ ﻋﺪم ﺗﺠﺎوز اﻟﻌﻤﺮ ﻟﺤﺪ ﻣﻌﻴﻦ، اﻳﻀﺎ‬‫ً‬ ‫ادﺧﺎل ﺑﻴﺎﻧﺎت ﻧﺼﻴﺔ ﻓﻲ ﺧﺎﻧﺔ اﻟﻌﻤﺮ وﺧﻼﻓﻪ ﺗﻨﺪرج ﺗﺤﺖ اﺳﻢ أﺧﻄﺎء اﻟﻤﺴﺘﺨﺪم.‬ ‫- ‪Exceptions‬‬‫اﻟﻨﻮع اﻷﺷﻬﺮ ﻣﻦ اﻷﺧﻄﺎء ، ﻣﺤﺎوﻟﺔ ﻓﺘﺢ ﻣﻠﻒ او ﻗﺎﻋﺪة ﺑﻴﺎﻧﺎت ﻏﻴﺮ ﻣﻮﺟﻮدة ﻣﺜﻼ ﺣﻴﺚ ﻟﻢ ﻳﺘﻢ‬ ‫ً‬‫ﺗﺤﻤﻴﻠﻬﺎ ﺑﺼﻮرة ﺻﺤﻴﺤﺔ ، ﻣﺤﺎوﻟﺔ ﻗﺮاءة ﺑﻴﺎﻧﺎت ﻣﻦ ﻗﺎﻋﺪة اﻟﺒﻴﺎﻧﺎت ﻓﻲ ﺣﻴﻦ اﻧﻬﺎ ﺗﺴﺎوي ‪null‬‬‫ﺑﺪون اﺳﺘﺨﺪام  ‪ ، nullable type‬ﻣﺤﺎوﻟﺔ اﻟﻜﺘﺎﺑﺔ إﻟﻰ ﻣﻠﻒ ﻧﺼﻲ ‪ ،ReadOnly‬وﺧﻼﻓﻪ ﻣﻦ اﻷﺧﻄﺎء‬ ‫اﻟﻤﺸﻬﻮرة.‬ ‫-  ‪Bugs‬‬‫اﻛﺜﺮ اﻷﺧﻄﺎء ﺷﻬﺮة ، ﻻ ﻳﻤﻜﻦ ﺣﺼﺮﻫﺎ وﻻ ﻋﺪﻫﺎ ، وﺗﻮﺟﺪ ﻓﻲ ﺟﻤﻴﻊ اﻟﺒﺮاﻣﺞ ﺑﻤﺎ ﻓﻴﻬﻢ ﻧﺴﺨﺔ‬‫اﻟﻮﻳﻨﺪوز اﻟﺘﻲ ﺗﺴﺘﺨﺪﻣﻬﺎ ، ﻓﻲ اﻟﻌﺎدة ﻟﻦ ﻳﺨﻠﻮ ﺑﺮﻧﺎﻣﺞ ﻣﻨﻬﺎ وﻟﻜﻨﻨﺎ ﻧﺤﺎول ﺗﻔﺎدﻳﻬﺎ ﻗﺪر اﻟﻤﺴﺘﻄﺎع، ﻗﺪ‬‫ﺗﺤﺪث ﺑﺴﺒﺐ ﻧﺴﻴﺎن ﺣﺬف ﻣﺘﻐﻴﺮ او ﻗﺮاءة ﻣﺘﻐﻴﺮ ﻣﻦ ﻗﻴﻤﺔ ﻣﻮﺟﻮدة اﺻﻼ ﻓﻲ اﻟﺬاﻛﺮة وﻧﺤﻦ ﻧﻈﻦ‬ ‫ً‬‫اﻧﻬﺎ ﻗﻴﻤﺔ ﻓﺎرﻏﺔ ... اﻟﺦ ، ﻫﺬه اﻷﺧﻄﺎء ﻗﺪ ﻻ ﺗﻈﻬﺮ ل 99% ﻣﻦ اﻟﻤﺴﺘﺨﺪﻣﻴﻦ وﻟﻜﻨﺎ ﺗﻈﻬﺮ ﻟﻤﺴﺘﺨﺪم‬‫واﺣﺪ ﻓﻘﻂ ، ﻟﺬا ﻓﻲ اﻟﻌﺎدة ﺗﻜﻮن ﻫﻨﺎك ﻋﺪة ﻧﺴﺦ ﺗﺠﺮﻳﺒﻴﺔ ﻣﻦ اي ﺑﺮﻧﺎﻣﺞ ﻟﻤﺤﺎوﻟﺔ ﻣﻌﺮﻓﺔ اﻣﺎﻛﻦ‬ ‫اﻣﺜﺎل ﻫﺬه اﻷﺧﻄﺎء وﺗﻌﺪﻳﻠﻬﺎ ﻗﺒﻞ ﻃﺮح اﻟﻨﺴﺨﺔ اﻟﺮﺳﻤﻴﺔ.‬‫ﻓﻲ درﺳﻨﺎ ﻫﺬا ﺳﻨﺮﻛﺰ ﻋﻠﻰ اﻟﻨﻮع اﻟﺜﺎﻧﻲ ﻣﻦ اﻷﺧﻄﺎء وﻫﻮ اﻷﻫﻢ ، اﻟﻨﻮع اﻷول اﻳﻀﺎ ﺳﻨﺤﺎول وﺿﻊ‬ ‫ً‬‫اﺳﺘﻨﺜﻨﺎءات ﻣﻦ اﺟﻞ اﻟﺘﺄﻛﺪ ﻣﻦ اﺧﺘﻴﺎرات اﻟﻤﺴﺘﺨﺪم وﻟﻜﻦ ﺟﻤﻞ اﻟﺘﺤﻘﻖ ﻫﻲ اﻷﻫﻢ ﻓﻲ اﻟﺤﺎﻟﺔ اﻷوﻟﻰ،‬ ‫اﻣﺎ اﻟﺤﺎﻟﺔ اﻟﺜﺎﻟﺜﺔ ﻓﺎﻟﺘﺠﺮﺑﺔ اﻟﻤﺴﺘﻤﺮة واﻟﻤﺘﺎﺑﻌﺔ ﻫﻲ اﻟﻮﺳﻴﻠﺔ اﻷﻣﺜﻞ ﻟﺘﻘﻠﻴﻠﻬﺎ.‬‫991‬
  • ‫اﻷﺧﻄﺎء و ﻣﻌﺎﻟﺠﺘﻬﺎ‬   ‫اﻟﺒﺎب اﻟﻌﺎﺷﺮ‬ System.Exception ‫3. اﻟﻔﺌﺔ‬ ‫. ﺑﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻷﺧﻄﺎء اﻟﺘﻲ ﺗﺤﺪث ﻓﻲ اﻟﻨﻈﺎم ، ﻓﻲ اﻟﻮاﻗﻊ ﻓﺈن أي‬net ‫ﻫﻲ اﻟﻔﺌﺔ اﻟﻤﺨﺘﺼﺔ ﻓﻲ ﻋﺎﻟﻢ‬ ‫، واﻟﺬي ﺑﺪوره ﻳﺨﻮل‬CLR ‫ﺧﻄﺄ ﻳﺮﺳﻞ ﻟﻠﻨﻈﺎم ﺛﻢ ﻳﻘﻮم اﻟﻨﻈﺎم ﺑﺎرﺳﺎﻟﻪ إﻟﻰ ال‬ :‫ ﻟﻠﺘﻌﺎﻣﻞ ﻣﻊ ﻫﺬا اﻟﺨﻄﺎ ، ﻣﺤﺘﻮﻳﺎت ﻫﺬه اﻟﻔﺌﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬System.ExceptionC# ‫ﻛﻮد‬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; }}200
  • ‫اﻷﺧﻄﺎء و ﻣﻌﺎﻟﺠﺘﻬﺎ‬   ‫اﻟﺒﺎب اﻟﻌﺎﺷﺮ‬ VB.NET ‫ﻛﻮد‬ 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 End Get Set(ByVal value As String) 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(ByVal value As String) 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 : ‫ﺳﻨﺤﺎول اﻟﺘﻌﺮف ﻋﻠﻰ اﻟﺨﺼﺎﺋﺺ واﻟﻄﺮق اﻻﺳﺎﺳﻴﺔ ﻟﻬﺬه اﻟﻔﺌﺔ‬201
  • ‫اﻷﺧﻄﺎء و ﻣﻌﺎﻟﺠﺘﻬﺎ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﻌﺎﺷﺮ‬ ‫اﻟﻤﻌﻨﻰ‬ ‫اﻟﺨﺎﺻﻴﺔ‬ ‫رﺳﺎﻟﺔ اﻟﺨﻄﺄ اﻟﺤﺎﺻﻠﺔ‬ ‫‪Message‬‬ ‫ﻣﻠﻒ اﻻﺳﻤﺒﻠﻲ اﻟﺬي ﻗﺎم ﺑﻌﻤﻞ ‪ throw‬ﻟﻬﺬا اﻟﺨﻄﺄ‬ ‫‪Source‬‬ ‫ﺣﺘﻮي ﻫﺬه اﻟﺨﺎﺻﻴﺔ ﻋﻠﻰ راﺑﻂ ﻳﺸﺮح اﻟﻤﺸﻜﻠﺔ ﺑﺒﻌﺾ اﻟﺘﻔﺼﻴﻞ ، ﺗﺴﺘﻄﻴﻊ‬ ‫‪HelpLink‬‬ ‫اﻻﺳﺘﻔﺎدة ﻣﻨﻪ ﻛﻤﺒﺮﻣﺞ ورﺑﻤﺎ ﻳﺴﺘﻔﻴﺪ ﻣﻨﻪ اﻟﻤﺴﺘﺨﺪم اﻟﻤﺘﺨﺼﺺ ﻓﻲ ال ‪IT‬‬ ‫ﻟﻨﻈﺎﻣﻚ‬ ‫اﻟﺠﺪول 01. 1. ﺑﻌﺾ ﺧﺼﺎﺋﺺ اﻟﻔﺌﺔ ‪Exception‬‬ ‫4. رﻣﻲ اﻻﺳﺘﺜﻨﺎءات ‪  Throwing Exceptions‬‬‫ﺧﻼل ﺗﻨﻔﻴﺬك ﻟﻠﺒﺮﻧﺎﻣﺞ ﻳﻤﻜﻦ ان ﻳﻘﻮم اﻟﺒﺮﻧﺎﻣﺞ ﺑﻌﻤﻞ ‪ throw‬ﻟﺨﻄﺄ ﻣﺎ ﻣﺜﻞ ﻋﺪم وﺟﻮد‬‫ﻣﻠﻒ ﻣﻌﻴﻦ. ﺳﻨﺘﻌﻠﻢ ﻛﻴﻔﻴﺔ ﻗﺮاءة ﻫﺬا اﻟﺨﻄﺄ واﻟﺘﻌﺎﻣﻞ ﻣﻌﻪ ، ﻟﻜﻦ ﺗﻈﻞ ﻫﻨﺎك ﺣﺎﻟﺔ أﺧﺮى ﺗﺮﻏﺐ اﻧﺖ‬‫ﻓﻴﻬﺎ ﺑﻌﻤﻞ ‪ throw‬ﻟﻠﺨﻄﺄ ، ﻟﻨﻔﺘﺮض اﻧﻚ ﺗﻘﻮم ﺑﻌﻤﻞ ‪ check‬ﺗﺘﺄﻛﺪ ﻣﻦ ﻋﺪم وﺟﻮد اﻟﻤﻠﻒ وﻣﻦ‬ ‫ﺛﻢ ﺗﻘﻮم ﺑﻌﺮض رﺳﺎﻟﺔ ﺧﻄﺄ ﻓﻲ ﺣﺎﻟﺔ ﻋﺪم وﺟﻮد اﻟﻤﻠﻒ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫))"‪if (!System.IO.File.Exists("c:ahmed.txt‬‬ ‫{‬ ‫;)"‪Console.WriteLine("there is no file‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪If Not System.IO.File.Exists("c:ahmed.txt") Then‬‬ ‫)"‪Console.WriteLine("there is no file‬‬ ‫‪End If‬‬‫ﻟﻜﻨﻚ رﺑﻤﺎ ﻟﻢ ﺗﻘﻢ ﺑﺎﻗﺘﻨﺎص ﺧﻄﺄ ﻛﻮن اﻟﻤﻠﻒ ﻟﻠﻘﺮاءة ﻓﻘﻂ ، وﺗﺮﻏﺐ ﻓﻲ ﺻﻮرة ﻗﻨﺺ اﺧﻄﺎء‬‫ﻣﻮﺣﺪة ، أو ﻷي اﻋﺘﺒﺎرات أﺧﺮى ﺗﺮﻏﺐ ﻓﻲ ﻋﻤﻞ ‪ throw‬ﻟﻠﻤﺒﺮﻣﺞ ﻣﺜﻼ ﻟﻮ ﻛﻨﺖ ﺗﺒﺮﻣﺞ ﻓﺌﺔ ﻟﻴﺘﻢ‬ ‫ً‬ ‫اﺳﺘﺨﺪاﻣﻬﺎ . ﻷي ﻣﻦ ﻫﺬه اﻻﻋﺘﺒﺎرات ﻳﻤﻜﻦ ﻋﻤﻞ ‪ throw‬ﻟﺨﻄﺄ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬‫202‬
  • ‫اﻷﺧﻄﺎء و ﻣﻌﺎﻟﺠﺘﻬﺎ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﻌﺎﺷﺮ‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫))"‪if (!System.IO.File.Exists("c:ahmed.txt‬‬ ‫{‬ ‫;)"‪throw new Exception("there is no file‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪If Not System.IO.File.Exists("c:ahmed.txt") Then‬‬ ‫)"‪Throw New Exception("there is no file‬‬ ‫‪End If‬‬‫ﻫﻜﺬا ﺗﺠﺪ ان اﻟﻔﻴﺠﻮال ﺳﺘﻮدﻳﻮ ﻗﺎم ﺑﺎﻇﻬﺎر ﺧﻄﺄ ﺑﺎﻟﺮﺳﺎﻟﺔ اﻟﺘﻲ اوﺿﺤﺘﻬﺎ ، ﺗﺴﺘﻄﻴﻊ ﻻﺣﻘﺎ ﻗﺮاءة‬ ‫ً‬ ‫ﻛﺎﺋﻦ اﻟﺨﻄﺄ واﻟﺘﻌﺎﻣﻞ ﻣﻌﻪ ﻛﻤﺎ ﺗﺘﻌﺎﻣﻞ ﻣﻊ اﻟﺨﻄﺄ اﻟﺬي ﻳﻨﺘﺞ ﺗﻠﻘﺎﺋﻴﺎ ﻣﻦ اﻟﻔﻴﺠﻮال ﺑﻴﺴﻚ.‬ ‫ً‬ ‫5. اﻗﺘﻨﺎص اﻷﺧﻄﺎء ‪  Catching Exceptions‬‬‫اﻵن ﺟﺎء دور اﻗﺘﻨﺎص اﻷﺧﻄﺎء ، اﺑﺴﻂ ﻃﺮﻳﻘﺔ ﻫﻲ ﺑﺎﺳﺘﺨﺪام ‪ Try‬ﺑﺤﻴﺚ ﻳﺨﺮج اﻟﺒﺮﻧﺎﻣﺞ ﻣﻦ‬ ‫اﻟﺒﻠﻮك ﻓﻲ ﺣﺎﻟﺔ وﺟﻮد اﻟﺨﻄﺄ دون ان ﻳﺘﺴﺒﺐ ﻓﻲ ﺗﻮﻗﻒ اﻟﺒﺮﻧﺎﻣﺞ ، ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪try‬‬ ‫{‬ ‫;001 =+ ‪x‬‬ ‫;)"‪console.writeLine("no errror‬‬ ‫}‬ ‫‪catch‬‬ ‫{‬ ‫;)"!‪console.writeLine("some error‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Try‬‬ ‫001 =+ ‪x‬‬ ‫)"‪Console.WriteLine("no errror‬‬ ‫‪Catch‬‬ ‫)"!‪Console.WriteLine("some error‬‬ ‫‪End Try‬‬‫ﻓﻲ ﺣﺎﻟﺔ وﺟﻮد ﺧﻄﺄ ﻓﻲ ﻋﻤﻠﻴﺔ اﻟﺠﻤﻊ اﻟﺴﺎﺑﻘﺔ ﻓﺴﻴﺘﻢ ﻣﺒﺎﺷﺮة اﻻﻧﺘﻘﺎل إﻟﻰ ‪ ، catch‬ﻓﻴﻤﺎ ﻋﺪا ذﻟﻚ‬ ‫ﺳﻴﻮاﺻﻞ اﻟﺒﺮﻧﺎﻣﺞ دون اﻟﻤﺮور ﻋﻠﻴﻬﺎ ، وﻓﻲ ﻛﻞ اﻻﺣﻴﺎن ﻟﻦ ﻳﺘﻢ اﻳﻘﺎف اﻟﺒﺮﻧﺎﻣﺞ.‬ ‫ﻳﻤﻜﻨﻨﺎ اﻳﻀﺎ ﻋﺮض ﺗﻔﺎﺻﻴﻞ ﻋﻦ اﻟﺨﻄﺄ اﻟﺬي ﺣﺪث ﺑﺎﺳﺘﺨﺪام اﻟﺨﺼﺎﺋﺺ اﻟﺴﺎﺑﻘﺔ‬ ‫ً‬‫302‬
  • ‫اﻷﺧﻄﺎء و ﻣﻌﺎﻟﺠﺘﻬﺎ‬   ‫اﻟﺒﺎب اﻟﻌﺎﺷﺮ‬ 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); } VB.NET ‫ﻛﻮد‬ 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،‫ﻟﻮ ﻛﻨﺎ ﻧﻌﺮف ﺑﻌﺾ اﻷﺧﻄﺎء اﻟﺘﻲ ﻳﻤﻜﻦ ان ﺗﺤﺪث، ﻓﻴﻤﻜﻨﻨﺎ اﺧﺘﺒﺎرﻫﺎ وﻋﺮض اﻟﺮﺳﺎﻟﺔ ﻓﻴﻤﺎ ﻋﺪا ذﻟﻚ‬‫ﻟﻨﻔﺘﺮض اﻟﻤﺜﺎل اﻟﺘﺎﻟﻲ ﻓﻲ ﺣﺎﻟﺔ ﻛﻮﻧﻨﺎ ﻧﻌﺮف أن اﻟﺨﻄﺄ ﻳﻤﻜﻦ ان ﻳﻜﻮن ﺑﺴﺒﺐ ﺗﺠﺎوز اﻟﻤﺠﺎل‬ :‫، وﻓﻴﻤﺎ ﻋﺪا ذﻟﻚ ﺳﻨﻈﻬﺮ رﺳﺎﻟﺔ ﺑﺨﻄﺄ ﻋﺎم‬overflow 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); }  204
  • ‫اﻷﺧﻄﺎء و ﻣﻌﺎﻟﺠﺘﻬﺎ‬   ‫اﻟﺒﺎب اﻟﻌﺎﺷﺮ‬VB.NET ‫ﻛﻮد‬Try x += 100 Console.WriteLine("no errror")Catch e0 As OverflowException 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. اﺳﺘﺨﺪام‬‫ وﻳﺘﻢ ﺗﻨﻔﻴﺬﻫﺎ ﻓﻲ ﺣﺎﻟﺔ وﺟﻮد ﺧﻄﺄ او‬try - catch ‫ﺗﺴﺘﺨﺪم ﻟﻠﺘﻨﻔﻴﺬ ﺑﻌﺪ ﻧﻬﺎﻳﺔ اﻟﺒﻠﻮك‬‫ ﻣﻦ ﻋﺪﻣﻪ‬x ‫ﻋﺪﻣﻪ، ﻓﻤﺜﻼ ﻟﻮ ﻛﻨﺎ ﻧﺮﻏﺐ ﻓﻲ ﻃﺒﺎﻋﺔ ﻧﺺ ﻣﺎ ﺑﻐﺾ اﻟﻨﻈﺮ ﻋﻦ ﺣﺪوث ﺧﻄﺄ ﻓﻲ اﻟﻤﺘﻐﻴﺮ‬ ً :‫ﻧﻜﺘﺐ اﻟﻜﻮد اﻟﺘﺎﻟﻲ‬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.NET ‫ﻛﻮد‬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 Try205
  • ‫اﻷﺧﻄﺎء و ﻣﻌﺎﻟﺠﺘﻬﺎ‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﻌﺎﺷﺮ‬ ‫5. 2. اﺳﺘﺨﺪام ‪break‬‬ ‫ﻟﻠﺨﺮوج ﻣﻦ اﻻﺳﺘﻨﺜﻨﺎء ﻓﻲ ﻣﺮﺣﻠﺔ ﻣﺎ ، ﻳﻤﻜﻦ اﺳﺘﺨﺪام ‪ break‬أو ‪ Exit Try‬ﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﻔﻴﺠﻮال‬ ‫ﺑﻴﺴﻚ.‬ ‫5. 3. اﺳﺘﺨﺪام ‪  Target Site‬‬ ‫ﺗﻮﻓﺮ ﻫﺬه اﻟﺨﺎﺻﻴﺔ ﻣﻌﻠﻮﻣﺎت ﻋﺪﻳﺪة ﺣﻮل اﻟﻔﺌﺔ واﻟﺪاﻟﺔ اﻟﺘﻲ ﻗﺎﻣﺖ ﺑﻌﻤﻞ ‪ throw‬ﻟﻠﺨﻄﺄ، ﻳﻤﻜﻦ‬ ‫اﻻﺳﺘﻔﺎدة ﻣﻨﻬﺎ ﻓﻲ ﻋﻤﻞ ‪ Debug‬ﻟﻤﻌﺮﻓﺔ ﻣﻜﺎن ﺣﺪوث اﻟﺨﻄﺄ.‬ ‫5. 4. اﺳﺘﺨﺪام ‪  HelpLink‬‬ ‫ﺗﺴﺘﻄﻴﻊ اﻓﺎدة ﻣﺴﺘﺨﺪم اﻟﻔﺌﺔ أو اﻟﻤﺴﺘﺨﺪم ﺑﻬﺎ ، ﻋﻦ ﻃﺮﻳﻖ وﺿﻊ ﻟﻴﻨﻚ ﻣﻌﻴﻦ ﻳﻤﻜﻨﻪ اﻻﺳﺘﻔﺎدة ﻣﻨﻪ‬ ‫ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪try‬‬ ‫{‬ ‫;001 =+ ‪m‬‬ ‫;)"‪Console.WriteLine("no errror‬‬ ‫}‬ ‫)‪catch (Exception e‬‬ ‫{‬ ‫;"‪e.HelpLink = "www.ahmedgamal-space.blogspot.com‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Try‬‬ ‫001 =+ ‪m‬‬ ‫)"‪Console.WriteLine("no errror‬‬ ‫‪Catch e As Exception‬‬ ‫"‪e.HelpLink = "www.ahmedgamal-space.blogspot.com‬‬ ‫‪End Try‬‬‫602‬
  • ‫اﻷﺧﻄﺎء و ﻣﻌﺎﻟﺠﺘﻬﺎ‬   ‫اﻟﺒﺎب اﻟﻌﺎﺷﺮ‬   ‫6. ﻋﻤﻞ أﺧﻄﺎء ﺧﺎﺻﺔ‬‫ﻳﻤﻜﻨﻚ ﺗﻌﺮﻳﻒ ﻓﺌﺔ ﻣﻦ اﻟﻨﻮع ﺧﻄﺄ ﻳﻤﻜﻨﻚ اﺳﺘﺨﺪاﻣﻬﺎ ﻻﺣﻘﺎ ﻓﻲ ﺑﺮاﻣﺠﻚ ﻳﺘﻢ اﺷﺘﻘﺎﻗﻬﺎ ﻣﻦ‬ ً‫ ﻛﻤﺎ أﻧﻚ ﺗﺤﺘﺎج أﻳﻀﺎ ﻟﺠﻌﻠﻬﺎ ﻣﺸﺘﻘﺔ ﻣﻦ اﻟﻔﺌﺔ‬ApplicationException ‫اﻟﻔﺌﺔ‬ ً‫ وﺧﻼﻓﻪ ، ﻳﻤﻜﻨﻚ ﺗﻌﺮﻳﻒ‬Remoting ‫ ﻣﻦ اﺟﻞ اﻣﻜﺎﻧﻴﺔ اﺳﺘﺨﺪاﻣﻬﺎ ﻓﻲ ال‬Serializable : ‫ﺧﻄﺄ ﺧﺎص ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ‬ ً C# ‫ﻛﻮد‬ public class NewException : ApplicationException, ISerializable { public NewException() { // something here } public NewException(string message) { // something here } public NewException(string message, Exception inner) { // something here. } // ‫ ال ﻟﻌﻤﻠﻴﺔ‬Serilization protected NewException(SerializationInfo info, StreamingContext context) { // Add something here. } }207
  • ‫اﻷﺧﻄﺎء و ﻣﻌﺎﻟﺠﺘﻬﺎ‬   ‫اﻟﺒﺎب اﻟﻌﺎﺷﺮ‬ VB.NET ‫ﻛﻮد‬ Public Class NewException Inherits ApplicationException 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. End Sub ‫ ال ﻟﻌﻤﻠﻴﺔ‬Sterilization Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext) Add something here. End Sub End Class :MSDN ‫ﻟﻠﻤﺰﻳﺪ ﺣﻮل اﻻﺧﻄﺎء واﻗﺘﻨﺎﺻﻬﺎ ﻳﻤﻜﻨﻚ اﻟﺮﺟﻮع إﻟﻰ‬ ‫راﺑﻂ‬ http://msdn.microsoft.com/en-us/library/ms229014(VS.80).aspx208
  • 209
  • ‫اﻟﺒﺎب‬ ‫11‬‫اﻟﺘﺠﻤﻴﻌﺎت ‪Collections‬‬‫012‬
  • 211
  • ‫اﻟﺘﺠﻤﻴﻌﺎت ‪Collections‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺤﺎدي ﻋﺸﺮ‬‫ﻓﻲ ﺗﻄﺒﻴﻘﺎﺗﻨﺎ اﻟﺒﺮﻣﺠﻴﺔ اﻟﻤﺨﺘﻠﻔﺔ ﻋﺎدة ﻣﺎ ﻧﻠﺠﺄ ﻟﻌﻤﻞ ‪ container‬ﻳﺤﺘﻮي ﻋﻠﻰ ﻋﺪة ﻋﻨﺎﺻﺮ،‬‫ﻣﻦ أﺟﻞ ذﻟﻚ ﻛﺎﻧﺖ ال ‪ array‬ورأﻳﻨﺎ ان ﺑﺎﻣﻜﺎﻧﻨﺎ ﻋﻤﻞ ‪ array‬ﻣﻦ اﻻرﻗﺎم واﻟﻨﺼﻮص واﺧﻴﺮًا ﺣﺘﻰ‬‫ﻣﻦ ﻓﺌﺎت ﻣﺨﺘﻠﻔﺔ. إﻻ اﻧﻨﺎ ﻓﺪ ﻧﺤﺘﺎج إﻟﻰ ﺑﻌﺾ اﻟﻤﻬﺎم اﻻﻛﺜﺮ ﻣﻦ ﺗﻠﻚ اﻟﺘﻲ ﺗﻮﻓﺮﻫﺎ ﻟﻨﺎ ال ‪،array‬‬ ‫ﻣﻦ اﺟﻞ ﻫﺬا وﺟﺪت ال ‪ collections‬اﻟﻤﺨﺘﻠﻔﺔ، ﻓﻲ درﺳﻨﺎ ﻫﺬا ﺳﻮف ﻧﺘﻌﺮف ﻋﻠﻴﻬﺎ إن ﺷﺎء اﷲ.‬‫1. ال‪ Interfaces‬ﻓﻲ‪System.Collections‬‬ ‫ﻟﻮ راﺟﻌﻨﺎ اﻟﻮاﺟﻬﺎت اﻟﻤﻮﺟﻮدة ﻓﻲ ال ‪ collection‬ﻟﻮﺟﺪﻧﺎ اﻟﻮاﺟﻬﺎت اﻟﺘﺎﻟﻴﺔ:‬ ‫‪:ICollection‬‬ ‫ﺗﺤﺘﻮي ﻫﺬه اﻟﻮاﺟﻬﺔ ﻋﻠﻰ ﺑﻌﺾ اﻟﻨﻘﺎط اﻻﺳﺎﺳﻴﺔ ﻣﺜﻞ ال ‪ Size‬وال‬ ‫‪ IsSynchronized‬وﺧﻼﻓﻪ ، ﻟﻬﺎ اﻟﺸﻜﻞ اﻟﻌﺎم اﻟﺘﺎﻟﻲ:‬‫#‪C‬‬ ‫ﻛﻮد‬‫‪public interface ICollection : IEnumerable‬‬‫{‬ ‫} ;‪int Count { get‬‬ ‫} ;‪bool IsSynchronized { get‬‬ ‫} ;‪object SyncRoot { get‬‬ ‫;)‪void CopyTo(Array array, int index‬‬‫}‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫‪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‬‬ ‫ﺗﻌﺮﻓﻨﺎ ﻋﻠﻴﻬﺎ ﺳﺎﺑﻘﺎ.‬ ‫‪:IComparer‬‬ ‫‪:IDictionary‬‬‫ﺗﺴﺘﺨﺪم ﻛﻤﺎ ﻫﻮ واﺿﺢ ﻣﻦ اﺳﻤﻬﺎ ﻣﻦ اﺟﻞ اﻻدﻟﺔ، ﻳﻤﻜﻦ اﺳﺘﺨﺪاﻣﻬﺎ ﻟﺘﺨﺰﻳﻦ ﻣﺜﻼ ﺑﻴﺎﻧﺎت‬ ‫ً‬‫اﻟﻤﻮﻇﻔﻴﻦ وﻋﻨﺎوﻳﻨﻬﻢ ﺑﺤﻴﺚ ﻳﻤﻜﻦ اﻟﻌﺜﻮر ﺑﻌﺪ ذﻟﻚ ﻋﻠﻰ اﻟﺸﺨﺺ ﺑﺪﻻﻟﺔ اﺳﻤﻪ او ﻋﻨﻮاﻧﻪ ، ﺗﺤﺘﻮي‬ ‫ﻋﻠﻰ دوال ﻟﻼﺿﺎﻓﺔ واﻟﺤﺬف وﺧﻼﻓﻪ . اﻟﺸﻜﻞ اﻟﻌﺎم ﻟﻬﺎ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ :‬‫212‬
  • Collections ‫اﻟﺘﺠﻤﻴﻌﺎت‬   ‫اﻟﺒﺎب اﻟﺤﺎدي ﻋﺸﺮ‬ 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.NET ‫ﻛﻮد‬ 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 ReadOnly Property Keys() As ICollection ReadOnly Property Values() As ICollection 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 .‫ﺗﻢ ﺷﺮﺣﻬﺎ ﺳﺎﺑﻘﺎ‬ ً :IEnumerator .‫ﺗﻢ ﺷﺮﺣﻬﺎ ﺳﺎﺑﻘﺎ‬ ً :IDictionaryEnumerator interface ‫ ، ﻫﺬا ﻫﻮ ال‬GetEnumerator ‫ ﺳﺘﺠﺪ اﻟﺪاﻟﺔ‬IDictionary ‫ﻟﻮ ﻻﺣﻈﺖ ﻓﻲ‬ :‫اﻟﺨﺎص ﺑﻬﺬه اﻟﺪاﻟﺔ ، ﻟﻬﺎ اﻟﺸﻜﻞ اﻟﻌﺎم اﻟﺘﺎﻟﻲ‬ 213
  • Collections ‫اﻟﺘﺠﻤﻴﻌﺎت‬   ‫اﻟﺒﺎب اﻟﺤﺎدي ﻋﺸﺮ‬ C# ‫ﻛﻮد‬ public interface IDictionaryEnumerator : IEnumerator { DictionaryEntry Entry { get; } object Key { get; } object Value { get; } } VB.NET ‫ﻛﻮد‬ Public Interface IDictionaryEnumerator Inherits IEnumerator ReadOnly Property Entry() As DictionaryEntry ReadOnly Property Key() As Object ReadOnly Property Value() As Object End Interface :IHashCodeProvider .GetHashCode ‫ اﻟﻤﻌﻴﻦ ﺑﺎﺳﺘﺨﺪام اﻟﺪاﻟﺔ‬collection ‫ ﻟﻞ‬hash code ‫ﻳﺨﺘﺺ ﺑﺎﻋﺎدة ال‬ :IList ‫ﻗﺎﺋﻤﺔ ، ﻫﺬا ﻛﻞ ﻣﺎ ﻓﻲ اﻷﻣﺮ ، ﺗﺤﺘﻮي ﻋﻠﻰ ﻋﺪة دوال ﺗﺴﻬﻞ اﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﻟﻼﺿﺎﻓﺔ واﻟﺒﺤﺚ واﻟﺤﺬف‬ :‫وﺧﻼﻓﻪ اﻟﺸﻜﻞ اﻟﻌﺎم ﻟﻬﺎ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ 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); }214
  • Collections ‫اﻟﺘﺠﻤﻴﻌﺎت‬   ‫اﻟﺒﺎب اﻟﺤﺎدي ﻋﺸﺮ‬ VB.NET ‫ﻛﻮد‬ 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 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 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. اﻟﻔﺌﺎت ﻓﻲ‬ :‫ﻳﺤﺘﻮي ﻋﻠﻰ اﻟﻔﺌﺎت اﻟﺘﺎﻟﻴﺔ‬ ArrayList • Hashtable • Queue • SortedList • Stack •   ArrayList .1 .2‫ ﻣﻦ ﺣﻴﺚ ﺗﺨﺰﻳﻨﻬﺎ‬array ‫ ﻛﻤﺎ ﻫﻮ واﺿﺢ ﻣﻦ اﻻﺳﻢ ، ﺗﺘﻤﻴﺰ ﺑﻨﻔﺲ ﺳﻤﺎت ال‬array ‫ﻫﻲ ﻗﺎﺋﻤﺔ‬‫ﻟﻌﺪة ﺑﻴﺎﻧﺎت، اﺿﺎﻓﺔ ﻟﻤﻤﻴﺰات اﻟﻘﺎﺋﻤﺔ اﻟﺘﻲ ﺗﺴﻬﻞ ﻋﻤﻠﻴﺎت اﻻﺿﺎﻓﺔ واﻟﺘﻌﺪﻳﻞ واﻟﺘﺮﺗﻴﺐ واﻟﺤﺬف‬ .‫وﺧﻼﻓﻪ داﺧﻞ ﻋﻨﺎﺻﺮ ﻫﺬه اﻟﻤﺼﻔﻮﻓﺔ‬‫ﻟﻨﻔﺘﺮض ان ﻟﺪﻳﻨﺎ ﻓﺌﺔ )ﺳﻴﺎرة( اﻟﺴﺎﺑﻘﺔ واﻟﺘﻲ ﺗﺤﺘﻮي ﻋﻠﻰ اﺳﻢ اﻟﺴﻴﺎرة وﻣﻮدﻳﻠﻬﺎ ، ﻛﻨﺎ ﻧﻌﺮف‬ :‫ﻣﺼﻔﻮﻓﺔ ﻣﻨﻬﺎ ﺑﺎﺳﺘﺨﺪام اﻷﻣﺮ اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ Car[] carArray = new Car[4]; VB.NET ‫ﻛﻮد‬ Dim carArray As Car() = New Car(3)215
  • ‫اﻟﺘﺠﻤﻴﻌﺎت ‪Collections‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺤﺎدي ﻋﺸﺮ‬‫رﺑﻤﺎ ﻟﻢ ﺗﻜﻦ ﺗﻌﺮف اﻧﻚ ﺗﺤﺘﺎج ﻻرﺑﻊ ﺳﻴﺎرات ﻓﻘﻂ ، رﺑﻤﺎ ﺗﺤﺘﺎج ﻟﻠﺰﻳﺎدة او ﻟﻠﻨﻘﺼﺎن ، رﺑﻤﺎ ﺗﺮﻏﺐ‬‫ﺑﺤﺬف واﺣﺪة ﻣﻨﻬﻢ ﻣﻦ اﻟﻤﻨﺘﺼﻒ ... اﻟﺦ ، ﻓﻜﻤﺎ ﺗﺮى ﻻ ﺗﻮﻓﺮ ﻟﻨﺎ ال ‪ array‬اﻟﻜﺜﻴﺮ ﻣﻦ اﻟﺨﻴﺎرات‬ ‫ﻟﺘﺴﻬﻴﻞ اﻟﺘﻌﺎﻣﻞ ﻣﻊ ﻫﺬه اﻟﺨﺼﺎﺋﺺ ، ﺳﺘﺤﺘﺎج ﻟﺒﻌﺾ اﻷواﻣﺮ ﻟﻠﺤﺬف وﺧﻼﻓﻪ.‬‫ﺑﺪاﻳﺔ ﻗﻢ ﺑﻌﻤﻞ ‪ using‬ل ‪ System.Collection‬ﻟﺘﻜﻮن ﻗﺎدرًا ﻋﻠﻰ اﻟﺘﻌﺎﻣﻞ اﻟﻤﺒﺎﺷﺮ ﻣﻌﻬﺎ‬ ‫ﻻﺣﻘﺎ.‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;‪using System.Collections‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Imports System.Collections‬‬ ‫ﻟﻜﻦ ﺟﺎءت ‪ ArrayList‬ﻟﺘﻠﻘﻲ ﻋﻦ ﻛﺎﻫﻠﻚ اي ﻣﺸﺎﻛﻞ ﺑﺨﺼﻮص ﻫﺬه اﻟﻌﻤﻠﻴﺎت ، ﻛﻞ ﻣﺎ ﻋﻠﻴﻚ‬ ‫ﻫﻮ ﺗﻌﺮﻳﻒ ‪ ArrayList‬ﺑﺎﻟﻄﺮﻳﻘﺔ اﻟﺘﺎﻟﻴﺔ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)(‪ArrayList carList = new ArrayList‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)(‪Dim carList As New ArrayList‬‬ ‫واﻵن ﻳﻤﻜﻨﻚ اﺿﺎﻓﺔ ﺳﻴﺎرة:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)0991 ,"‪Car temp = new Car("BMW‬‬ ‫;)‪carList.Add(temp‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)0991 ,"‪Dim temp As New Car("BMW‬‬ ‫)‪carList.Add(temp‬‬‫ﺗﺴﺘﻄﻴﻊ اﻳﻀﺎ ﻋﻤﻞ ‪ Insert‬ﻓﻲ ﺟﺰء ﻣﻌﻴﻦ، ﻻﺿﺎﻓﺔ اﻟﺴﻴﺎرة ﻣﺜﻼ ﻓﻲ اﻟﻤﻜﺎن اﻟﺜﺎﻟﺚ ﻧﻜﺘﺐ اﻟﻜﻮد‬ ‫ً‬ ‫ً‬ ‫اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)‪carList.Insert(temp‬‬‫612‬
  • ‫اﻟﺘﺠﻤﻴﻌﺎت ‪Collections‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺤﺎدي ﻋﺸﺮ‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)‪carList.Insert(temp‬‬ ‫ﻓﻲ اﻟﻨﺎﺣﻴﺔ اﻷﺧﺮى ، ﺗﺴﺘﻄﻴﻊ ﻣﺴﺢ ﻛﺎﻣﻞ اﻟﻘﺎﺋﻤﺔ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)(‪carList.Clear‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)(‪carList.Clear‬‬ ‫أو ﺣﺬف ﻋﻨﺼﺮ ﻣﻌﻴﻦ ﺑﺪﻻﻟﺔ ﻣﻮﻗﻌﻪ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)4(‪carList.RemoveAt‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)4(‪carList.RemoveAt‬‬ ‫او ﺑﺪﻻﻟﺔ اﻟﻌﻨﺼﺮ ﻧﻔﺴﻪ :‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)‪carList.Remove(temp‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)‪carList.Remove(temp‬‬‫ﻳﻤﻜﻨﻨﺎ اﺳﺘﺨﺪام اﻟﺨﺎﺻﻴﺔ ‪ Count‬ﻟﻤﻌﺮﻓﺔ اﻟﻌﺪد، وﺑﺎﻟﺘﺎﻟﻲ اﻟﺪوران ﻋﻠﻴﻬﻢ ﺟﻤﻴﻌﺎ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ ‫ً‬ ‫ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)++‪for (int i = 0; i < carList.Count; i‬‬ ‫{‬ ‫;]‪temp = (Car)carList[i‬‬ ‫}‬‫712‬
  • ‫اﻟﺘﺠﻤﻴﻌﺎت ‪Collections‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺤﺎدي ﻋﺸﺮ‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫1 - ‪For i As Integer = 0 To carList.Count‬‬ ‫)‪temp = DirectCast(carList(i), Car‬‬‫‪Next‬‬‫ﻳﻤﻜﻨﻨﺎ اﺳﺘﺨﺪام ﺑﻌﺾ اﻟﺨﺼﺎﺋﺺ اﻷﺧﺮى ﻣﺜﻞ ‪ Sort‬ﻛﻤﺎ ﺗﻌﻠﻤﻨﺎ ﺳﺎﺑﻘﺎً، ﻳﻤﻜﻨﻨﺎ ﺗﺤﻮﻳﻠﻬﺎ إﻟﻰ ‪array‬‬‫ﻋﺎدﻳﺔ ﺑﺎﺳﺘﺨﺪام اﻟﺪاﻟﺔ ‪ ،ToArray‬اﻟﺪاﻟﺔ ‪ Reverse‬ﺳﺘﻌﻜﺲ ﺗﺮﺗﻴﺐ اﻟﻘﺎﺋﻤﺔ، اﻟﺪاﻟﺔ ‪IndexOf‬‬‫ﺗﺴﺘﺨﺪم ﻟﻠﺒﺤﺚ ﺑﺎﻟﻄﺮﻳﻘﺔ اﻟﺘﺎﻟﻴﺔ، ﻟﻨﻔﺘﺮض ﻟﺪﻳﻨﺎ اﻟﺴﻴﺎرة ‪ temp‬وﻧﺮﻏﺐ ﻓﻲ اﻟﺒﺤﺚ ﻋﻨﻬﺎ ﺿﻤﻦ‬ ‫اﻟﺴﻴﺎرات اﻟﻤﻮﺟﻮدة ، ﺳﻴﻜﻮن ذﻟﻚ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬‫#‪C‬‬ ‫ﻛﻮد‬‫;)0 ,‪int find = carList.IndexOf(temp‬‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫)0 ,‪Dim find As Integer = carList.IndexOf(temp‬‬‫وﻫﻜﺬا ﺗﺴﺘﻄﻴﻊ اﺳﺘﺨﺪام اﻟﻤﺘﻐﻴﺮ ‪ Find‬ﻟﻠﻮﺻﻮل إﻟﻰ ﻣﻜﺎن اﻟﻌﻨﺼﺮ واﻟﺘﻌﺎﻣﻞ ﻣﻌﻪ ﻛﻤﺎ ﺗﺮﻳﺪ ، ﻛﻤﺎ‬ ‫ﻳﻤﻜﻨﻚ ﺗﺤﺪﻳﺪ ﻧﻘﻄﺔ ﺑﺪاﻳﺔ اﻟﺒﺤﺚ 0 ﻛﻤﺎ ﺣﺪدﻧﺎ او ﺗﻐﻴﻴﺮﻫﺎ او ﻋﺪم اﺳﺘﺨﺪاﻣﻬﺎ اﺻﻼ .‬ ‫ً‬ ‫2. 2. ‪  HashTable‬‬‫واﺣﺪ ﻣﻦ ﻃﺮق ﺗﺨﺰﻳﻦ اﻟﺒﻴﺎﻧﺎت ‪ ،Data Structure‬ﻣﻬﻤﺘﻪ اﻻﺳﺎﺳﻴﺔ ﺗﺴﻬﻴﻞ اﻟﺒﺤﺚ ﻋﻦ اﻟﺒﻴﺎﻧﺎت‬‫اﻟﻤﺮﺗﺒﻄﺔ ، إذا ﻟﻢ ﺗﻜﻦ ﻗﺪ ﻣﺮت ﻋﻠﻴﻚ ﻫﺬه ال  ‪ Hash Table‬ﻣﻦ ﻗﺒﻞ ﻓﺎﻧﺼﺤﻚ ﺑﺎﻟﺘﻌﺮف ﻋﻠﻴﻬﺎ ﻣﻦ‬ ‫ﺧﻼل وﻳﻜﺒﻴﺪﻳﺎ ﻫﻨﺎ:‬ ‫راﺑﻂ‬‫‪http://en.wikipedia.org/wiki/Hash_table‬‬ ‫وﺑﺎﺧﺘﺼﺎر ﺷﺪﻳﺪ ، ﻓﺎل ‪ HashTable‬ﻫﻲ ﻋﺒﺎرة ﻋﻦ ﻣﺠﻤﻮﻋﺔ ﻣﻦ اﻟﻤﻔﺎﺗﻴﺢ ‪ keys‬ﻳﺨﺰن ﻣﻌﻬﺎ ﻣﻦ‬ ‫اﻟﺪﻻﺋﻞ ‪ Indexes‬ﺗﺸﻴﺮ إﻟﻰ ﻣﻜﺎن ﺑﺎﻗﻲ اﻟﻘﻴﻢ اﻟﻤﺮﺗﺒﻄﺔ ﻣﻊ اﻟﻤﺘﺎح اﻻﺳﺎﺳﻲ.‬‫812‬
  • ‫اﻟﺘﺠﻤﻴﻌﺎت ‪Collection‬‬ ‫‪ns‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺤﺎﺎدي ﻋﺸﺮ‬ ‫ة 11. 1. ﻨﻴﺔ ال ‪ble‬‬ ‫‪HashTab‬‬ ‫ﺑﻨ‬ ‫اﻟﺼﻮرة‬‫‪ HashT‬ﻋﺒﺎرة ﻋﻦ  ‪ Linked  List‬ﺮﺗﺒﻂ ﻛﻞ ﻋﻨﺼﺮ ﻓﻴﻪ‬ ‫ﻋ‬ ‫ﻳﺮ‬ ‫ﻓﻲ اﻟﺴﺎﺑﻖ ﻛﻨﺎ ﻮم ﺑﺘﻜﻮﻳﻦ ال ‪Table‬‬ ‫ﻧﻘﻮ‬‫ﻚ ﺑﺒﺴﺎﻃﺔ‬ ‫ﺨﺘﻠﻔﺔ، أﻣﺎ ﻵن ﻓﻴﻤﻜﻨﻚ‬ ‫اﻵ‬ ‫ﺮاءاﺗﻪ اﻟﻤﺨ‬ ‫ب‪ Linked List‬ﺮى، وﻛﻨﺎ ﻧﻘﻮم ﺑﻌﻤﻞ دواﻟﻪ واﺟﺮ‬ ‫ﻧ‬ ‫اﺧﺮ‬ ‫ ‪d‬‬‫ﺪام اﻷواﻣﺮ اﻟﺘﻘﻠﻴﺪﻳﺔ‬ ‫ﺪء ﻓﻲ ﺿﻊ اﻟﺒﻴﺎﻧﺎت ﻓﻴﻪ ﻣﺒﺎﺷﺮ‬ ‫ﺮة ﺑﺎﺳﺘﺨﺪ‬ ‫وﺿ‬ ‫ﺗﻌﺮﻳﻒ ‪shTable‬‬ ‫‪ Has‬واﻟﺒﺪ‬ ‫‪ Re‬وﺧﻼﻓﻪ ﻣﻤﺎ ﺗﻌﻠﻤﻨﺎه ﻓﻲ اﻟﺪرس اﻟﺴﺎﺑﻖ.‬ ‫‪ A‬و ‪emove‬‬ ‫‪Add,AddR‬‬ ‫‪Range‬‬ ‫2. 3. ‪eue‬‬ ‫‪Que‬‬ ‫اﻟﺘﺮﺟﻤﺔ ﺤﺮﻓﻴﺔ ﻟﻪ ﻲ اﻟﻄﺎﺑﻮر ، وﻣﻊ اﻧﻲ ﻻ اﺳﺘﺴﻴﻎ ﺑﻌﺾ اﻟﺘﺮﺟ‬‫ﺟﻤﺎت ﻟﻜﻦ ﻻ ﺑﺄس ﻣﻦ‬ ‫ﻓﻲ‬ ‫اﻟﺤ‬‫‪ Que‬ﻣﺎ ﻫﻮ إﻻ ﻃﺎﺑﻮر ﻓﻌﻼ ، ﺣﻴﺚ ﻳﺘﻢ دﻓﻊ ﺒﻴﺎﻧﺎت إﻟﻴﻪ ﺑﺎﺳﺘﺨﺪام ‪Enqueue‬‬ ‫ﺑ‬ ‫اﻟﺒ‬ ‫ﻓ ً‬ ‫ﺗﻮﺿﻴﺢ ان ال ‪eue‬‬‫ﻴﻦ ﻓﻨﺤﻦ ﻫﻨﺎ ﻧﺘﺤﺪث ﻋﻦ ﻃﺎﺑﻮر‬ ‫ﻋ‬ ‫ﻫ‬ ‫‪ ،De‬أول اﻟﺪاﺧﻠﻴﻦ ﻫﻮ اول اﻟﺨﺎرﺟﻴ‬ ‫م ‪equeue‬‬ ‫ﻬﺎ ﺑﺎﺳﺘﺨﺪام‬ ‫واﺧﺮاﺟﻬ‬ ‫ﺣﻘﻴﻘﻲ.‬‫ﺞ ﻟﺘﻠﻘﻲ ﻃﻠﺒﺎت اﻟﻌﻤﻼء، ﻓﻤﻦ ﻄﺒﻴﻌﻲ ان ﻀﻌﻬﺎ ﻓﻲ ﻃﺎﺑﻮر ﻟﻴﺘﻢ‬ ‫ﻃ‬ ‫ﺗﻀ‬ ‫اﻟﻄ‬ ‫ﻃ‬ ‫إذا ﻛﻨﺖ ﺒﺮﻣﺞ ﺑﺮﻧﺎﻣﺞ‬ ‫ﺗﺒ‬ ‫إ‬‫‪ Que‬ﻫﻮ ﺒﺮوﺳﻴﺴﻮر‬ ‫اﻟﺒ‬ ‫ﻣﻌﺎﻟﺠﺔ اﻻﺳﺒﻖ ﺑﺎﻟﻮﺻﻮل اوﻻً، ﻓﻲ اﻟﺴﻴﺮﻓﺮات اﻳﻀﺎً، رﺑﻤﺎ اﺷﻬﺮ ﻣﺜﻠﺔ ال ‪eue‬‬ ‫اﻣ‬ ‫ور‬ ‫ﻓ‬ ‫ﺞ( ﺣﻴﺚ ﻢ ﺗﺮﺗﻴﺐ ﻤﻬﻤﺎت ﻟﻴﺘﻢ ادﺧﺎﻟﻬﺎ ﻰ اﻟﻤﻌﺎﻟﺞ، ﻷول وﺻﻮﻻ ﻟﻠﻄﺎﺑﻮر ﻫﻮ اﻷول‬ ‫ﻫ‬ ‫ﻻ‬ ‫ً‬ ‫اﻷ‬ ‫إﻟﻰ‬ ‫اﻟﻤ‬ ‫ﻳﺘﻢ‬ ‫)اﻟﻤﻌﺎﻟﺞ‬‫ﺜﺔ ﻫﻨﺎك ﻌﺪﻳﺪ ﻣﻦ ﻨﺎﺻﺮ اﻟﺘﻲ‬ ‫اﻟﻌﻨ‬ ‫اﻟﻌ‬ ‫ﻟﺠﺎت اﻟﺤﺪﻳﺜ‬ ‫ﺗﻨﻔﻴﺬًا ﺑﺎﺑﺴﻂ ﺻﻮرة ، ﻟﻜﻦ ﻻ ﺗﻨﺲ اﻧﻪ ﻓﻲ ﻧﻈﻢ اﻟﻤﻌﺎﻟ‬ ‫ﺗ‬ ‫ﺑ‬‫ﺗﺘﺤﻜﻢ ﻓﻲ دﺧﻮل ﻟﺒﻴﺎﻧﺎت ﻣﺜﻞ اﻻوﻟﻮﻳﺔ ﺿﺎﻓﺔ ﻟﻨﻈﺎم ال ‪ Slides‬ﺣﻴﺚ ﻻ ﻳﺘﻢ ﺗﻨﻔﻴﺬ ال ‪ Task‬ﻣﺮة‬ ‫ﻢ‬ ‫اﺿ‬ ‫اﻟ‬ ‫ﻓ‬ ‫واﺣﺪة ... اﻟﺦ.‬ ‫ﺮض ﻃﺎﺑﻮر ااﻟﻌﻤﻼء ﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫ﺑﺎﻟﺸ‬ ‫ﻻ ﻧﺮﻳﺪ ان ﻧﺒﺘﻌﺪ ﻛﺜﻴﺮاً، ﺳﻨﻔﺘﺮ‬ ‫ﻛ‬‫912‬
  • ‫اﻟﺘﺠﻤﻴﻌﺎت ‪Collections‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺤﺎدي ﻋﺸﺮ‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)(‪Queue empQueue = new Queue‬‬ ‫;)(‪employee temp = new employee‬‬ ‫)++‪for (int i = 0; i < 10; i‬‬ ‫{‬ ‫;)(‪temp.userName = Console.ReadLine‬‬ ‫;)‪empQueue.Enqueue(temp‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)(‪Dim empQueue As New Queue‬‬ ‫)(‪Dim temp As New employee‬‬ ‫9 ‪For i As Integer = 0 To‬‬ ‫)(‪temp.userName = Console.ReadLine‬‬ ‫)‪empQueue.Enqueue(temp‬‬ ‫‪Next‬‬‫ﻟﻮ ﻗﻤﻨﺎ اﻵن ﺑﻌﻤﻞ ‪ Loop‬ﻟﻨﻌﻤﻞ ‪ ،Dequeue‬ﺳﺘﺠﺪ ان اول اﻟﻤﻮﻇﻔﻴﻦ دﺧﻮﻻ ﺳﻴﻜﻮن أوﻟﻬﻢ ﺧﺮوﺟﺎ.‬ ‫ً‬ ‫ً‬‫ﻃﺒﻌﺎ ﻻ ﺗﻨﺲ أن ﺑﺎﻣﻜﺎﻧﻚ اﺳﺘﺨﺪام ﺑﻌﺾ اﻟﺨﺼﺎﺋﺺ ﻣﺜﻞ ‪ Count‬وﺧﻼﻓﻪ ﺗﻠﻚ اﻟﺘﻲ ﺷﺮﺣﻨﺎﻫﺎ ﻓﻲ‬ ‫ً‬ ‫اﻟﺪرس اﻟﺴﺎﺑﻖ.‬‫ﻗﺒﻞ اﻟﻨﻬﺎﻳﺔ اﺷﻴﺮ ﻓﻘﻂ إﻟﻰ ان اﻟﺪاﻟﺔ ‪ Dequeue‬ﺗﻌﻴﺪ اﻟﻌﻨﺼﺮ اﻷول وﺗﻘﻮم ﺑﺤﺬﻓﻪ ﻣﺒﺎﺷﺮة ﻣﻦ‬‫اﻟﻄﺎﺑﻮر ، أﻣﺎ اﻟﺪاﻟﺔ ‪ Peek‬ﻓﻬﻲ ﺗﻌﻴﺪ اول ﻋﻨﺼﺮ ﻓﻲ اﻟﺘﺮﺗﻴﺐ وﻟﻜﻨﻬﺎ ﺗﺤﺘﻔﻆ ﺑﻪ ﻓﻲ اﻟﻄﺎﺑﻮر ﻛﻤﺎ‬ ‫ﻛﺎن.‬‫ﻣﻊ ﺗﻄﺒﻴﻖ ﻫﺬه اﻟﻔﺌﺔ، أﺿﻦ اﻇﻦ اﻧﻚ ﺗﺬﻛﺮ ﻟﻮ ﻛﻨﺖ درﺳﺖ ‪ Data Structure‬وﻛﻴﻔﻴﺔ ﺗﻄﺒﻴﻖ ال‬‫‪ Queue‬ﺑﺎﺳﺘﺨﺪام اﻟـ ‪ ، linked list‬وال ‪ circular queue‬واﻟﻜﺜﻴﺮ ﻣﻤﺎ ﻟﻦ ﺗﺰﻋﺞ ﻧﻔﺴﻚ ﺑﻪ ﻣﻨﺬ اﻵن‬ ‫ﻓﺼﺎﻋﺪًا ﻣﻊ ﻫﺬه اﻟﻔﺌﺔ .‬ ‫2. 4. ‪Stack‬‬‫ﻣﺜﻞ ال ‪ Queue‬ﻓﻴﻤﺎ ﻋﺪا اﻧﻪ ﻳﺘﺒﻊ ﺗﻘﻨﻴﺔ ‪ ، LIFO  ‐  Last  Input  First  Output‬ﺣﻴﺚ ان‬‫اﻟﻌﻨﺼﺮ اﻵﺧﻴﺮ ﻓﻲ اﻟﺪﺧﻮل ﻫﻮ اﻷول ﻓﻲ اﻟﺨﺮوج ، ﻳﺘﻢ ادﺧﺎل اﻟﻌﻨﺎﺻﺮ ﺑﺎﺳﺘﺨﺪام ‪ Push‬وﻳﺘﻢ‬‫اﺧﺮاﺟﻬﺎ ﺑﺎﺳﺘﺨﺪام ‪ ، Pop‬ال ‪ Peek‬ﺗﻘﻮم ﺑﻤﻬﻤﺘﻬﺎ ﻛﻤﺎ ﻫﻲ ﻓﻲ ﻋﺮض اﻟﻌﻨﺼﺮ اﻷول وﻫﻮ ﻓﻲ‬ ‫ﺣﺎﻟﺘﻨﺎ اﻵﺧﺮ دﺧﻮﻻ دون ﺣﺬﻓﻪ ﻣﻦ ال ‪.Stack‬‬ ‫ً‬‫022‬
  • ‫اﻟﺘﺠﻤﻴﻌﺎت ‪Collections‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺤﺎدي ﻋﺸﺮ‬ ‫ﺗﻌﺮﻳﻒ ال ‪ Stack‬ﻳﺘﻢ ﺑﺒﺴﺎﻃﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)(‪Stack jobStack = new Stack‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)(‪Dim jobStack As New Stack‬‬ ‫اﻻﺳﺘﺨﺪاﻣﺎت‬‫ﻳﺴﻬﻞ ﺗﺼﻮر اﺳﺘﺨﺪاﻣﺎت ﻣﻦ اﺟﻞ ال ‪ ،Queue‬ذﻟﻚ ان ﻣﻌﻈﻢ ﺗﻄﺒﻴﻘﺎت ﺣﻴﺎﺗﻨﺎ اﻟﻴﻮﻣﻴﺔ ﺗﻌﺘﻤﺪ‬ ‫ﻋﻠﻰ ذﻟﻚ ، ﺣﻴﺚ اﻟﻮاﺻﻞ أوﻻ ﻳﺨﺪم اوﻻ ، ﻟﻜﻦ ال ‪ Stack‬ﺑﻤﺒﺪﺋﺔ اﻟﻤﻨﺎﻓﻲ ﻟﻠﻌﺪاﻟﺔ رﺑﻤﺎ ﺳﻴﻜﻮن‬ ‫ً‬ ‫ً‬‫ﻏﺮﻳﺒﺎ ﺑﻌﺾ اﻟﺸﻲء ﺗﻄﺒﻴﻘﻪ ﻓﻲ ﺣﻴﺎﺗﻨﺎ اﻟﺤﻘﻴﻘﻴﺔ ، ﻟﺬا ﻓﺈن اﺳﺘﺨﺪام ال ‪ Stack‬ﻳﻘﺘﺼﺮ ﻓﻲ اﻟﻌﺎدة‬ ‫ً‬ ‫ﻋﻠﻰ ﺗﻄﺒﻴﻘﺎت اﻟﻜﻮﻣﺒﻴﻮﺗﺮ.‬ ‫اﺑﺴﻂ اﺳﺘﺨﺪام ﻟﻞ ‪ Stack‬ﻫﻮ ﺣﻞ اﻟﻤﻌﺎدﻻت ﻓﻲ اﻟﺒﺮوﺳﻴﺴﻮر، إن اﻟﻤﻌﺎدﻟﺔ:‬ ‫ ‪A + B‬‬ ‫ﺗﺪﺧﻞ إﻟﻰ اﻟﺒﺮوﺳﻴﺴﻮر ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫+‪AB‬‬‫ﻳﺴﻤﻰ ﻫﺬا اﻻﺳﻠﻮب ﺑﺎﺳﻢ ‪ ،postfix‬وﻓﻲ اﻟﺒﺮوﺳﻴﺴﻮر ﻳﺘﻢ ادﺧﺎﻟﻬﻢ ﻓﻲ ‪ Stack‬ﻟﺘﻨﻔﻴﺬﻫﻢ ﺣﻴﺚ ان‬ ‫ﺗﻨﻔﻴﺬﻫﻢ ﻟﻦ ﻳﺘﻢ ﺑﺘﺮﺗﻴﺐ اﻟﻮﺻﻮل ، ﻣﺜﺎل آﺧﺮ ﻓﻲ ﺗﺮﺟﻤﺔ ال ‪ Compilers‬اﻳﻀﺎ.‬ ‫ً‬‫ﻓﻲ اﻟﻤﺮﻓﻘﺎت ﺑﺮﻧﺎﻣﺞ ﻳﻮﺿﺢ ﻛﻴﻔﻴﺔ اﻟﺘﺤﻮﻳﻞ ﺑﻴﻦ ‪ postfix‬و ‪ infix‬ﻛﺎن اﺣﺪ ﻣﺸﺎرﻳﻊ اﻟﻜﻠﻴﺔ ﻓﻲ‬‫اﻟﻔﺮﻗﺔ اﻟﺜﺎﻟﺜﺔ ل ‪ ،FUTEX  Group‬ﻳﻮﺿﺢ اﻟﺒﺮﻧﺎﻣﺞ ﻛﻴﻔﻴﺔ اﻟﺘﺤﻮﻳﻞ وﻛﻴﻔﻴﺔ ﻳﻘﻮم اﻟﺒﺮوﺳﻴﺴﻮر‬‫ﺑﻮﺿﻌﻬﻢ ﻓﻲ ‪ Stack‬وﺗﻨﻔﻴﺬﻫﻢ ، ﻗﻢ ﺑﺎﺧﺘﻴﺎر ‪ View‬ﻻﺳﺘﻌﺮاض ﺳﺮﻋﺔ ﻋﺮض اﻟﺨﻄﻮات ، ﻳﻤﻜﻨﻚ‬‫اﻟﺤﻞ ﺑﺎﺳﺘﺨﺪام اﻻرﻗﺎم او اﻟﺮﻣﻮز وﻳﻤﻜﻨﻚ اﻻﺧﺘﻴﺎر ﻓﻴﻤﺎ ﺑﻴﻨﻬﻤﺎ ﻣﻦ اﻋﻠﻰ اﻟﻨﺎﻓﺬة . ﻫﺬا إذا ﻛﻨﺖ‬ ‫ﻣﻬﺘﻤﺎ ﺑﺒﻌﺾ اﻟﺘﻔﺎﺻﻴﻞ.‬ ‫ً‬‫122‬
  • ‫اﻟﺘﺠﻤﻴﻌﺎت ‪Collections‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺤﺎدي ﻋﺸﺮ‬ ‫راﺑﻂ‬ ‫‪http://vb4arab.com/vb/uploaded/3/21207604046.rar‬‬ ‫أو ﻳﻤﻜﻨﻚ اﻹﻃﻼع ﻋﻠﻰ ﻧﺎﺗﺞ ﻋﻤﻠﻴﺔ اﻟﺘﺤﻮﻳﻞ ﻣﺒﺎﺷﺮة ﻣﻦ ﻫﺬا اﻟﻤﻮﻗﻊ :‬ ‫راﺑﻂ‬ ‫‪http://scriptasylum.com/tutorials/infix_postfix/infix_postfix.html‬‬ ‫ﻣﺰﻳﺪ ﻣﻦ اﻟﺘﻔﺎﺻﻴﻞ ﺗﺠﺪﻫﺎ ﻓﻲ ﻣﻮﻗﻊ ‪ MSDN‬ﻫﻨﺎ:‬ ‫راﺑﻂ‬ ‫‪http://msdn2.microsoft.com/en-us/library/aa289149(VS.71).aspx‬‬‫ﻛﻞ ﻣﺎ ﺳﺒﻖ ﻓﻲ ﻫﺬا اﻟﺪرس ﻳﻨﻄﺒﻖ ﺗﺤﺖ ﻋﻠﻢ  ‪ ، Data Structure‬ﻳﻤﻜﻨﻚ اﻻﻧﻄﻼق ﻣﻦ ﻫﺬه اﻟﻨﻘﻄﺔ‬‫إذا ﻛﻨﺖ ﺗﺮﻏﺐ ﻓﻲ ﻣﻌﺮﻓﺔ اﻟﻜﺜﻴﺮ ﻋﻦ ﻫﺬا اﻟﻌﺎﻟﻢ اﻟﺬي ﻳﺘﺪاﺧﻞ ﻣﻌﻚ ﻛﺜﻴﺮًا ﻓﻲ ﻋﺎﻟﻤﻚ ، ﺳﻴﻔﻴﺪك‬ ‫ان ﺗﻜﻮن ﻣﻄﻠﻌﺎ ﻋﻠﻰ اﺳﺎﺳﻴﺎﺗﻪ اﺿﺎﻓﺔ ﻟﻌﻠﻢ ال ‪.Algorithms‬‬ ‫ً‬‫اﻳﻀﺎ ﻫﻨﺎك ﻣﺎ ﻳﻌﺮف ﺑﺎﺳﻢ ‪ System.Collections.Specialized‬وﻳﺤﺘﻮي ﻋﻠﻰ ﻓﺌﺎت‬ ‫ً‬ ‫اﺧﺮى اﻛﺜﺮ ﺗﺨﺼﺼﺎً ﻣﺸﺘﻘﺔ ﻣﻦ اﻟﻔﺌﺎت اﻟﺴﺎﺑﻘﺔ.‬‫222‬
  • 223
  • ‫اﻟﺒﺎب‬ ‫21‬ ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬‫ ‪.net‬‬‫422‬
  • 225
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬‫ﻓﻲ ﻫﺬا اﻟﻔﺼﻞ ﺳﻮف ﻧﺘﻌﺮف ﻋﻠﻰ ﺑﻌﺾ ﻋﻨﺎﺻﺮ اﻟﺒﺮﻣﺠﺔ ﻓﻲ ‪ .net‬ﻣﻨﻬﺎ اﻟﺠﺪﻳﺪ اﻟﺬي ﻇﻬﺮ ﻷول ﻣﺮة‬‫ﻣﻊ 8002 ‪ .net‬ﻓﻘﻂ وﻣﻨﻬﺎ ﻋﻨﺎﺻﺮ ﻣﻮﺟﻮدة ﻗﺒﻼ وﻟﻜﻨﻬﺎ ﻣﺘﻘﺪﻣﺔ ﻧﻮﻋﺎ ﻣﺎ ، ﻟﺬا ﻗﻤﻨﺎ ﺑﺘﺠﻤﻴﻌﻬﺎ ﺳﻮﻳﺔ‬ ‫ً‬ ‫ً‬ ‫ﻓﻲ ﻫﺬا اﻟﺒﺎب .‬ ‫1. ال ‪Generics‬‬ ‫ﻧﻮاﺻﻞ ﻓﻲ ﻫﺬا اﻟﺪرس ﻣﻊ واﺣﺪة ﻣﻦ اﻟﺘﻄﻮرات اﻟﺠﺪﻳﺪة ﻣﻊ 0.2 ‪ ،.net Framework‬ﻫﻲ ال‬ ‫‪ generics‬ﻟﺘﻌﻄﻲ ﺑﻌﺪًا ﺟﺪﻳﺪًا ﻟﻤﻔﻬﻮم ال ‪ ،overloading‬ﻟﻨﻔﺘﺮض ﻣﺜﺎﻻ ﻣﺎ ﻟﻠﻄﺒﺎﻋﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫ً‬ ‫#‪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.NET‬‬ ‫ﻛﻮد‬ ‫‪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‬‬‫اﻟﻜﻮد ﻛﻤﺎ ﻫﻮ واﺿﺢ ﻗﺎم ﺑﻌﻤﻞ ﺛﻼث دوال ﺑﻨﻔﺲ اﻻﺳﻢ ﻻﺳﺘﻘﺒﺎل ﺑﺎرﻣﻴﺘﺮات ﻣﺨﺘﻠﻔﺔ ، وﻫﻜﺬا ﺗﺠﺪ‬‫اﻧﻚ ﺗﺴﺘﻄﻴﻊ ﻓﻲ اﻟﻜﻮد اﺳﺘﺪﻋﺎء اﻟﺪاﻟﺔ اﻟﻄﺒﺎﻋﺔ ﻟﻼرﻗﺎم او ﻟﻞ ‪ longs‬او ﻟﻠﻨﺼﻮص ، ﺟﺮب ﻋﺪة‬ ‫ﻋﻤﻠﻴﺎت ﻟﻄﺒﺎﻋﺔ اﻧﻮاع ﻣﺨﺘﻠﻔﺔ وﺷﺎﻫﺪ ﺟﻤﻠﺔ اﻟﻄﺒﺎﻋﺔ ، ﻋﻠﻰ ﺳﺒﻴﻞ اﻟﻤﺜﺎل اﻷواﻣﺮ اﻟﺘﺎﻟﻴﺔ:‬‫622‬
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬‫#‪C‬‬ ‫ﻛﻮد‬‫;)"‪print("Ahmed‬‬‫;)21(‪print‬‬‫;)0000000000001(‪print‬‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫)"‪Print("Ahmed‬‬‫)21(‪Print‬‬‫)0000000000001(‪Print‬‬ ‫ﺳﻴﻜﻮن ﻧﺎﺗﺞ اﻟﻄﺒﺎﻋﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫اﻟﺼﻮرة 21. 1. ﻧﺎﺗﺞ ﺗﻨﻔﻴﺬ اﻟﻌﻤﻠﻴﺎت‬‫ال ‪ Generic‬ﺳﺘﻐﻴﺮ اﻟﻤﻔﻬﻮم ﻧﻮﻋﺎ ، ﺣﻴﺚ ان ﺑﺎﻣﻜﺎﻧﻚ اﻵن ﺗﻌﺮﻳﻒ داﻟﺔ ﻻ ﺗﺴﺘﻘﺒﻞ ﻧﻮﻋﺎ ﻣﻌﻴﻨﺎ ﻣﻦ‬ ‫ً‬ ‫ً‬ ‫ً‬‫اﻟﻤﺘﻐﻴﺮات ، ﺑﻞ ﻫﻲ ﺗﺴﺘﻘﺒﻞ >‪ <T‬وﺗﺘﻌﺎﻣﻞ ﻣﻌﻪ ﻋﻠﻰ ﻫﺬا اﻻﺳﺎس ، ﻟﺬا ﻗﺪ ﻧﺴﺘﻄﻴﻊ اﻓﺘﺮاض اﻟﺪوال‬ ‫اﻟﺜﻼث اﻟﺴﺎﺑﻘﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬‫#‪C‬‬ ‫ﻛﻮد‬‫)‪public static void print<T>(T x‬‬‫{‬ ‫;)‪Console.WriteLine("Print As {0}: {1}", typeof(T), x‬‬‫}‬‫722‬
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)‪Public Shared Sub print(Of T)(ByVal x As T‬‬ ‫)‪Console.WriteLine("Print As {0}: {1}", GetType(T), x‬‬ ‫‪End Sub‬‬ ‫واﻵن ﻓﻲ ﺣﺎﻟﺔ ﺗﻄﺒﻴﻘﻨﺎ ﻟﻨﻔﺲ اﻟﻤﺜﺎل اﻟﺴﺎﺑﻖ ، ﺳﻮف ﻳﻜﻮن اﻟﻨﺎﺗﺞ ﻛﺎﻟﺘﺎﻟﻲ:‬ ‫اﻟﺼﻮرة 21. 2. ﻧﺎﺗﺞ ﺗﻨﻔﻴﺬ اﻟﻌﻤﻠﻴﺎت‬ ‫1. 1. ‪Structure and Class Generics‬‬ ‫ﻓﻲ اﻟﺪرس اﻟﺴﺎﺑﻖ ﺗﻌﺮﻓﻨﺎ ﻋﻠﻰ ال ‪ methods‬اﻟﺘﻲ ﺗﻄﺒﻖ ال ‪ ،Generics‬اﻳﻀﺎ ال ‪ Classes‬وال‬ ‫ً‬‫‪ Structs‬ﻳﻤﻜﻨﻬﺎ ﺗﻄﺒﻴﻖ ﻫﺬا اﻟﻤﻔﻬﻮم ﻟﺒﻌﺾ اﻟﺒﻴﺎﻧﺎت ﺑﻬﺎ ، ﺳﻨﻔﺘﺮض ﻣﺜﺎل ال ‪ class‬وﻣﺎ ﻳﻨﻄﺒﻖ ﻋﻠﻰ‬ ‫ال ‪ class‬ﻳﻨﻄﺒﻖ ﻋﻠﻰ ال ‪.struct‬‬‫ﻟﻨﻔﺘﺮض ﻓﺌﺔ ﺗﺤﺘﻮي ﻋﻠﻰ اﻟﺒﻀﺎﺋﻊ ، وﺣﻴﺚ ان ﻟﺪﻳﻨﺎ ﻧﻮﻋﻴﻦ ﻣﻦ اﻟﺒﻀﺎﺋﻊ ﻳﺤﺘﻮي اﻟﻨﻮع اﻷول‬‫ﻋﻠﻰ اﻻﺳﻢ وﻫﻲ ﺗﻠﻚ اﻟﺒﻀﺎﺋﻊ اﻟﺘﻲ ﻳﺘﻢ ﺗﺼﻨﻴﻌﻬﺎ ﻓﻲ اﻟﻤﺤﻞ ) اﻧﻮع ﻣﻦ اﻟﺠﺒﻦ او اﻟﺰﺑﺎدي ( وﺑﻀﺎﺋﻊ‬‫822‬
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬‫أﺧﺮى ﺟﺎﻫﺰة ﺗﺤﺘﻮي ﻋﻠﻰ اﻟﺒﺎرﻛﻮد ، ﺑﻬﺬه اﻟﻄﺮﻳﻘﺔ ﻧﺴﻨﺘﺞ ان ﺣﻘﻞ ‪ Identify‬ﻗﺪ ﻳﺤﺘﻮي ﻋﻠﻰ‬ ‫اﺳﻢ ﻓﻲ ﺑﻌﺾ اﻟﺒﻀﺎﺋﻊ ورﻗﻢ ﻓﻲ ﺑﻀﺎﺋﻊ أﺧﺮى.‬‫اﻟﺤﻞ اﻟﺘﻘﻠﻴﺪي ﻛﺎن ﻟﻴﻌﺘﺒﺮ وﺟﻮد ﻓﺌﺘﻴﻦ ﻣﻨﻔﺼﻠﻴﺘﻦ، أو ﻓﻲ أﺣﺴﻦ اﻟﻈﺮوف وﺿﻊ ﻗﻴﻤﺔ‬‫ﻣﻨﻄﻘﻴﺔ ﻟﺘﺤﺪﻳﺪ اذا ﻣﺎ ﻛﻨﺖ ﺳﺎﺳﺘﺨﺪم ﺣﻘﻞ ال ‪ name‬ام ﺣﻘﻞ ال ‪ ،number‬ﻟﻜﻦ ﻣﻊ ال‬ ‫‪ Generics‬ﺗﻢ ﺗﻐﻴﻴﺮ ﻫﺬا اﻟﻤﻔﻬﻮم ، ﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﺳﺘﺼﺒﺢ اﻟﻔﺌﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫>‪public class product<T‬‬ ‫{‬ ‫;‪private T Identify‬‬ ‫)‪public product(T val‬‬ ‫{‬ ‫;‪Identify = val‬‬ ‫;)‪Console.WriteLine(Identify‬‬ ‫}‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)‪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‬‬ ‫واﻵن ﻳﻤﻜﻨﻨﻲ ﺗﻌﺮﻳﻒ ﻛﺎﺋﻦ ﻣﻦ اﻟﻨﻮع اﻷول ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)1001(>‪product<int> prd = new product<int‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)1001()‪Dim prd As New product(Of Integer‬‬ ‫أو ﻣﻦ اﻟﻨﻮع اﻟﺜﺎﻧﻲ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)"‪product<string> prd2 = new product<string>("Some Product‬‬‫922‬
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ VB.NET ‫ﻛﻮد‬ Dim prd2 As New product(Of String)("Some Product") Generic Collection .2 .1 ‫، اﺻﺒﺢ اﻟﺪور اﻵن ﻋﻠﻰ ﻋﻤﻞ‬Generic Class ‫ﻛﻤﺎ ﺗﻌﺮﻓﻨﺎ ﻓﻲ اﻟﺪرس اﻟﺴﺎﺑﻖ ان ﺑﺎﻣﻜﺎﻧﻨﺎ ﻋﻤﻞ‬ ‫، ﺳﻨﻘﻮم ﺑﻌﻤﻞ ﻓﺌﺔ ﺗﺴﺘﻘﺒﻞ ﻋﺪة ﻓﺌﺎت وﻳﻘﻮم ﺑﻌﺪة ﻋﻤﻠﻴﺎت ﻣﺜﻞ‬Generic  Collection :‫ ﻣﺎ‬Collection ‫، ﻛﻤﺎ ﺗﻌﻠﻤﻨﺎ ﺳﺎﺑﻘﺎ ، ﻫﺬا ﻣﺜﺎل ﻋﻠﻰ‬Add,Delete ... etc ً 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(it); } public void ClearCars() { myList.Clear(); } } VB.NET ‫ﻛﻮد‬ 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(it) End Sub Public Sub ClearCars() myList.Clear() End Sub End Class230
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬‫ﻃﺒﻌﺎ ﺑﺎﻣﻜﺎﻧﻚ اﺿﺎﻓﺔ اﻟﻜﺜﻴﺮ ﻣﻦ اﻟﺨﺼﺎﺋﺺ ورﺑﻤﺎ ﺑﻌﺾ اﻟﺨﺼﺎﺋﺺ اﻟﻐﻴﺮ ﻣﺘﻮﻓﺮة اﺻﻼ ﻟﻠﺒﺤﺚ‬ ً ً‫ ﺣﻴﺚ ﻳﻤﻜﻦ ﻓﻲ ﻣﺮاﺣﻞ ﻻﺣﻘﺔ اﻻﻋﺘﻤﺎد ﻋﻠﻴﻪ ﺑﺪل‬Generic Collection  ‫وﺧﻼﻓﻪ ، ﻫﺬا ﻣﺎ ﻳﺴﻤﻰ ﺑﺎل‬‫ إﻟﻰ ﻏﻴﺮ ذﻟﻚ ﻣﻦ‬Employee .... ‫ او‬Car ‫ اﻟﻌﺎدﻳﺔ ﺣﻴﺚ ﻳﻤﻜﻦ ان ﻳﺴﺘﻘﺒﻞ‬Colelctions ‫ال‬ : ‫اﻟﺨﻴﺎرات ، ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ‬ ً C# ‫ﻛﻮد‬ Identify = val; Console.WriteLine(Identify); MyCollection<Car> myCars = new MyCollection<Car>(); myCars.AddItem(temp); MyCollection<Employee> myCars = new MyCollection<Employee>(); myCars.AddItem(tempEmployee); VB.NET ‫ﻛﻮد‬ Dim myCars As New MyCollection(Of Car)() myCars.AddItem(temp) Dim myCars As New MyCollection(Of Employee)() myCars.AddItem(tempEmployee) :‫أو ﺣﺘﻰ ارﻗﺎم‬ C# ‫ﻛﻮد‬ MyCollection<int> myCars = new MyCollection<int>(); myCars.AddItem(12); VB.NET ‫ﻛﻮد‬ Dim myCars As New MyCollection(Of Integer)() myCars.AddItem(12)‫ اﻟﺨﺎص ﺑﻨﺎ ﻳﺤﺘﻮي ﻋﻠﻰ ﺧﺼﺎﺋﺺ ﻣﺜﻞ‬Generic Collection  ‫ﻫﻨﺎ ﻇﻬﺮت ﻟﻨﺎ ﻣﺸﻜﻠﺔ ﺗﺘﻌﻠﻖ ﺑﻜﻮن ال‬‫. ﻟﻌﺮﺿﻬﺎ ، وﻫﺬا ﻣﺎ ﻻ ﻳﺘﻮﻓﺮ ﻣﺜﻼ ﻟﻜﻞ اﻟﻔﺌﺎت او ﻟﻼرﻗﺎم ﻣﺜﻼ ، ﻣﻦ ﻫﻨﺎ ﺟﺎءت ﻟﻨﺎ اﻟﻜﻠﻤﺔ‬name ً ً .‫ واﻟﺘﻲ ﺳﻨﺘﺤﺪث ﻋﻨﻬﺎ ﻓﻲ اﻟﺪرس اﻟﻘﺎدم‬where ‫اﻟﻤﺤﺠﻮزة‬ where T ‫1. 3. اﺳﺘﺨﺪام‬‫ ان ﻻ ﻧﻘﺒﻞ ﺳﻮى ﺑﻌﺾ اﻟﻔﺌﺎت ، ﻳﻤﻜﻨﻨﺎ‬Generic Collection ‫ﻳﺘﻴﺢ ﻟﻨﺎ ﻫﺬا اﻟﺸﺮط ﻓﻲ ﻋﻤﻞ ال‬ :‫وﺿﻊ اﻟﺸﺮوط ﺑﺄﺣﺪ اﻟﻄﺮق اﻟﺘﺎﻟﻴﺔ‬231
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫اﻟﻤﻌﻨﻰ‬ ‫اﻟﺸﺮط‬ ‫ ﺑﺤﻴﺚ ﻻ ﻳﻘﺒﻞ ﺳﻮى ﻣﺘﻐﻴﺮات ﻣﻦ اﻟﻨﻮع‬where T : struct ValueType RefernceType ‫ ﻻ ﻳﻘﺒﻞ ﺳﻮى ﻣﻦ اﻟﻨﻮع‬where T : class Constructor ‫ ﻻ ﺑﺪ ان ﻳﺤﺘﻮي ﻋﻠﻰ‬where T :new() ‫ ﻣﻌﻴﻦ او ﻳﻄﺒﻖ‬class ‫ ﻻ ﺑﺪ ان ﻳﻜﻮن ﻣﺸﺘﻖ ﻣﻦ‬where T : ClassName .‫ ﻣﻌﻴﻦ‬interface where T : IInterfaceName Generics ‫اﻟﺠﺪول 21. 1. اﺳﺘﺨﺪام اﻟﺸﺮوط ﻣﻊ ال‬ :‫ﺑﻬﺬه اﻟﻄﺮﻳﻘﺔ ﻳﻤﻜﻨﻨﺎ دﻣﺞ ﻋﺪة ﺷﺮوط ﻣﻊ ﺑﻌﻀﻬﺎ ، ﻟﻨﺮى اﻟﻤﺜﺎل اﻟﺘﺎﻟﻲ ﺳﻮﻳﺔ‬ C# ‫ﻛﻮد‬ public class Example <T> where T : class, IComparable, new() VB.NET ‫ﻛﻮد‬ Public Class Example(Of T As {Class, IComparable, New}) ‫ وﺗﺤﺘﻮي ﻋﻠﻰ‬IComparable ‫ ، ﺗﻄﺒﻖ اﻟﻮاﺟﻬﺔ‬reference ‫ ﻻ ﺑﺪ ان ﺗﻜﻮن‬T ‫ﻫﺬا ﻳﻌﻨﻲ ان‬ .Constructor :‫اﻳﻀﺎ اﻟﻤﺜﺎل اﻟﺘﺎﻟﻲ‬ ً C# ‫ﻛﻮد‬ public class Example<K, T> where K : class, new() where T : IComparable<T> VB.NET ‫ﻛﻮد‬ Public Class Example(Of K As {Class, New}, T As IComparable(Of T)) ‫ ﻻ ﺑﺪ ان ﺗﻄﺒﻖ اﻟﻮاﺟﻬﺔ‬T ‫ ﻓﻴﻤﺎ‬constructor ‫ وﻟﻬﺎ‬Reference ‫ ﻻ ﺑﺪ ان ﺗﻜﻮن‬K ‫ﻫﺬا ﻳﻌﻨﻲ ان‬ . IComparable .‫ ﺑﺪﻻ ﻣﻦ ﺟﻌﻠﻬﺎ ﻣﻔﺘﻮﺣﺔ ﻟﻠﺠﻤﻴﻊ‬T ‫واﻵن ، اﺻﺒﺢ ﺑﺎﻣﻜﺎﻧﻚ اﻟﺘﺤﻜﻢ ﺑﻌﺾ اﻟﺸﻲء ﻓﻲ‬ ً232
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ Delegates ‫2. ال‬ ‫، ﻣﻮﻋﺪﻧﺎ ﻫﺬه اﻟﻤﺮة ﻣﻊ‬advanced  .net  programming  ‫ﻧﻮاﺻﻞ رﺣﻠﺘﻨﺎ ﻣﻊ ال‬ .Delegates‫ال‬ .‫ﻗﺒﻞ ان ﻧﺸﺮح ﺗﺮﻛﻴﺒﻬﺎ وﻛﻴﻔﻴﺔ اﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ، ﺳﻨﻘﻮم ﺑﺸﺮح ﻟﻤﺎذا ﻧﻘﻮم ﺑﺎﺳﺘﺨﺪاﻣﻬﺎ‬ ‫ اﻳﻀﺎ ﺧﺎﺻﺔ ﺑﻌﻤﻠﻴﺎت اﻟﺘﺤﻮﻳﻞ ، وﻫﻲ ﻋﻠﻰ اﻟﺸﻜﻞ‬int ‫ وﺗﻌﻴﺪ‬int ‫ﻟﻨﻔﺘﺮض ﻋﺪة دوال ﺗﺴﺘﻘﺒﻞ‬ ً :‫اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ public int ConvertEGToD(int EG) { return EG * 5.45; } public int ConvertRSToD(int RS) { 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; } 233
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ VB.NET ‫ﻛﻮد‬ 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‫ﻛﻤﺎ ﻻﺣﻈﺖ ﻓﻌﻼً، ﻓﻬﻲ ﻋﺪة دوال ﺗﺴﺘﺨﺪم ﻟﻠﺘﺤﻮﻳﻼت اﻟﻤﺨﺘﻠﻔﺔ ﺑﻴﻦ ﺛﻼث ﻋﻤﻼت، اﻟﺠﻨﻴﺔ اﻟﻤﺼﺮي‬ .‫واﻟﺮﻳﺎل اﻟﺴﻌﻮدي واﻟﺪوﻻر اﻷﻣﺮﻳﻜﻲ‬‫ﻃﺒﻌﺎ ﻳﻤﻜﻨﻨﺎ ﻋﻤﻠﻬﻢ ﻓﻲ داﻟﺔ واﺣﺪة وارﺳﺎل ﻣﺘﻐﻴﺮ ﻳﻤﺜﻞ رﻗﻢ اﻟﺘﺤﻮﻳﻞ ، ﻟﻜﻨﻨﺎ ﻟﻦ ﻧﺴﺘﻄﻴﻊ ﻋﻤﻞ ذﻟﻚ‬ ً .‫ﻣﺜﻼ ﻣﻊ دوال اﻛﺒﺮ وﻣﺨﺘﻠﻔﺔ ، ﻟﺬا ﻓﻬﺬا اﻟﻤﺜﺎل ﻟﻠﺘﻮﺿﻴﺢ‬ ً switch ‫ او‬if ‫اﻵن ﻓﻲ ﺑﺮﻧﺎﻣﺠﻨﺎ ﺳﻨﻘﺮأ اﻟﺒﻴﺎﻧﺎت ﻣﻦ اﻟﻤﺴﺘﺨﺪم ، وﻣﻦ ﺛﻢ ﻧﺴﺘﺨﺪم ﺟﻤﻠﺔ ﺷﺮط‬ :‫ﻟﺘﺤﺪﻳﺪ اي داﻟﺔ ﺳﻨﻘﻮم ﺑﺎرﺳﺎل اﻟﺒﻴﺎﻧﺎت إﻟﻴﻬﺎ ، ﻫﺬا ﻣﺨﺘﺼﺮ ﻟﻠﻜﻮد اﻟﻤﻜﺘﻮب‬ C# ‫ﻛﻮد‬ if (Operation == 0) result = ConvertDToEG(userInput); else if(Operation == 1) result = ConvertRSToD(userInput); VB.NET ‫ﻛﻮد‬ If Operation = 0 Then result = ConvertDToEG(userInput) ElseIf Operation = 1 Then result = ConvertRSToD(userInput) End If‫وﻟﻜﻦ ﻟﻨﻔﺘﺮض اﻧﻨﺎ ﻓﻘﻂ اﻵن ﻧﻮد ﻣﻌﺮﻓﺔ ﻧﻮع اﻟﻌﻤﻠﻴﺔ دون ﺗﻨﻔﻴﺬﻫﺎ وﻋﺮﺿﻬﺎ ﻟﻠﻤﺴﺘﺨﺪم ﺣﻴﺚ‬‫ﺳﻨﻨﻔﺬﻫﺎ ﻻﺣﻘﺎ ، ﻫﺬا ﻳﻌﻨﻲ اﻧﻨﺎ ﺳﻨﻘﻮم ﺑﺬات اﻻﺧﺘﺒﺎر ﻣﺮﺗﻴﻦ ، ﻣﺮة ﻟﻠﻌﺮض ﻋﻠﻰ اﻟﻤﺴﺘﺨﺪم وﻣﺮة‬ ً234
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬،‫ﻟﺘﻨﻔﻴﺬ اﻟﻌﻤﻠﻴﺔ ، اﻳﻀﺎ أﻻ ﺗﺘﻔﻖ ﻣﻌﻲ ﻓﻲ اﻧﻚ ﻗﺪ ﺗﺤﺘﺎج ﻟﺘﻨﻔﻴﺬ اﻟﻌﻤﻠﻴﺔ ﻣﺮﺗﻴﻦ ﻓﻲ ﻣﻜﺎﻧﻴﻦ ﻣﺨﺘﻠﻔﻴﻦ‬ ً .‫ إذا ﺳﺘﻀﻄﺮ ﻟﻌﻤﻞ ﺟﻤﻞ اﻟﺸﺮط ﻣﺮة أﺧﺮى‬Operation ‫وﻣﺎ دﻣﺖ ﻻ ﺗﺤﺘﻔﻆ ﺳﻮى ﺑﺮﻗﻢ ال‬ .Delegates ‫ﻣﻦ أﺟﻞ ﻫﺬا وﺟﺪت ال‬ Delegates ‫2. 1. ﺗﻌﺮﻳﻒ ال‬‫ ﻟﻤﺠﻤﻮﻋﺔ دوال ، اول ﻣﺎ ﻧﺤﺘﺎج إﻟﻴﻪ ان ﺗﻜﻮن ﻫﺬه اﻟﺪوال ﻣﻦ ﻧﻔﺲ ﻋﺪد‬Delegates ‫ﻟﻮ اردﻧﺎ ﺗﻌﺮﻳﻒ‬‫ اﻟﺨﺎص ﺑﺪواﻟﻨﺎ‬Delegate ‫ ، ﻟﺬا ﺳﻴﻜﻮن ال‬output ‫ وال‬input ‫اﻟﺒﺎرﻣﻴﺘﺮات . اﻳﻀﺎ ﻟﻬﺎ ﻧﻔﺲ ال‬ ً :‫ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ public delegate int myDelegate(int value); VB.NET ‫ﻛﻮد‬ Public Delegate Function myDelegate(ByVal value As Integer) As Integer‫واﻵن ﻛﻞ ﻣﺎ ﻋﻠﻲ ﻓﻲ ﺟﻤﻠﻲ اﻟﺸﺮﻃﻴﺔ ان اﺣﺪد ﻟﻬﺬا اﻟﺘﻔﻮﻳﺾ - إن ﺻﺤﺖ اﻟﺘﺮﺟﻤﺔ - اﻟﺪاﻟﺔ‬ ‫اﻟﻤﺴﺆول ﻋﻨﻬﺎ ، ﻟﺬا ﺳﺘﻜﻮن ﺷﺮوﻃﻨﺎ اﻟﻤﺨﺘﺼﺮة ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ 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.NET ‫ﻛﻮد‬ 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 If235
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬‫اﻳﻀﺎ ﺑﺎﻣﻜﺎﻧﻚ ﺗﺄﺧﻴﺮ اﻟﺸﺮط اﻷﺧﻴﺮ اﻟﺬي ﻳﻘﻮم ﺑﺘﻨﻔﻴﺬ ال ‪ Delegate‬ﻟﻠﻨﻬﺎﻳﺔ ، او ﺗﻜﺮار اﺳﺘﺨﺪاﻣﻬﺎ‬‫ﻣﺮة أﺧﺮى ، ﺣﻴﺚ ان ال ‪ aDelegate‬ﻗﺪ اﺻﺒﺤﺖ ﺗﻌﺮف اي داﻟﺔ ﺗﺨﺘﺺ ﺑﺘﻨﻔﻴﺬ ﻫﺬه اﻟﻌﻤﻠﻴﺔ اﻵن ،‬ ‫ﻟﺬا ﻳﻤﻜﻨﻚ ﻛﺘﺎﺑﺔ اﻟﻜﻮد ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ :‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)0 == ‪if (Operation‬‬ ‫{‬ ‫;)‪myDelegate aDelegate = new myDelegate(ConvertDToEG‬‬ ‫}‬ ‫)1 == ‪else if (Operation‬‬ ‫{‬ ‫;)‪myDelegate aDelegate = new myDelegate(ConvertRSToD‬‬ ‫}‬ ‫هﻨﺎ اﻷواﻣﺮ ﺑﻌﺾ ﻧﻔﺬ //‬ ‫;)‪result = aDelegate(userInput‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪If Operation = 0 Then‬‬ ‫)‪Dim aDelegate As New myDelegate(ConvertDToEG‬‬ ‫‪ElseIf Operation = 1 Then‬‬ ‫)‪Dim aDelegate As New myDelegate(ConvertRSToD‬‬ ‫‪End If‬‬ ‫هﻨﺎ اﻷواﻣﺮ ﺑﻌﺾ ﻧﻔﺬ‬ ‫)‪result = aDelegate(userInput‬‬‫وﻫﻜﺬا ، ﻳﻤﻜﻨﻚ ﺗﺄﺧﻴﺮ اﺳﺘﺪﻋﺎء اﻟﺪاﻟﺔ ﺣﺘﻰ ﺗﻨﺘﻬﻲ ﻣﻦ ﺗﻨﻔﻴﺬ أي أواﻣﺮ ﻣﺮﺗﺒﻄﺔ دون ان ﺗﻘﻠﻖ ﻣﻦ‬ ‫أﻧﻚ ﺳﺘﻌﻴﺪ اﻟﺘﺄﻛﺪ ﻣﺮة أﺧﺮى ، ﻫﺬه واﺣﺪة .‬‫واﻟﺜﺎﻧﻴﺔ ﻳﻤﻜﻨﻚ ﻋﻤﻞ اﻟﺘﺄﻛﺪ ﻓﻲ داﻟﺔ ﻣﻨﻔﺼﻠﺔ واﻋﺎدة ال ‪ Delegate‬ﺟﺎﻫﺰ ﻟﻠﺘﻨﻔﻴﺬ ، ﻫﺬا ﻳﻔﻴﺪ‬ ‫ﻛﺜﻴﺮًا ﻓﻲ ﺣﺎﻟﺔ اﻟﻌﻤﻞ ﻋﻠﻰ ﺷﻜﻞ ﻣﺠﻤﻮﻋﺎت .‬ ‫2. 2. اﻷﺣﺪاث ‪Events‬‬‫ﻟﻮ ﺟﺮﺑﻨﺎ اﻵن ان ﻧﻘﻮم ﺑﻌﻤﻞ ﺣﺪث ﻣﻌﻴﻦ ﻷي ﻣﻮﻇﻒ ﻋﻨﺪﻧﺎ )ﻣﺮض ... اﻟﺦ أو ﻻي ﺳﻴﺎرة‬‫)ﺣﺎدث اﺻﺪام ... اﻟﺦ( ﻛﻨﺎ ﻧﻘﻮم ﺑﺬﻟﻚ ﺳﺎﺑﻘﺎ ﻋﻦ ﻃﺮﻳﻖ ‪ Delegates‬ﺑﺎﺳﻢ ‪ Event‬ﻣﺜﻼ ، وﻧﻘﻮم‬ ‫ً‬ ‫ً‬‫632‬
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬‫ﺑﺘﻤﺮﻳﺮ اﻟﺪاﻟﺔ اﻟﺨﺎﺻﺔ ﺑﺎﻟﺤﺪث ﻟﻪ ، وإذا ﻛﻨﺖ ﻗﺪ ﺗﻮﺳﻌﺖ ﻓﻲ ال ‪ Delegates‬ﻓﺄﻧﺖ ﻗﺎدر ﻋﻠﻰ ﻣﻌﺮﻓﺔ‬ ‫اﻧﻚ ﺗﺴﺘﻄﻴﻊ ﻋﻤﻞ ‪ List‬ﺑﺎﻻﺣﺪاث اﻟﺘﻲ ﺗﻢ ﺗﻨﻔﻴﺬﻫﺎ ﻋﻠﻰ ﻫﺬا ال ‪.Delegate‬‬ ‫اﻵن ﺳﻨﺘﻌﻠﻢ اﻷﻣﺮ ﺑﻄﺮﻳﻘﺔ ﺟﺪﻳﺪة ﻋﻦ ﻃﺮﻳﻖ اﻟﻜﻠﻤﺔ اﻟﻤﺤﺠﻮزة ‪... Event‬‬‫ﻟﻌﻤﻞ‬ ‫ﺳﻨﻌﺮف ﻓﻲ اﻟﺒﺪاﻳﺔ ‪ Delegate‬ﻣﺴﺆول ﻋﻦ ﻛﺎﻓﺔ اﻷﺣﺪاث اﻟﺘﻲ ﺗﺤﺼﻞ ﻟﻠﺴﻴﺎرة ﻣﺜﻼ‬ ‫ً‬ ‫‪ Delegate‬ﻳﺴﺘﻘﺒﻞ ﻧﺺ اﻟﺮﺳﺎﻟﺔ اﻟﻤﻄﻠﻮﺑﺔ :‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)‪public delegate void CarEventHandler(string msg‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)‪Public Delegate Sub CarEventHandler(ByVal msg As String‬‬ ‫واﻵن ﺳﻨﻘﻮم ﺑﺘﻌﺮﻳﻒ ﺑﻌﺾ اﻻﺣﺪاث:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;‪public event CarEventHandler Exploded‬‬ ‫;‪public event CarEventHandler Damaged‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Public Event Exploded As CarEventHandler‬‬ ‫‪Public Event Damaged As CarEventHandler‬‬ ‫اﻵن ﻳﻤﻜﻨﻚ ﺑﺒﺴﺎﻃﺔ ﻣﻦ ﺧﻼل اﻟﻜﻮد ﺗﻨﻔﻴﺬ اي ﺣﺪث ﻓﻴﻬﻢ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)"‪Damaged("my car‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)"‪Damaged("my car‬‬‫وأﻳﻀﺎ ﻳﻤﻜﻨﻚ اﺧﺘﺒﺎر اي ‪ event == null‬ام ﻻ ﻟﻤﻌﺮﻓﺔ إذا ﻛﺎن ﺗﻢ اﻃﻼﻗﻪ ﻗﺒﻞ ذﻟﻚ أم ﻻ،‬ ‫ً‬ ‫ﻟﻤﻌﺮﻓﺔ ﻫﻞ اﻟﺴﻴﺎرة ﻣﺜﻼ ﺗﻢ ﺗﺪﻣﻴﺮﻫﺎ أم ﻻ.‬ ‫ً‬ ‫آﺧﺮ ﻧﻘﻄﺔ ، ﻻﺿﺎﻓﺔ داﻟﺔ اﻟﺤﺪث إﻟﻰ اﻟﻜﺎﺋﻦ :‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)‪Car.EngineHandler d = new Car.CarEventHandler(CarExploded‬‬‫732‬
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)‪Dim d As Car.EngineHandler = New Car.CarEventHandler(CarExploded‬‬‫ﺣﻴﺚ ﻳﺘﻢ ﺗﻌﺮﻳﻒ اﻟﺪاﻟﺔ ‪ CarExploded‬ﻟﺘﻨﻔﻴﺬ اﻟﻤﻬﻤﺔ اﻟﻤﻄﻠﻮﺑﺔ وﻫﻲ اﻇﻬﺎر رﺳﺎﻟﺔ ﺑﻨﺎء ﻋﻠﻰ‬ ‫اﻟﻨﺺ اﻟﻤﺮﺳﻞ واﻟﺬي ﺗﻢ ارﺳﺎﻟﻪ ﻓﻲ اﻟﺤﺪث ‪ ، Damaged‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ :‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪public void CarExploded(string msg‬‬ ‫{‬ ‫;)‪Console.WriteLine(msg‬‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)‪Public Sub CarExploded(ByVal msg As String‬‬ ‫)‪Console.WriteLine(msg‬‬ ‫‪End Sub‬‬ ‫3. ال ‪ Anonymous Methods‬ﻓﻘﻂ ﻓﻲ #‪  C‬‬‫إذا ﻛﻨﺖ ﻗﺪ اﺳﺘﻮﻋﺒﺖ اﻟﺪرس اﻟﺴﺎﺑﻖ ﻋﻦ ال ‪ Delegates‬ﻓﺄﻧﺖ ﺗﺪرك أن ﺑﺎﻣﻜﺎﻧﻚ اﺳﺘﺪﻋﺎء‬ ‫داﻟﺔ ﺑﺎﺳﺘﺨﺪام ﻣﺘﻐﻴﺮ ﻣﻦ اﻟﻨﻮع ‪. Delegate‬‬‫وﺑﻌﺪ اﻟﺪرس اﻟﺨﺎص ب ‪ Events‬اﺻﺒﺤﺖ ﺗﺪرك ان ﺑﺎﻣﻜﺎﻧﻚ اﺿﺎﻓﺔ اﺳﻢ داﻟﺔ ﻟﻴﻤﺜﻞ اﻟﺤﺪث‬ ‫اﻟﺬي ﻗﻤﺖ ﺑﺒﺮﻣﺠﺘﻪ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)‪t.SomeEvent += new SomeDelegate(MyEventHandler‬‬‫واﻵن ﻟﻨﻔﺘﺮض اﻧﻚ ﻻ ﺗﺮﻳﺪ اﺳﺘﺪﻋﺎء اﻟﺪاﻟﺔ ﺳﻮى ﻓﻲ ﻫﺬا اﻟﻤﻜﺎن ﻓﻘﻂ ، ﻟﺬا ﺳﻴﻜﻮن ﻣﻦ اﻟﻤﻜﻠﻒ‬‫ﺗﻌﺮﻳﻒ اﻟﺪاﻟﺔ وﻣﻦ ﺛﻢ اﺳﺘﺪﻋﺎءﻫﺎ ﻓﻲ ‪ ، Delegate‬ﻫﻨﺎ ﻳﻈﻬﺮ ﻟﻨﺎ ﻣﺎ ﻳﻌﺮف ﺑﺎﺳﻢ ‪Anonymous‬‬ ‫‪ Methods‬ﺣﻴﺚ ﺑﺎﻣﻜﺎﻧﻚ ﺗﻌﺮﻳﻒ اﻟﺪاﻟﺔ وﺳﻂ اﻟﻜﻮد.‬ ‫ﻟﻨﺮى اﻟﻜﻮد اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫{‪t.SomeEvent += delegate‬‬ ‫;)"‪Console.WriteLine("Some Text‬‬ ‫}‬‫832‬
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬‫ﻧﻌﻢ ﻫﺬا ﺻﺤﻴﺢ وﻟﻜﻦ ﻓﻘﻂ ﻣﻊ  #‪ .C‬ﻛﻤﺎ ﺗﺮى اﺻﺒﺢ اﻵن ﺑﺎﻣﻜﺎﻧﻚ ﺗﻌﺮﻳﻒ اﻟﺪاﻟﺔ ﻓﻲ ﻣﻮﻗﻊ‬ ‫اﺳﺘﺨﺪاﻣﻬﺎ ﻓﻘﻂ ، ﻳﻤﻜﻦ اﻳﻀﺎ ان ﺗﻜﻮن اﻟﺪاﻟﺔ ﺗﺴﺘﻘﺒﻞ ﻋﺪة ﺑﺎرﻣﻴﺘﺮات ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪t.SomeEvent += delegate(object sender, CarEventArgs e‬‬ ‫{‬ ‫;)‪Console.WriteLine("Some Text {0}",e.msg‬‬ ‫}‬‫اﻳﻀﺎ ﺑﺎﻣﻜﺎن ال ‪ Anonymous method‬ان ﺗﺼﻞ إﻟﻰ اﻟﻤﺘﻐﻴﺮات اﻟﻤﻮﺟﻮدة ﻓﻲ اﻟﺪاﻟﺔ اﻟﺘﻲ ﺗﻢ ﺗﻌﺮﻳﻔﻬﺎ‬ ‫ً‬ ‫ﻓﻴﻬﺎ.‬ ‫4. اﺳﺘﻨﺘﺎج أﻧﻮاع اﻟﻤﺘﻐﻴﺮات‬ ‫ﻓﻲ اﻳﺎم اﻟﻔﻴﺠﻮال ﺑﻴﺴﻚ 6 ، ﻛﻨﺎ ﻗﺎدرﻳﻦ ﻋﻠﻰ ﺗﻌﺮﻳﻒ ﻣﺘﻐﻴﺮ دون ﺗﺤﺪﻳﺪ ﻧﻮﻋﻪ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Dim x‬‬ ‫01 = ‪x‬‬‫ﻓﻲ اﻟﻮاﻗﻊ ﻛﺎن اﻟﻔﻴﺠﻮال ﺑﻴﺴﻚ ﻳﻘﻮم ﺑﺘﻌﺮﻳﻔﻬﺎ ﻣﺒﺪﺋﻴﺎ ﻣﻦ اﻟﻨﻮع ‪ ،Object‬ﻓﻲ ﺣﻴﻦ ﻛﺎن ﻣﺜﻞ ﻫﺬا‬ ‫ً‬ ‫اﻻﻣﺮ ﻣﻤﻨﻮﻋﺎ ﻓﻲ اﻟﻠﻐﺎت اﻟﺘﻲ ﺗﺘﺒﻊ ﻋﺎﺋﻠﺔ اﻟﺴﻲ.‬ ‫ً‬‫ﻣﻊ 8002  ‪ ، .net‬اﺻﺒﺢ ﺑﺎﻣﻜﺎن اﻟﺴﻲ ﺷﺎرب ﺗﻌﺮﻳﻒ ﻣﺘﻐﻴﺮ ﺑﺪون اﻟﺤﺎﺟﺔ إﻟﻰ ﺗﺤﺪﻳﺪ ﻧﻮﻋﻪ ﺑﺎﻟﺸﻜﻞ‬ ‫اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪var x = 2.3 // double‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Dim x = 2.3 ‘ double‬‬‫اﻟﻬﺪف ﻣﻦ ﻫﺬه اﻟﻌﻤﻠﻴﺔ ﻫﻮ ﺗﻌﺮﻳﻒ ﻣﺘﻐﻴﺮ ﻗﺎدر ﻋﻠﻰ ﺣﻤﻞ اي ﻧﻮع ﻣﻦ اﻟﺒﻴﺎﻧﺎت ، ﻟﻜﻦ ﻛﻦ ﺣﺬرًا ، ﻓﻠﻦ‬‫ﻳﻤﻜﻨﻚ ﻣﺜﻼ ﺗﻌﺮﻳﻒ ‪ var‬ﻓﻲ اﻟﻔﺌﺔ ﻣﺒﺎﺷﺮة ، او ﻓﻲ ﺑﺎرﻣﻴﺘﺮات اﻟﺪاﻟﺔ أو ﻓﻲ ال ‪return‬‬ ‫ً‬ ‫‪ value‬ﻟﻬﺎ ، أﺧﻴﺮًا ﻻ ﻳﻤﻜﻦ ﻟﻞ ‪ var‬أن ﻳﺤﻤﻞ ﻗﻴﻤﺔ ‪.null‬‬‫932‬
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫اﻟﻤﺜﺎل اﻟﺘﺎﻟﻲ ﻳﺠﻤﻊ اﻷﺧﻄﺎء اﻟﺘﻲ ﻻ ﻳﻤﻜﻦ اﺳﺘﺨﺪام ‪ var‬ﻓﻴﻬﺎ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪class classname‬‬ ‫{‬ ‫ﻣﺒﺎﺷﺮة اﻟﻔﺌﺔ ﻓﻲ ﺗﻌﺮﻳﻔﺔ ﻳﻤﻜﻦ ﻻ //‬ ‫;01 = ‪private var varInt‬‬ ‫. ‪ return value‬ك او آﺒﺎرﻣﻴﺘﺮ اﻟﺘﻌﺮﻳﻒ ﻳﻤﻜﻦ ﻻ //‬ ‫} {)‪var functionname(var x, var y‬‬ ‫)(‪void somefunction‬‬ ‫{‬ ‫‪ null‬ﻗﻴﻤﺔ ﻳﺤﻤﻞ ان ﻳﻤﻜﻦ ﻻ //‬ ‫;‪var varNull=null‬‬ ‫‪ null‬ﻗﻴﻤﺔ ﻳﺤﻤﻞ ان ﻳﻤﻜﻦ ﻻ اﻟﻄﺮﻳﻘﺔ ﺑﻬﺬﻩ وﺣﺘﻰ //‬ ‫;21 = ‪var? varNullable‬‬ ‫ﻗﻴﻤﺔ ﺗﻌﻴﻴﻦ ﻣﻦ ﺑﺪ ﻻ //‬ ‫;‪var m‬‬ ‫}‬ ‫}‬ ‫5. اﻟﺪوال اﻟﻤﻤﺘﺪة ‪Extension Methods‬‬‫ال  ‪ Extension Methods‬واﺣﺪة ﻣﻦ ﺧﻮاص 8002 ‪ .net‬اﻟﺠﺪﻳﺪة ، ﺗﺘﻴﺢ ﻟﻚ ﻫﺬه اﻟﺨﺎﺻﻴﺔ‬ ‫اﻟﺘﻌﺪﻳﻞ ﻋﻠﻰ ﻓﺌﺎت ﻣﻮﺟﻮدة ﻣﺴﺒﻘﺎ واﺿﺎﻓﺔ داﻟﺔ أو دوال ﺟﺪﻳﺪة.‬ ‫ً‬‫ﻟﻨﻔﺘﺮض اﻧﻨﺎ ﻧﺮﻳﺪ اﺿﺎﻓﺔ داﻟﺔ ﻟﻠﻔﺌﺔ ‪ string‬ﻟﺘﻘﻮم ﺑﺎﻟﺘﺄﻛﺪ ﻣﻦ ﺻﺤﺔ اﻟﺒﺮﻳﺪ اﻻﻟﻜﺘﺮوﻧﻲ ،‬ ‫ﺳﻨﻘﻮم ﺑﻌﻤﻞ داﻟﺔ ﺗﺴﺘﺨﺪم ‪ Regex‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪public static class Extensions‬‬ ‫{‬ ‫)‪public static bool IsValidEmailAddress(this string s‬‬ ‫{‬ ‫;)"$}4,2{]-‪Regex regex = new Regex(@"^[w-.]+@([w-]+.)+[w‬‬ ‫;)‪return regex.IsMatch(s‬‬ ‫}‬ ‫}‬‫042‬
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬VB.NET ‫ﻛﻮد‬Imports System.Runtime.CompilerServicesModule 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 FunctionEnd Module :‫ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬string ‫واﻵن ، ﻳﻤﻜﻨﻨﺎ ﺑﻜﻞ ﺑﺴﺎﻃﺔ ﺗﻌﺮﻳﻒ ﻣﺘﻐﻴﺮ‬C# ‫ﻛﻮد‬string mailExample = "email@mail. com";MessageBox.Show(mailExample.IsValidEmailAddress.toString());VB.NET ‫ﻛﻮد‬Dim mailExample As String = "email@mail. com"MessageBox.Show(mailExample.IsValidEmailAddress.toString())   Automatic Properties .6 ‫ ﻟﻠﻘﺮاءة واﻟﻜﺘﺎﺑﺔ‬Get ‫ و‬Set ‫ ﻛﻨﺎ ﻧﻘﻮم ﺑﺘﻌﺮﻳﻒ دوال‬Properties ‫ﺳﺎﺑﻘﺎ وﻣﻦ اﺟﻞ اﻧﺸﺎء‬ ً :‫ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ‬ ًC# ‫ﻛﻮد‬public class myclass{ private string _name; public string name { get {return _name;} set {_name=value;} }}241
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ VB.NET ‫ﻛﻮد‬ Public Class [myclass] Private _name As String Public Property name() As String Get Return _name End Get Set(ByVal value As String) _name = value End Set End Property End Class :‫اﻵن اﺻﺒﺢ ﺑﺎﻣﻜﺎﻧﻚ ﻛﺘﺎﺑﺔ اﻟﻜﻮد ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ public class myclass { public string name{get; set;} } VB.NET ‫ﻛﻮد‬ Public Class [myclass] Public Property name() As String Get End Get Set(ByVal value As String) End Set End Property End Class   Lamda Expressions ‫7. ﺗﻌﺎﺑﻴﺮ ﻻﻣﺪا‬  ‫ اﻟﺘﻲ ﺗﻤﻜﻨﻨﺎ ﻣﻦ ﻛﺘﺎﺑﺔ ﻛﻮد‬Anonymous Methods ‫ﻛﻨﺎ ﻗﺪ ﺗﺤﺪﺛﻨﺎ ﻓﻲ ﻣﻮﺿﻮع ﺳﺎﺑﻖ ﻋﻦ‬‫اﻟﺪاﻟﺔ ﻓﻲ ﻣﻜﺎن اﺳﺘﺪﻋﺎءﻫﺎ ﻣﺎ دﻣﻨﺎ ﻟﻦ ﻧﺴﺘﺪﻋﻴﻬﺎ ﺳﻮى ﻣﺮة واﺣﺪة ﻓﻘﻂ ، ﻟﻨﻔﺘﺮض ﻣﺼﻔﻮﻓﺔ ﻧﻘﻮم‬ :2 ‫ﻓﻴﻬﺎ ﺑﺎﻟﺒﺤﺚ ﻋﻦ اﻷﻋﺪاد اﻟﺘﻲ ﺗﻘﺒﻞ اﻟﻘﺴﻤﺔ ﻋﻠﻰ‬242
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ 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); 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.NET ‫ﻛﻮد‬ 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)(AddressOf 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 ‫ اﺻﺒﺢ ﺑﺎﺳﺘﻄﺎﻋﺘﻨﺎ ﻛﺘﺎﺑﺘﻬﺎ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬C# 2008 ‫ ﻣﻦ‬Anonymous Methods  ‫ﻣﻊ اﺳﺘﺨﺪاﻣﻨﺎ ﻟﻞ‬ :‫ﻛﻤﺎ ﺗﻌﺮف‬243
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ 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); 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.NET ‫ﻛﻮد‬ 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(AddressOf ConvertedAnonymousMethod1) Console.WriteLine("Here are your even numbers:") For Each evenNumber As Integer In evenNumbers Console.Write("{0}" & Chr(9) & "", evenNumber) Next‫، واﻟﺘﻲ ﻳﻤﻜﻦ ﻛﺘﺎﺑﺘﻬﺎ‬Lambda Expressions ‫. ﻫﻮ اﺳﺘﺨﺪام ﻣﺎ ﻳﻌﺮف ﺑﺎﺳﻢ‬net 2008 ‫اﻟﺠﺪﻳﺪ ﻓﻲ‬ :‫ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ ‫ﻛﻮد‬ X => f(X) :‫ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬i%2==0 ‫ ﻓﻲ ﺣﺎﻟﺔ‬True ‫ﻟﺬا ﺳﺘﻜﻮن اﻟﺪاﻟﺔ اﻟﺨﺎﺻﺔ ﺑﻨﺎ واﻟﺘﻲ ﺗﻌﻴﺪ‬ C# ‫ﻛﻮد‬ (int i) => (i % 2) == 0; VB.NET ‫ﻛﻮد‬ Function(i As Integer) (i Mod 2) = 0244
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫ ، ﻳﻤﻜﻨﻚ ﺣﺘﻰ اﻻﺳﺘﻐﻨﺎء ﻋﻦ ﺗﻌﺮﻳﻒ ﻧﻮع اﻟﺒﺎرﻣﻴﺘﺮ ﻹن‬int ‫ ﻫﻲ اﻟﺒﺎرﻣﻴﺘﺮ ، وﻧﻮﻋﻪ‬i ‫ﺣﻴﺚ ان ال‬ :‫ ﺳﻮف ﺗﺘﻌﺮف ﻋﻠﻴﻪ ﺗﻠﻘﺎﺋﻴﺎ ، ﻟﺬا ﺳﻴﻜﻮن اﻟﻜﻮد اﻟﻜﺎﻣﻞ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬Lambda ً 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.NET ‫ﻛﻮد‬ 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 As ) (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‫ ﻓﻘﻂ ، ﻳﻤﻜﻨﻚ اﻻﻃﻼع ﻋﻠﻰ‬true , false ‫ﻳﻤﻜﻨﻨﺎ ﻟﻴﺲ ﻓﻘﻂ اﻋﺎدة ﻗﻴﻤﺔ واﺣﺪة أو‬ :‫اﻟﻤﺜﺎل اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ List<int> evenNumbers = list.FindAll((i) => { Console.WriteLine("value of i is currently: {0}", i); bool isEven = ((i % 2) == 0); return isEven; }); ...‫اﻳﻀﺎ ﻳﻤﻜﻨﻨﺎ ﺗﻤﺮﻳﺮ اﻛﺜﺮ ﻣﻦ ﺑﺎرﻣﻴﺘﺮ ، وذﻟﻚ ﺣﺴﺐ اﻟﺪاﻟﺔ‬ ً   :Lambda ‫ﻣﻮاﺻﻔﺎت‬ . ‫ ﺧﺎﺻﻴﺔ اﻹﺳﻢ‬Lambda ‫- ﻻ ﺗﻤﻠﻚ‬245
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫ﻻ ﻳﻤﻜﻦ اﺳﺘﺨﺪام ﺑﻌﺾ ﻣﺒﺎدئ ال ‪ OOP‬ﻣﺜﻞ ‪ Overloads‬أو ‪.Overrides‬‬ ‫-‬ ‫ﻻ ﺗﺴﺘﺨﺪم ﻗﺴﻢ ‪ As‬ﻟﺘﺤﺪﻳﺪ ﻧﻮع اﻟﻘﻴﻤﺔ اﻟﻤﻌﺎدة وﺑﺪﻻ ﻣﻦ ذﻟﻚ ﻳﺘﻢ اﺳﺘﻨﺘﺎج اﻟﻤﺘﻐﻴﺮات ﺗﻠﻘﺎﺋﻴﺎ .‬ ‫ً‬ ‫-‬ ‫داﺧﻞ اﻟﺘﻌﺒﻴﺮ ﻻ ﺑﺪ ﻣﻦ وﺟﻮد ﻛﻮد وﻟﻴﺲ ﺗﻌﺮﻳﻒ ﻟﺸﻲء آﺧﺮ ، وﻳﻤﻜﻦ اﺳﺘﺪﻋﺎء داﻟﺔ أﻳﻀﺎ .‬ ‫ً‬ ‫-‬ ‫ﻻ ﻳﺘﻢ اﺳﺘﺨﺪام ‪ Return‬ﺑﻞ ﻳﺘﻢ اﻋﺎدة ﻗﻴﻢ اﻟﺪاﻟﺔ ﻣﺒﺎﺷﺮة .‬ ‫-‬ ‫ﻻ ﻳﻮﺟﺪ ‪ End‬أو }{ ﻓﻲ ‪.Lambda‬‬ ‫-‬ ‫ﻻ ﻳﻤﻜﻦ اﺳﺘﺨﺪام ‪ Optinal‬ﻓﻲ ‪.VB‬‬ ‫-‬ ‫ﻻ ﻳﻤﻜﻦ اﺳﺘﺨﺪام ‪.Generic‬‬ ‫-‬‫‪  Object Initializer Syntax‬‬ ‫8. ﺻﻴﻎ اﻧﺸﺎء اﻟﻜﺎﺋﻨﺎت‬‫ﻟﻦ ﻧﻄﻴﻞ ﻛﺜﻴﺮًا ﻓﻲ ﻫﺬا اﻟﺪرس ، ﻓﻘﻂ ﺳﻨﺘﻌﺮض ﻟﻌﺪة اﻣﺜﻠﺔ ﺳﺮﻳﻌﺔ ﻋﻦ ﻓﺌﺔ اﻟﻤﻮﻇﻔﻴﻦ اﻟﺘﻲ‬ ‫ﺗﺤﺘﻮي ﺧﺼﺎﺋﺺ اﻻﺳﻢ واﻟﻌﻤﺮ واﻟﻤﺮﺗﺐ.‬ ‫اﻟﻤﺜﺎل اﻷول ﻣﺎ ﻗﺒﻞ 8002 ‪:.net‬‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪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‬‬ ‫}‬ ‫‪public string salary‬‬ ‫{‬ ‫} ;‪get { return _salary‬‬ ‫} ;‪set { _salary = value‬‬ ‫}‬ ‫}‬‫642‬
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ VB.NET ‫ﻛﻮد‬ 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(ByVal value As String) _name = value End Set End Property Public Property age() As String Get Return _age End Get Set(ByVal value As String) _age = value End Set End Property Public Property salary() As String Get Return _salary End Get Set(ByVal value As String) _salary = value End Set End Property End Class :‫ اﻟﺘﻲ ﺗﻌﻠﻤﻨﺎﻫﺎ ﻓﻲ درس ﺳﺎﺑﻖ‬automatic property ‫. وﺑﺎﺳﺘﺨﺪام‬net 2008 ‫اﻟﻤﺜﺎل اﻟﺜﺎﻧﻲ ﻣﻊ‬ VB.NET ‫ﻛﻮد‬ Public Class Employee Public Property name() As String Get: End Get Set(ByVal value As String) End Set End Property Public Property age() As String Get: End Get Set(ByVal value As String) End Set End Property Public Property salary() As String Get:End Get Set(ByVal value As String) End Set End Property End Class247
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ C# ‫ﻛﻮد‬ public class Employee { public string name { get; set; } public string age { get; set; } public string salary { get; set; } }‫.، ﻧﺮﻳﺪ‬net  2008‫ اﻟﺠﺪﻳﺪ ﻣﻦ‬Object  Initializer  Syntax ‫اﻟﻤﺜﺎل اﻟﺜﺎﻟﺚ وﻣﻊ اﺳﺘﺨﺪام‬‫اﻟﻮﺻﻮل إﻟﻰ اﻟﺨﺼﺎﺋﺺ اﻟﺘﻲ ﺳﺒﻖ ﻟﻨﺎ ﺗﻌﺮﻳﻔﻬﺎ ﺑﺄﺣﺪ اﻟﻄﺮق اﻟﺴﺎﺑﻘﺔ ، ﻓﻲ اﻟﺴﺎﺑﻖ ﻛﻨﺎ ﻧﻜﺘﺐ ﻛﻮد‬ :‫ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ Employee e = new Employee(); e.Name="Ahmed"; e.Age=15; e.salary=6000; VB.NET ‫ﻛﻮد‬ Dim e As Employee = New Employee() e.Name = "Ahmed" e.Age = 15 e.salary = 6000 :‫اﻟﺠﺪﻳﺪ ﻫﻨﺎ‬ C# ‫ﻛﻮد‬ Employee e = new Employee { Name = "Ahmed", Age = 15, salary = 6000 }; VB.NET ‫ﻛﻮد‬ Dim e As Employee = New Employee With {.Name="Ahmed" ,.Age=15,.Salary=1500} Anonymous Types ‫9. اﻷﻧﻮاع اﻟﻤﺠﻬﻮﻟﺔ‬‫.، ﻓﻲ ﻫﺬا اﻟﺪرس ﺳﻮف ﻧﺘﻌﺮف‬net 2008‫ﻧﻮاﺻﻞ ﻓﻲ ﻫﺬا اﻟﺪرس ﺷﺮح اﻟﺨﺼﺎﺋﺺ اﻟﺠﺪﻳﺪة ﻓﻲ‬ . Anonymous Types ‫ﻋﻠﻰ‬248
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬‫ﻻ ﺗﻨﺴﻰ اﻧﻨﺎ ﺗﻌﻠﻤﻨﺎ ان ﺑﺎﻣﻜﺎﻧﻨﺎ ﺗﻌﺮﻳﻒ ﻣﺘﻐﻴﺮات ﻣﺠﻬﻮﻟﺔ ﺑﺎﺳﺘﺨﺪام اﻟﻜﻠﻤﺔ ‪ var‬ﻓﻲ اﻟﺴﻲ ﺷﺎرب ، اﻣﺎ‬‫اﻵن ﻓﻠﻢ ﺗﻌﺪ ﻣﺘﻐﻴﺮات ﻣﺠﻬﻮﻟﺔ اﻟﻬﻮﻳﺔ ﻓﻘﻂ ﺑﻞ ﺑﺎﻣﻜﺎﻧﻚ ﺗﻌﺮﻳﻒ اﻧﻮاع ﻣﺠﻬﻮﻟﺔ اﻳﻀﺎ ، ﻟﻦ اﻃﻴﻞ‬ ‫ً‬ ‫ﻛﺜﻴﺮًا ﻓﻲ اﻟﻤﻘﺪﻣﺔ ، اﻧﻈﺮ إﻟﻰ اﻟﻜﻮد اﻟﺘﺎﻟﻲ :‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;} 02 = ‪var e = new { Name = "Ahmed", Age‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫}0051=‪Dim e As Employee = New Employee With {.Name="Ahmed" ,.Age=15,.Salary‬‬‫اﺻﻼً،‬ ‫اﻟﻔﺌﺔ‬ ‫ﺗﻌﺮﻳﻒ‬ ‫ﺑﺪون‬ ‫‪e.Age‬‬ ‫و‬ ‫‪e.Name‬‬ ‫ﻗﺮاءة‬ ‫ﺑﺎﻣﻜﺎﻧﻚ‬ ‫اﺻﺒﺢ‬ ‫اﻵن‬‫ﻓﻌﻠﻴﺎ ال ‪ Anonymous Types‬ﻳﺘﻢ اﺳﻨﺎده ﻣﺒﺎﺷﺮة إﻟﻰ ‪ System.Object‬ﻟﺬا ﻓﻬﻮ ﻳﺤﺘﻮي ﻋﻠﻰ‬ ‫ً‬ ‫ﺧﺼﺎﺋﺼﻪ اﻻﺳﺎﺳﻴﺔ.‬ ‫ﻣﺎذا اﺳﺘﻔﻴﺪ ؟‬‫ﻓﻲ ‪ LINQ‬ﻳﻤﻜﻨﻨﺎ ﺗﻌﺮﻳﻒ ﻓﺌﺔ ﺗﺮﺗﺒﻂ ﺑﻨﺎﺗﺞ ﺟﻤﻠﺔ اﻻﺳﺘﻌﻼم ، ﻟﻨﻔﺘﺮض اﻧﻨﺎ ﻧﻮد ﻗﺮاءة ﻧﺎﺗﺞ ﺟﻤﻠﺔ‬ ‫اﺳﺘﻌﻼم وﻻ ﻧﻌﻠﻢ ﺗﺤﺪﻳﺪاً ﺷﻜﻞ اﻟﻨﺎﺗﺞ ، ﻳﺘﻢ ذﻟﻚ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ :‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;} ‪var result = from emp in employee select new { emp.Name, emp.Salary‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Dim namePriceQuery = From emp In employee Select emp.Name, emp.Salary‬‬ ‫اﻟﺨﺼﺎﺋﺺ اﻟﻤﻔﺘﺎﺣﻴﺔ ‪Key Properties‬‬ ‫ﺗﺨﺘﻠﻒ اﻟﺨﺼﺎﺋﺺ اﻟﻤﻔﺘﺎﺣﻴﺔ ﻋﻦ اﻟﻌﺎدﻳﺔ ﺑﻌﺪة أﻣﻮر‬ ‫- ﺗﺴﺘﺨﺪم اﻟﺨﺼﺎﺋﺺ اﻟﻤﻔﺘﺎﺣﻴﺔ ﻓﻘﻂ ﻟﻤﻘﺎرﻧﺔ اﻟﻤﺴﺎواة ﺑﻴﻦ ﻧﻮﻋﻴﻦ ﻣﺠﻬﻮﻟﻴﻦ‬ ‫- ﻻﻳﻤﻜﻦ ﺗﻐﻴﻴﺮ ﻗﻴﻢ اﻟﺨﺼﺎﺋﺺ اﻟﻤﻔﺘﺎﺣﻴﺔ ﻓﻬﻲ داﺋﻤﺎ ﻟﻠﻘﺮاءة ﻓﻘﻂ‬‫942‬
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬‫- ﻓﻘﻂ اﻟﺨﺼﺎﺋﺺ اﻟﻤﻔﺘﺎﺣﻴﺔ ﻳﺘﻢ ﺗﻀﻤﻴﻨﻬﺎ ﺿﻤﻦ اﻟـ ‪ Hash  Code‬اﻟﺬي ﻳﻮﻟﺪه اﻟﻤﺘﺮﺟﻢ ﻣﻦ أﺟﻞ‬ ‫اﻷﻧﻮاع اﻟﻤﺠﻬﻮﻟﺔ .‬ ‫اﻟﻤﺴﺎواة ‪Equality‬‬‫ﺗﻜﻮن ﻣﺘﻐﻴﺮات اﻷﻧﻮاع اﻟﻤﺠﻬﻮﻟﺔ ﻣﺘﺴﺎوﻳﺔ ﻋﻨﺪﻣﺎ ﺗﻜﻮن ﻣﺘﻐﻴﺮات ﻟﻨﻔﺲ اﻟﻨﻮع اﻟﻤﺠﻬﻮل وﻳﻘﻮم‬ ‫اﻟﻤﻌﺎﻟﺞ ﺑﻤﻌﺎﻣﻠﺔ ﻣﺘﻐﻴﺮﻳﻦ ﻛﻤﺘﻐﻴﺮﻳﻦ ﻣﻦ ﻧﻔﺲ اﻟﻨﻮع إذا ﺗﻮﻓﺮت ﻓﻴﻬﻤﺎ اﻟﺸﺮوط اﻟﺘﺎﻟﻴﺔ :‬ ‫- ﺗﻢ اﻟﺘﺼﺮﻳﺢ ﻋﻨﻬﻤﺎ ﻓﻲ ﻧﻔﺲ اﻟﻤﺪى ‪. Scope‬‬‫- ﺗﻤﺘﻠﻚ ﺧﺼﺎﺋﺼﻬﻤﺎ ﻧﻔﺲ اﻻﺳﻢ واﻟﻨﻮع وﺗﻢ اﻟﺘﺼﺮﻳﺢ ﻋﻨﻬﺎ ﺑﻨﻔﺲ اﻟﺘﺮﺗﻴﺐ وﺗﻜﻮن ﻣﻘﺎرﻧﺔ اﻷﺳﻤﺎء‬ ‫ﻏﻴﺮ ﺣﺴﺎﺳﺔ ﻟﺤﺎﻟﺔ اﻷﺣﺮف .‬ ‫- ﻧﻔﺲ اﻟﺨﺼﺎﺋﺺ ﻓﻴﻬﺎ ﻣﺤﺪدة ﻛﺨﺼﺎﺋﺺ أﺳﺎﺳﻴﺔ .‬ ‫- ﻳﻤﺘﻠﻚ ﻛﻞ ﻧﻮع ﺧﺎﺻﻴﺔ أﺳﺎﺳﻴﺔ واﺣﺪة ﻋﻠﻰ اﻷﻗﻞ .‬ ‫واﻟﺘﺼﺮﻳﺢ ﻋﻦ ﻧﻮع ﻣﺠﻬﻮل ﻻﻳﻤﺘﻠﻚ أي ﺧﺎﺻﻴﺔ ﻣﻔﺘﺎﺣﻴﺔ ﻳﻜﻮن ﻣﺴﺎوﻳﺎ ﻟﻨﻔﺴﻪ ﻓﻘﻂ .‬ ‫ﻛﻤﺎ ﻻ ﺗﻨﺲ أﻧﻪ ﻻ ﻳﻤﻜﻦ ﺗﻐﻴﻴﺮ ﻗﻴﻢ اﻟﺨﺼﺎﺋﺺ اﻟﻤﻔﺘﺎﺣﻴﺔ ...‬ ‫01. ‪Partial Methods‬‬‫ﺑﺎﺧﺘﺼﺎر ﺷﺪﻳﺪ ، ﻟﻢ ﺗﻌﺪ اﻵن ﻣﺠﺒﺮًا ﻋﻠﻰ وﺿﻊ اﻟﻔﺌﺔ ﻓﻲ ﻣﻨﻄﻘﺔ واﺣﺪة ، ﺑﻞ ان ﺑﺎﻣﻜﺎﻧﻚ‬‫ﻛﺘﺎﺑﺔ اﻟﻔﺌﺔ ﻓﻲ اﻛﺜﺮ ﻣﻦ ﻣﻮﺿﻊ ، ﺣﻴﺚ ﻳﻜﻔﻲ ان ﺗﺴﺘﺨﺪم اﻟﻜﻠﻤﺔ ‪ Partial‬ﻓﻲ اﺳﻢ اﻟﻔﺌﺔ ﻟﺘﺪل‬ ‫ﻋﻠﻰ ان ﻫﺬه ﻟﻴﺲ ﻓﺌﺔ ﺟﺪﻳﺪة ﺑﻞ ﻫﻮ ﻳﺘﺒﻊ ﻓﺌﺔ ﻣﻌﺮﻓﺔ ﻓﻲ ﻣﻜﺎن آﺧﺮ ، ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪partial class Car‬‬ ‫{‬ ‫}‬‫052‬
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫‪Partial Class Car‬‬‫‪End Class‬‬‫ﻛﺎن ﻫﺬا ﻣﻊ ﻋﺼﺮ 5002 ‪ ، .net‬وﻟﻜﻦ ﺑﻌﺪ ذﻟﻚ ﻇﻬﺮ ﻣﺆﺧﺮًا ﻣﺎ ﻳﻌﺮف ﺑﺎﺳﻢ ‪،Partial Methods‬‬ ‫ﺣﻴﺚ ﻟﻢ ﺗﻌﺪ ﻣﻀﻄﺮًا ﻟﻜﺘﺎﺑﺔ اﻟﺪاﻟﺔ ﻓﻲ ﻣﻜﺎن واﺣﺪ اﻳﻀﺎ ، ﻳﺘﻢ ذﻟﻚ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ :‬ ‫ً‬‫#‪C‬‬ ‫ﻛﻮد‬‫)‪partial void methodname(string parm‬‬‫{‬‫}‬‫‪VB.NET‬‬ ‫ﻛﻮد‬‫)‪Partial Private Sub methodname(ByVal parm As String‬‬‫‪End Sub‬‬‫ﻃﺒﻌﺎ ﻛﻤﺎ ﺗﻼﺣﻆ ، اﻓﺎدﻧﺎ ﻫﺬا اﻟﻤﻮﺿﻮع ﻛﺜﻴﺮًا ﻓﻲ ﺗﻄﻮﻳﺮ ﺧﺼﺎﺋﺺ اﻟﻔﺌﺎت اﻻﺳﺎﺳﻴﺔ ودواﻟﻬﺎ ﺑﺪون‬ ‫ً‬ ‫اﻟﺤﺎﺟﺔ إﻟﻰ ﺗﻌﺮﻳﻒ ﻧﺴﺨﺔ ﺟﺪﻳﺪة ﻣﻨﻬﺎ.‬ ‫11. ‪Garbage Collector‬‬‫ﺧﻼل دروﺳﻨﺎ اﻟﺴﺎﺑﻘﺔ ﻛﻨﺎ ﻧﻌﺮف ﻣﺘﻐﻴﺮات وﻓﺌﺎت .. اﻟﺦ ، وﻟﻜﻨﻨﺎ ﻟﻢ ﻧﺴﺄل ﻧﻔﺴﻨﺎ ﻛﻴﻒ ﻳﺘﻢ‬‫ﺗﺨﺰﻳﻨﻬﺎ ﻓﻲ اﻟﺬاﻛﺮة وﻣﺘﻰ ﻳﺘﻢ ﺣﺬﻓﻬﺎ ، ﻫﺬه اﻻﺳﺌﻠﺔ ﺳﻮف ﻧﺠﻴﺐ ﻋﻠﻴﻬﺎ ﻓﻲ ﻫﺬا اﻟﺪرس ﻣﻦ ﺧﻼل‬ ‫ﻣﻔﺎﻫﻴﻢ ال ‪ Object lifetime‬وال ‪.GC‬‬‫ﻋﻨﺪ ﺗﻌﺮﻳﻔﻚ ﻟﻜﺎﺋﻦ ﻣﻦ ﻓﺌﺔ ‪ OBJECT  FROM  CLASS‬ﻓﺈﻧﻚ ﺑﺎﻟﻮاﻗﻊ ﺗﺼﺒﺢ ﻣﻤﺴﻜﺎ ب ‪Refernce‬‬ ‫ً‬‫ﻳﺸﻴﺮ إﻟﻰ ﻫﺬا اﻟﻜﺎﺋﻦ اﻟﻤﻮﺟﻮد ﻓﻲ ال ‪ ، heap‬ﻫﺬا ال ‪ reference‬ﻳﻮﺟﺪ اﻳﻀﺎ ﻓﻲ ‪ stack‬ﺧﺎص‬ ‫ً‬ ‫ﺑﺎﻟﺒﺮﻧﺎﻣﺞ.‬‫ﺑﻌﺪ اﻏﻼق اﻟﺒﺮﻧﺎﻣﺞ او اﻧﺘﻬﺎء اﻟﺪاﻟﺔ ﻳﺘﻢ ﺣﺬف ال ‪ reference‬ﻣﻦ ال ‪ ، stack‬ﺳﻴﻜﻮن اﻟﺘﺴﺎؤل‬‫اﻟﻄﺒﻴﻌﻲ ﻫﻮ اﻧﻪ وﻓﻲ ﻫﺬه اﻟﺤﺎﻟﺔ ﺳﻮف ﺗﻤﺘﻠﺊ اﻟﺬاﻛﺮة ﺑﻤﺌﺎت اﻟﻜﺎﺋﻨﺎت اﻟﺘﻲ ﻻ ﺗﺠﺪ ﻣﻦ ﻳﺸﻴﺮ ﻟﻬﺎ ،‬‫ﻳﺮﻳﺤﻚ ال ‪ garbage collector‬واﻟﺬي ﻳﺮﻣﺰ ﻟﻪ اﺧﺘﺼﺎرًا ‪ GC‬ﻣﻦ ﻫﺬا اﻟﺘﺴﺎؤل ﺣﻴﺚ ﻳﻘﻮم ﺑﺤﺬف‬‫152‬
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬‫اﻟﻔﺌﺎت ﻏﻴﺮ اﻟﻤﺴﺘﺨﺪﻣﺔ ، او ﻓﻲ اﻟﺤﻘﻴﻘﺔ ﻓﻬﻮ ﻳﻘﻮم ﺑﺤﺬف ﺟﻤﻴﻊ اﻟﻔﺌﺎت اﻟﺘﻲ ﻟﻢ ﻳﻌﺪ ﺑﺎﻣﻜﺎﻧﻚ‬ ‫اﻟﻮﺻﻮل إﻟﻴﻬﺎ ﻣﻦ داﺧﻞ اﻟﺒﺮﻧﺎﻣﺞ.‬‫ﻓﻲ اﻳﺎم ال ++‪ C‬ﻛﺎن ﻣﻦ اﻟﻤﻔﺘﺮض ان ﺗﻘﻮم ﺑﺤﺬف ﻣﺘﻐﻴﺮاﺗﻚ اﻟﻐﻴﺮ ﻣﺴﺘﺨﺪﻣﺔ اول ﺑﺄول، اﻣﺎ اﻵن‬ ‫ﻣﻊ ‪ GC‬ﻓﺎﺻﺒﺤﺖ ﺟﻞ اﻟﻤﻬﺎم ﻳﺘﻢ ﺗﻨﻔﻴﺬﻫﺎ دون ان ﺗﺸﻌﺮ.‬‫اﻟﺤﺎﻟﺔ اﻻﻛﺜﺮ ﺷﻴﻮﻋﺎ ﻫﻲ ان ﺗﻘﻮم ﺑﻌﻤﻞ ‪ ، =null‬ﻓﻲ اﻟﻮاﻗﻊ ﻫﺬا ﻻ ﻳﻌﻄﻲ اﺷﺎرة ﻣﺒﺎﺷﺮة ﻟﻞ ‪GC‬‬ ‫ً‬‫ﻟﺤﺬف ﻛﺎﺋﻨﻚ ﻣﻦ اﻟﺬاﻛﺮة ، ﻟﻜﻨﻪ ﺳﻴﺘﻢ ﺣﺬﻓﻪ ﻓﻲ ﻟﺤﻈﺔ ﻣﺎ ﻻ ﻳﻤﻜﻨﻚ اﻟﺘﺤﻜﻢ ﺑﻬﺎ ، ﻋﻨﺪﻣﺎ ﺗﻤﺘﻠﺊ‬ ‫اﻟﺬاﻛﺮة ﻣﺜﻼ.‬ ‫ً‬ ‫11. 1. اﻟﻔﺌﺔ ‪  GC‬‬‫ﺗﺤﺘﻮي اﻟﻔﺌﺔ ‪ GC‬ﻋﻠﻰ ﻋﺪد ﻣﻦ اﻟﺪاول اﻟﺘﻲ ﺗﻤﻜﻨﻚ ﻣﻦ اﻟﺘﻌﺎﻣﻞ اﻟﻤﺒﺎﺷﺮ ﻣﻌﻬﺎ ، ﻫﺬه ﺻﻮرة‬ ‫ﻣﻦ ﻛﺘﺎب 8002 ‪ Pro Csharp‬اﻟﺪوال واﺳﺘﺨﺪاﻣﺎﺗﻬﺎ:‬ ‫اﻟﺼﻮرة 21. 1. دوال اﻟﻔﺌﺔ ‪GC‬‬‫252‬
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫)(‪:Finalize‬‬‫ﻳﻤﻜﻨﻚ ﻫﺬا اﻟﺤﺪث ﻣﻦ اﻗﺘﻨﺎص وﻗﺖ ﺣﺬف اﻟﻜﺎﺋﻦ ، ﻳﻤﻜﻨﻚ ﻋﻤﻞ ‪ overriding‬ﻟﻪ وﺗﻨﻔﻴﺬ ﺑﻌﺾ‬ ‫اﻟﻤﻬﺎم ﻗﺒﻞ ﺗﺪﻣﻴﺮ اﻟﻜﺎﺋﻦ.‬ ‫ﻳﺘﻢ ذﻟﻚ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪class example‬‬ ‫{‬ ‫)(‪~example‬‬ ‫{‬ ‫;)(‪Console.Beep‬‬ ‫}‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Class example‬‬ ‫)(‪Protected Overrides Sub Finalize‬‬ ‫‪Try‬‬ ‫)(‪Console.Beep‬‬ ‫‪Finally‬‬ ‫)(‪MyBase.Finalize‬‬ ‫‪End Try‬‬ ‫‪End Sub‬‬ ‫‪End Class‬‬ ‫21. ‪Operator Overloading‬‬‫ﻓﻲ اﻻﻧﻮاع اﻟﺮﺋﻴﺴﻴﺔ ﻟﻨﺎ ، ﻧﺴﺘﺨﺪم اﻟﻤﻌﺎﻣﻼت اﻟﻤﺨﺘﻠﻔﺔ ﻟﺘﻨﻔﻴﺬ ﻋﻤﻠﻴﺎت ﻋﻠﻰ اﻟﻔﺌﺎت اﻟﻤﺸﺘﻘﺔ‬ ‫ﻣﻨﻬﺎ ، ﻓﻤﺜﻼ اﻟﻤﺘﻐﻴﺮ ﻣﻦ ﻧﻮع ‪ Integer‬ﻳﻔﻬﻢ اﻟﻤﻌﺎﻣﻞ + ﻋﻠﻰ اﻧﻪ ﺟﻤﻊ ، - ﻋﻠﻰ اﻧﻪ ﻃﺮح ... اﻟﺦ.‬ ‫ً‬ ‫اﻳﻀﺎ اﻟﻤﺘﻐﻴﺮات ﻣﻦ ﻧﻮع ‪ String‬ﺗﻔﻬﻢ اﻟﻤﺘﻐﻴﺮ + ﻣﺜﻼ ﻋﻠﻰ اﻧﻪ ﻟﺪﻣﺞ ﻧﺼﻴﻦ ، وﻫﻜﺬا.‬ ‫ً‬ ‫ً‬ ‫اﻵن ﻟﻮ ﻗﻤﻨﺎ ﺑﻌﻤﻞ ‪ Structure‬ﻣﻦ ﻧﻮع ‪ Point‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪public struct Point‬‬ ‫{‬ ‫;‪private int x, y‬‬ ‫)‪public Point(int xPos, int yPos‬‬ ‫{‬ ‫;‪x = xPos‬‬ ‫;‪y = yPos‬‬ ‫}‬ ‫}‬‫352‬
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ VB.NET ‫ﻛﻮد‬ 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 ‫اﻵن ﺟﺮب ﺗﻌﺮﻳﻒ ﻋﺪة ﻧﻘﺎط ، واﺳﺘﺨﺪام اﻟﻤﻌﺎﻣﻞ + او - ﻟﺠﻤﻊ وﻃﺮح اﻟﻨﻘﺎط ، ﻣﺎ ﺗﺘﻮﻗﻌﻪ ان‬ . ‫ﺗﺸﺎﻫﺪ اﻟﻨﺎﺗﺞ‬‫ ، أو ﺟﻤﻌﻬﻤﺎ ﻣﻌﺎ ، إﻻ اﻧﻚ ﻓﻲ‬y ‫ ﻓﻲ اﻟﻨﻘﻄﺔ اﻟﺜﺎﻧﻴﺔ ﻣﻦ اﻷوﻟﻰ وﻛﺬا ال‬x ‫ﻋﺒﺎرة ﻋﻦ ﻃﺮح ال‬ ً‫ ﻻ ﻳﺪﻋﻢ ﻣﻌﺎﻣﻼت‬Point ‫ اﻟﻤﺴﻤﻰ‬structure ‫اﻟﻮاﻗﻊ ﻟﻦ ﺗﺤﺼﻞ ﺳﻮى ﻋﻠﻰ رﺳﺎﻟﺔ ﺧﻄﺄ ﺗﻔﻴﺪك ﺑﺄن‬ . ‫اﻟﺠﻤﻊ واﻟﻄﺮح‬ :‫ اﻟﺴﺎﺑﻖ‬structure ‫اﻵن ﺳﻨﻘﻮم ﺑﺎﺿﺎﻓﺔ ﻣﻌﺎﻣﻼت ﺟﻤﻊ وﻃﺮح إﻟﻰ ال‬ 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); } }254
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ VB.NET ‫ﻛﻮد‬ 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 :‫اﻵن ﻳﻤﻜﻨﻚ ﻛﺘﺎﺑﺔ ﻛﻮد ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ Point p3 = p1 + p2; VB.NET ‫ﻛﻮد‬ Dim p3 As Point = p1 + p2 .Points ‫ﺳﺘﺤﺼﻞ ﻋﻠﻰ اﻟﻨﺘﻴﺠﺔ اﻟﺼﺤﻴﺤﺔ ﻟﻌﻤﻠﻴﺔ ﺟﻤﻊ ال‬ :‫أﻳﻀﺎ ﻳﻤﻜﻨﻚ ﻛﺘﺎﺑﺔ ﻛﻮد ﻛﺎﻟﺘﺎﻟﻲ ﻣﺒﺎﺷﺮة‬ ً C# ‫ﻛﻮد‬ p2-=p1; VB.NET ‫ﻛﻮد‬ p2-=p1static ‫آﺧﺮ ﻣﺎ ﺳﻨﺘﻌﺮف ﻋﻠﻴﻪ ﻓﻲ ﻫﺬا اﻟﺠﺰء ﻣﻦ اﻟﺪرس ، اﻧﻚ ﻟﻦ ﺗﻜﻮن ﻗﺎدرًا ﺳﻮى ﻋﻠﻰ ﺗﻌﺮﻳﻒ‬ .‫ ﻷي ﻣﻌﺎﻣﻞ‬overloading ‫ ﻣﻦ اﺟﻞ ﻋﻤﻞ‬function‫، ﺑﻞ ﻳﻤﻜﻨﻚ ﻋﻤﻞ ذﻟﻚ ﻷي ﻧﻮع‬overloading ‫ﻟﻴﺴﺖ ﻣﻌﺎﻣﻼت اﻟﺠﻤﻊ واﻟﻄﺮح ﻓﻘﻂ ﻣﻦ ﻳﻤﻜﻦ ﻋﻤﻞ‬ :‫ﻣﻦ اﻟﻤﻌﺎﻣﻼت ، ﻓﻤﺜﻼ ++ و -- ﻓﻲ اﻟﺴﻲ ﺷﺎرب ﻓﻘﻂ‬ ً255
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ 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); }‫ﻧﻔﺲ اﻷﻣﺮ ﺑﺎﻟﻨﺴﺒﺔ ﻟﺪوال اﻟﻤﺴﺎواة وﻋﻤﻞ == أو != ﺣﻘﻴﻘﻴﺔ ﻣﺜﻞ ﻣﺎ ﺗﻌﻠﻤﻨﺎ ﺳﺎﺑﻘﺎ ﻣﻊ ﻋﻤﻞ‬ ً :‫، ﺳﻨﻌﺘﻤﺪ ﻫﻨﺎ ﻋﻠﻰ ﻫﺬه اﻟﺪاﻟﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬Equals ‫ ﻟﻠﺪاﻟﺔ‬overriding C# ‫ﻛﻮد‬ public override bool Equals(object o) { return o.ToString() == this.ToString(); } public static bool operator ==(Point p1, Point p2) { return p1.Equals(p2); } public static bool operator !=(Point p1, Point p2) { return !p1.Equals(p2); } VB.NET ‫ﻛﻮد‬ 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 ‫ ﻷي ﻣﻦ ﻫﺬه‬overloading ‫وﻫﻜﺬا ﺗﺠﺪ ان ﺑﺎﻣﻜﺎﻧﻚ ﻋﻤﻞ‬ :‫اﻟﻤﻌﺎﻣﻼت‬256
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫31. اﻟﻤﺆﺷﺮات ‪Pointers‬‬ ‫إذا ﻛﻨﺖ ﻣﺒﺮﻣﺞ ++‪ ، C‬ﻓﺄﻧﺖ ﺑﺎﻟﺘﺄﻛﻴﺪ ﺗﺪرك ﻣﻌﻨﻰ ‪ ،pointer‬أﻣﺎ ﻟﻮ ﻟﻢ ﺗﻜﻦ ﻛﺬﻟﻚ، أﻣﺎ ﻟﻮ‬ ‫ﻟﻢ ﺗﻜﻦ ﻛﺬﻟﻚ ﻓﻌﻠﻴﻚ ان ﺗﻌﺮف اﻧﻪ ﺑﺎﻻﺿﺎﻓﺔ إﻟﻰ ال  ‪ value  type‬وال ‪ ،reference  type‬ﻫﻨﺎك‬ ‫اﻳﻀﺎ ال ‪ pointer type‬واﻟﺘﻲ ﺗﺨﺘﺺ ﺑﺎﻻﺷﺎرة إﻟﻰ اﻣﺎﻛﻦ ﻣﻌﻴﻨﺔ ﻓﻲ اﻟﺬاﻛﺮة.‬ ‫ً‬ ‫ﺑﺪاﻳﺔ أول ﻣﺎ ﺳﺘﻌﺮﻓﻪ اﻧﻚ ﻟﻦ ﺗﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﻓﻲ اﻟﻜﻮد اﻟﻄﺒﻴﻌﻲ ، ﺑﻞ ﺳﺘﻀﻄﺮ ﻻﺳﺘﺨﺪام  ‪unsafe‬‬ ‫‪ code‬ﻟﻌﻤﻞ ذﻟﻚ ﺣﻴﺚ أن اﻟﺴﻲ ﺷﺎرب ﻟﻦ ﺗﺴﻤﺢ ﻟﻚ اﻓﺘﺮاﺿﻴﺎ ﺑﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ ال ‪ ،pointers‬ﻟﺬا ﻗﻢ‬ ‫ً‬ ‫اوﻻ ﺑﺎﻟﺴﻤﺎح ﻟﻨﻔﺴﻚ ﺑﺎﺳﺘﺨﺪاﻣﻬﺎ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫ً‬ ‫اﻟﺼﻮرة 21. 2. ﺗﻤﻜﻴﻦ اﺳﺘﺨﺪام ﺧﺎﺻﻴﺔ ال ‪ Unsafe code‬ﻓﻲ اﻟﻤﺸﺮوع.‬ ‫واﻵن ﻣﻦ ﺧﻼل اﻟﻜﻮد اﻟﺨﺎص ﺑﻚ ﻳﻤﻜﻨﻚ ﻛﺘﺎﺑﺔ ﻛﻮد ﻳﺘﻌﺎﻣﻞ ﻣﻊ ال ‪ pointers‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ ‫ﻣﺜﻼ:‬ ‫ً‬ ‫752‬
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪class Program‬‬ ‫{‬ ‫)‪static void Main(string[] args‬‬ ‫{‬ ‫‪unsafe‬‬ ‫{‬ ‫!‪// Work with pointer types here‬‬ ‫}‬ ‫!‪// Cant work with pointers here‬‬ ‫}‬ ‫}‬‫اﻵن ﺳﻨﺘﻌﺮف ﻋﻠﻰ اﻷدوات اﻷﺳﺎﺳﻴﺔ اﻟﺘﻲ ﺳﺘﻌﻴﻨﻨﺎ ﻋﻠﻰ اﻟﺘﻌﺎﻣﻞ ﻣﻊ ال ‪ pointers‬ﻗﺒﻞ ان ﻧﻐﻮص ﻓﻲ‬ ‫اﻷﻣﺜﻠﺔ:‬ ‫اﻻﺳﺘﺨﺪام‬ ‫اﻷدوات‬ ‫ﺗﺴﺘﺨﺪم ﻟﺘﻌﺮﻳﻒ ‪pointer‬‬ ‫*‬ ‫ﻟﻤﻌﺮﻓﺔ ﻋﻨﻮان اﻟﻤﺘﻐﻴﺮ ﻓﻲ اﻟﺬاﻛﺮة‬ ‫&‬ ‫ﺗﺴﺘﺨﺪم ﻟﻠﻮﺻﻮل إﻟﻰ ﺣﻘﻞ ﻣﺎ داﺧﻞ اﻟﻔﺌﺔ اﻟﺘﻲ ﻳﺸﻴﺮ إﻟﻴﻬﺎ ال‬ ‫>-‬ ‫‪pointer‬‬ ‫- اﻟﺘﺤﺮك ﺿﻤﻦ اﻟﻤﺆﺷﺮات واﻟﻤﻘﺎرﻧﺔ وﺧﻼﻓﻪ.‬ ‫+،‬ ‫++، --،‬ ‫، ==، =!‬ ‫اﻟﺠﺪول 21. 2. ﻣﻌﺎﻣﻼت اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻤﺆﺷﺮات ﻓﻲ اﻟﺴﻲ ﺷﺎرب.‬‫ﻣﻊ اﺳﺘﻤﺮارﻧﺎ ﻓﻲ ﻫﺬا اﻟﺪرس ﺳﻮف ﺗﻜﺘﺸﻒ ان اﻟﺘﻌﺎﻣﻞ ﻣﻊ ال  ‪ unsafe code‬ﻟﻦ ﻳﻜﻮن ﺑﻨﻔﺲ ﺳﻬﻮﻟﺔ‬ ‫اﻟﻌﻤﻞ ﻓﻲ ‪ safe code‬ﻣﻦ ﺧﻼل ﺳﻲ ﺷﺎرب اﻟﻌﺎدﻳﺔ .‬ ‫وﻟﻜﻦ ﻟﻤﺎذا اﺳﺘﺨﺪم ال ‪ unsafe code‬؟‬ ‫• أﻏﺮاض ﺗﻌﻠﻴﻤﻴﺔ.‬ ‫• اﺳﺘﺨﺪاﻣﻚ ﻟﺒﻌﺾ ال ‪ dlls‬او ال ‪ COM  Components‬اﻟﺘﻲ ﺗﻌﻤﻞ اﺻﻼ ﻣﻦ ﺧﻼل‬ ‫ً‬ ‫‪.pointers‬‬ ‫• ﻣﺤﺎوﻟﺔ ﺗﺤﺴﻴﻦ اداء وﺳﺮﻋﺔ ﻣﻬﻤﺔ ﻣﻌﻴﻨﺔ ﻣﻦ ﺧﻼل اﻟﻮﺻﻮل اﻟﻤﺒﺎﺷﺮ ﻟﻠﺬاﻛﺮة .‬‫ﻓﻲ ﻣﺸﺮوع اﻟﺘﺨﺮج اﻟﺨﺎص ﺑﻨﺎ وأﺛﻨﺎء ﻗﺮاءة ‪ pixels‬ﺻﻮرة ﻣﺎ ﻟﻌﻤﻞ ﺑﻌﺾ ﻋﻤﻠﻴﺎت  ‪Image‬‬‫‪ Processing‬ﻛﺎن ﺑﺎﻣﻜﺎﻧﻨﺎ اﺳﺘﺨﺪام دوال ‪ GetPixel‬و ‪ SetPixel‬اﻟﺨﺎﺻﺔ ﺑﺎﻟﺼﻮر ﻟﻠﻘﺮاءة‬‫852‬
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬‫واﻟﻜﺘﺎﺑﺔ ، وﻟﻜﻨﻬﺎ ﻛﺎﻧﺖ ﻟﺘﻜﻮن ﻋﻤﻠﻴﺔ ﻃﻮﻳﻠﺔ ﺟﺪًا ﻟﻠﻤﺮور ﻋﻠﻰ اﻟـ‪ pixels‬ﺑﻬﺬه اﻟﻄﺮﻳﻘﺔ ، اﻟﺤﻞ‬‫اﻟﺒﺪﻳﻞ ﻛﺎن ﺑﺎﺳﺘﺨﺪام ‪ unsafe  code‬واﻟﺘﻌﺎﻣﻞ ﻣﻊ ال ‪ pointers‬ﻣﺒﺎﺷﺮة ﻟﻠﻤﺮور ﻋﻠﻰ ال ‪pixels‬‬‫اﻟﺨﺎﺻﺔ ﺑﺎﻟﺼﻮرة ، ﺟﺮب ﻣﺜﻼ ﻛﻮد ﻟﻄﺮح ﺻﻮرﺗﻴﻦ ﺑﺎﻟﻄﺮﻳﻘﺔ ‪ GetPixel‬و ‪، SetPixel‬‬ ‫ً‬ ‫وﺑﻌﺪ ﻫﺬه اﻟﺪرس ﺟﺮﺑﻬﺎ ﻣﺮة أﺧﺮى ﺑﺎﺳﺘﺨﺪام ‪ ،pointers‬وأﺧﺒﺮﻧﻲ ﺑﺎﻟﻔﺎرق ...‬ ‫اﻵن ﺳﻨﻌﻮد ﻣﺮة أﺧﺮى ﻟﻨﺸﺮح ﻣﻦ اﻟﺒﺪاﻳﺔ...‬ ‫ﻳﻤﻜﻨﻚ اﻵن ﺗﻌﺮﻳﻒ ‪ pointer‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;‪public Node* Left‬‬ ‫ﻟﻴﺲ ﻫﺬا ﻓﻘﻂ ، ﺑﻞ ﺑﺎﻣﻜﺎﻧﻚ ﺗﻌﺮﻳﻒ ‪ structure‬او ‪ class‬ﻣﻦ اﻟﻨﻮع ‪ unsafe‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪public unsafe struct Node‬‬ ‫{‬ ‫;‪public int Value‬‬ ‫;‪public Node* Left‬‬ ‫;‪public Node* Right‬‬ ‫}‬ ‫أو داﻟﺔ اﻳﻀﺎ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪unsafe static void SquareIntPointer(int* myIntPointer‬‬ ‫{‬ ‫.‪// Square the value just for a test‬‬ ‫;‪*myIntPointer *= *myIntPointer‬‬ ‫}‬‫وﻟﻤﺎ ﻛﻨﺎ ﻗﺪ اﺳﺘﺨﺪﻣﻨﺎ * ﻟﺘﻌﺮﻳﻒ اﻟﻤﺘﻐﻴﺮ ﻓﻲ اﻟﺒﺎرﻣﻴﺘﺮ ، إذن ﺳﻨﺮﺳﻞ اﻟﺒﺎرﻣﻴﺘﺮ ﺑﺎﺳﺘﺨﺪام &‬ ‫ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;)2‪SquareIntPointer(&myInt‬‬ ‫اﻳﻀﺎ ﻟﻠﻮﺻﻮل إﻟﻰ اﻟﻤﺘﻐﻴﺮ ‪ Value‬ﻓﻲ ال ‪ Node‬ﺳﻨﺴﺘﺨﺪم >- ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;5=‪n->Value‬‬‫952‬
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫ ؟‬VB.net ‫وﻣﺎذا ﻋﻦ‬‫ ﻓﻠﻦ ﻳﻤﻜﻨﻚ اﻻﺳﺘﻔﺎدة ﻣﻦ اﻟﻤﺆﺷﺮات ﻣﺒﺎﺷﺮة ، وﻟﻜﻦ ﺗﻮﻓﺮ ﻟﻚ اﻟﻔﺌﺔ‬VB.net ‫ﻟﻮ ﻛﻨﺖ ﻣﺒﺮﻣﺞ‬‫ ﻣﺤﺎﻛﺎة‬System.Runtime.InteropServices ‫ اﻟﺘﺎﺑﻌﺔ ﻟﻤﺠﺎل اﻷﺳﻤﺎء‬Marshal : C# ‫ﻗﺮﻳﺒﺔ ﻣﻦ ﻋﺎﻟﻢ اﻟﻤﺆﺷﺮات ، ﻟﻨﻔﺘﺮض اﻟﻜﻮد اﻟﺘﺎﻟﻲ‬ C# ‫ﻛﻮد‬ Bitmap bitmap = new Bitmap(this.BackgroundImage); unsafe { System.Drawing.Imaging.BitmapData bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), 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; } : ‫ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬VB ‫ﺳﻴﺘﻢ ﺗﻄﺒﻴﻘﻬﺎ ﻓﻲ‬ VB.NET ‫ﻛﻮد‬ Dim bitmap As New Bitmap(Me.BackgroundImage) Dim width As Integer = bitmap.Width Dim height As Integer = bitmap.Height Dim bmpData As System.Drawing.Imaging.BitmapData = _ bitmap.LockBits(New Rectangle(0, 0, width, height) _ , System.Drawing.Imaging.ImageLockMode.ReadWrite, _ PixelFormat.Format32bppArgb) System.Runtime.InteropServices.Marshal.WriteByte(bmpData.Scan0, bmpData.Stride, 255) System.Runtime.InteropServices.Marshal.WriteByte(bmpData.Scan0, bmpData.Stride + 4, 0) bitmap.UnlockBits(bmpData) . ‫*** ﻣﻊ اﻟﺸﻜﺮ ﻟﻸخ وﻟﻴﺪ ﺻﺎﺣﺐ اﻟﻤﺜﺎل‬260
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫41. ‪Query Expressions‬‬ ‫ﺗﻌﺘﺒﺮ ال  ‪ Query Expressions‬ﻫﻲ اﻟﺨﻄﻮة اﻷوﻟﻰ واﻷﺳﺎﺳﻴﺔ ﻓﻲ ﻋﺎﻟﻢ ‪ ، LINQ‬ﺳﻨﺘﻌﺮف ﻋﻠﻴﻬﺎ ﻫﻨﺎ‬ ‫ﺑﺎﺧﺘﺼﺎر ﺷﺪﻳﺪ ﻛﻤﻴﺰة ﺟﺪﻳﺪة ﻣﻦ ﻣﻤﻴﺰات 8002  ‪ .net‬ﻓﻴﻤﺎ ﺳﻨﺆﺟﻞ ﺑﺎﻗﻲ اﻟﺘﻔﺎﺻﻴﻞ ﻟﻠﻔﺼﻮل‬ ‫اﻟﻘﺎدﻣﺔ ﺣﻴﻨﻤﺎ ﻧﺒﺪأ اﻟﺘﻌﺎﻣﻞ اﻟﻔﻌﻠﻲ ﻣﻊ ﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت.‬ ‫ﻟﻨﺮى ﻫﺬا اﻟﻤﺜﺎل ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪from d in developers‬‬ ‫"#‪where d.Language =="C‬‬ ‫;‪select d.Name‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫_ )(‪From d In developers‬‬ ‫_ )"#‪Where(d.Language = "C‬‬ ‫‪Select d.Name‬‬ ‫ﻫﺬا ﺑﺎﻟﻀﺒﻂ ﻫﻮ ﻣﺤﺘﻮى ﺟﻤﻠﺔ اﻻﺳﺘﻌﻼم اﻟﺘﻲ ﺗﻌﻮدت ﻋﻠﻰ ﻛﺘﺎﺑﺘﻬﺎ ﺳﺎﺑﻘﺎ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻓﻲ ال ‪:SQL‬‬ ‫ً‬ ‫‪SQL‬‬ ‫ﻛﻮد‬ ‫"#‪Select name from developers where language = "C‬‬ ‫إذن ﻟﻤﺎذا ﻫﺬا اﻟﺸﻜﻞ اﻟﺠﺪﻳﺪ ؟‬ ‫ﻓﻲ اﻟﺴﺎﺑﻖ ﻛﻨﺎ ﻧﻘﻮم ﺑﺎرﺳﺎل ﺟﻤﻠﺔ اﻻﺳﺘﻌﻼم ﻟﻴﺘﻢ ﺗﻨﻔﻴﺬﻫﺎ ﻓﻲ ﻗﺎﻋﺪة اﻟﺒﻴﺎﻧﺎت وﺗﻌﻮد ﺑﻨﺎﺗﺞ ﻋﻠﻰ‬ ‫ﺷﻜﻞ ‪ DataReader‬أو ﻣﻬﻤﺎ ﻳﻜﻦ ، أﻣﺎ اﻵن اﺻﺒﺤﺖ ﺟﻤﻞ اﻻﺳﺘﻌﻼم ﺟﺰء ﻣﻦ ﻣﺤﺘﻮﻳﺎت اﻟﻠﻐﺔ اﻟﺘﻲ‬ ‫ﺗﻘﻮم ﺑﺒﺮﻣﺠﺘﻬﺎ.‬ ‫ﻟﺘﻌﻤﻞ ﻋﻠﻰ ‪ LINQ‬ﻓﻼ ﺑﺪ ﻣﻦ ﺗﻮرﻳﺪ ﻣﺠﺎل اﻷﺳﻤﺎء ﻫﺬا:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;‪using System.Linq‬‬ ‫162‬
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Imports System.Linq‬‬ ‫ﺗﻌﺘﻤﺪ ال ‪ LINQ‬ﻋﻠﻰ ان ﻗﺎﻋﺪة اﻟﺒﻴﺎﻧﺎت ﻫﻲ ﻋﺒﺎرة ﻋﻦ ‪ Array‬أو أي ﺟﺰء ﻣﻨﻬﺎ ، ﻟﺬا ﺳﻨﺠﺮب ﺑﻌﺾ‬ ‫اﻟﻌﻤﻠﻴﺎت ﻋﻠﻰ ال ‪ ، Array‬ﻟﻨﻔﺘﺮض اﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫;}"‪string[] userNames = {"Ahmed", "Ali","Mohammed", "Ahmed","Ramy", "Khaled‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫,"‪Dim userNames As String() = {"Ahmed", "Ali", "Mohammed", "Ahmed", "Ramy‬‬ ‫}"‪"Khaled‬‬‫*** ﻟﻦ اذﻛﺮك ﻛﺜﻴﺮًا ﺑﺄﻧﻨﻲ ﻫﻨﺎ ﻻ اﻫﺘﻢ ﺑـ ‪ LINQ‬ﻗﺪر ﻣﺎ اﻫﺘﻢ ﺑﺎل ‪ ، Query Expressions‬اﻟﻔﺎرق‬‫ﻫﻮ ان اﻷوﻟﻰ ﺧﺎﺻﺔ ﺑﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ ﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت ﺑﻤﺨﺘﻠﻒ اﻧﻮاﻋﻬﺎ اﻣﺎ اﻟﺜﺎﻧﻴﺔ ﻓﻬﻲ ﺗﻌﻠﻤﻚ ﻛﻴﻔﻴﺔ‬ ‫اﻟﻜﺘﺎﺑﺔ ﻓﻘﻂ دون اﻟﺘﻄﺮق ﻟﺨﺼﺎﺋﺺ ﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت‬‫ﻫﺬه اﻟﻤﺼﻔﻮﻓﺔ ﻗﺪ ﺗﻜﻮن ﻗﺎﻋﺪة ﺑﻴﺎﻧﺎت ، ﻗﺪ ﺗﻜﻮن ﻣﻠﻒ ‪ ، XML‬ﻗﺪ ﺗﻜﻮن أي ﺷﻲء آﺧﺮ ، اﻵن ﺳﻨﺤﺎول‬ ‫ﺑﻨﺎء ﺟﻤﻠﺔ اﺳﺘﻌﻼم ﻟﻘﺮاءة اﻻﺳﻤﺎء اﻟﺘﻲ ﺗﺴﺎوي"‪"Ahmed‬‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪IEnumerable<string> subset = from users in userNames‬‬ ‫;‪where users == "Ahmed" orderby users select users‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫= ‪Dim subset As IEnumerable = From users In userNames Where users‬‬ ‫‪"Ahmed"OrderBy users Select users‬‬ ‫اﻟﻨﺎﺗﺞ ﺳﻴﻜﻮن اﻳﻀﺎ ‪ ، array‬ﻟﺬا ﻳﻤﻜﻨﻚ اﻵن ﻃﺒﺎﻋﺘﻬﺎ ﺑﺒﺴﺎﻃﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ:‬ ‫ً‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)‪foreach (string s in subset‬‬ ‫;)‪Console.WriteLine("Item: {0}", s‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪For Each s As String In subset‬‬ ‫)‪Console.WriteLine("Item: {0}", s‬‬ ‫‪Next‬‬‫262‬
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫ﻳﻤﻜﻨﻚ ﺑﺎﻟﻄﺒﻊ اﺳﺘﺨﺪام اي داﻟﺔ ﻣﻦ دوال  #‪ ، C‬ﻟﺬا ﻓﺎﻟﺠﻤﻠﺔ اﻟﺘﺎﻟﻴﺔ ﺻﺤﻴﺤﺔ ﻟﻌﺮض اﻻﺳﻤﺎء اﻃﻮل‬ ‫ﻣﻦ ﺛﻼث ﺣﺮوف:‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪IEnumerable<string> subset = from users in userNames‬‬ ‫3 > ‪where users.Length‬‬ ‫‪orderby users‬‬ ‫;‪select users‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫)3 > ‪Dim subset As IEnumerable = From users In userNames Where (users.Length‬‬ ‫‪OrderBy users Select users‬‬‫اﻳﻀﺎ ﻗﺪ ﻻ ﺗﻜﻮن ﻗﺎدرًا ﻋﻠﻰ ﻣﻌﺮﻓﺔ ﻧﻮع اﻟﺒﻴﺎﻧﺎت اﻟﻈﺎﻫﺮ ، ﺧﺼﻮﺻﺎ ﻟﻮ ﻛﻨﺖ ﺗﺴﺘﻌﻠﻢ ﻋﻦ اﻛﺜﺮ ﻣﻦ‬ ‫ً‬ ‫ً‬‫ﺣﻘﻞ ﺣﻴﺚ ان اﻟﻨﺎﺗﺞ ﻻ ﺑﺪ ان ﻳﻜﻮن ﻓﺌﺔ ، ﻫﻨﺎ ﺗﻈﻬﺮ ﻟﻨﺎ ﻓﺎﺋﺪة ال ‪ var‬أو ال ‪ Dim‬ﺑﺪون‪Data Type‬‬ ‫اﻟﺘﻲ ﺷﺮﺣﻨﺎﻫﺎ ﺳﺎﺑﻘﺎ ، اﻳﻀﺎ رﺑﻤﺎ ﻻ ﺗﻌﻮد ﺟﻤﻠﺔ اﻻﺳﺘﻌﻼم ﺑﻨﺘﻴﺠﺔ ﻟﺬا ﺳﻨﺴﺘﺮﺟﻊ ﻫﻨﺎ ﻓﺎﺋﺪة ال‬ ‫ً‬ ‫ً‬ ‫ ‪ Nullable Types‬واﻟﺘﻲ ﺷﺮﺣﻨﺎﻫﺎ اﻳﻀﺎ ﻓﻲ درس ﺳﺎﺑﻖ.‬ ‫ً‬ ‫ﻃﺮﻳﻘﺔ أﺧﺮى ﻟﻜﺘﺎﺑﺔ ﻫﺬه اﻟﺠﻤﻞ ﺑﺎﺳﺘﺨﺪام ‪ ،Lambda‬وﺳﻨﺘﻌﺮف ﻋﻠﻴﻬﺎ ﻓﻲ ﻣﺮﺣﻠﺔ ﻗﺎدﻣﺔ.‬ ‫51. ‪Preprocessor Directives‬‬‫ﻛﺜﻴﺮًا ﺧﻼل ﺗﺼﻔﺤﻚ ﻟﻠﺒﺮاﻣﺞ او ﻟﻠﻤﺸﺎرﻳﻊ اﻟﺠﺎﻫﺰة أو ﺣﺘﻰ ﻟﻼدوات ﻓﻲ ﺑﺮﻧﺎﻣﺠﻚ ﻣﺎ ﺗﻌﺜﺮ ﻋﻠﻰ‬ ‫اﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ:‬ ‫ً‬‫وﻛﻨﺖ ﻋﻠﻰ ﺣﺪ ﻋﻠﻤﻚ ﺗﻌﺮف اﻧﻬﺎ ﻃﺮﻳﻘﺔ ﻟﻮﺿﻊ ﻣﺠﻤﻮﻋﺔ ﻣﻦ اﻻﻛﻮاد ﺿﻤﻦ ﺣﺪود ﻣﻌﻴﻨﺔ ﺑﺤﻴﺚ‬‫ﻳﺘﻢ ﻓﺘﺤﻬﺎ واﻏﻼﻗﻬﺎ ﺑﺴﻬﻮﻟﺔ ﻟﻀﻤﺎن ﻋﺪم اﻟﺘﺸﻮﻳﺶ ﻟﻚ أﺛﻨﺎء ﻛﺘﺎﺑﺘﻚ اﻟﻜﻮد ، إﻻ ان ﻣﺎ ﺳﺘﻌﺮﻓﻪ ﻓﻲ‬‫362‬
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬‫ اﻟﺘﻲ‬Preprocessor  Directives ‫ وﺧﻼﻓﻬﺎ ﻫﻲ ﻣﺠﻤﻮﻋﺔ ﻣﻦ ال‬Regions ‫ﻫﺬا اﻟﺪرس أن ﻫﺬه ال‬ .‫ﺳﻨﺘﻌﺮف ﻋﻠﻴﻬﺎ ﺗﻔﺼﻴﻼ ﻓﻲ ﻫﺬا اﻟﺪرس‬ ً #region, #endregion .1 .15 ‫ﺗﺴﺘﺨﺪم ﻋﺎدة ﻟﺘﻨﺴﻴﻖ ﻣﻈﻬﺮ اﻟﻜﻮد ﻓﻲ ﻣﻠﻒ اﻟﺸﻔﺮة اﻟﺨﺎص ﺑﻚ ﻛﻤﺎ ذﻛﺮﻧﺎ ﺳﺎﺑﻘﺎً، ﻳﻤﻜﻦ ﻛﺘﺎﺑﺘﻬﺎ‬ :‫ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ‬ ً 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; } } public string name { get { return _salary; } set { _salary = value; } } } #endregion264
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ VB.NET ‫ﻛﻮد‬ #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(ByVal value As String) _name = value End Set End Property Public Property age() As String Get Return _age End Get Set(ByVal value As String) _age = value End Set End Property Public Property name() As String Get Return _salary End Get Set(ByVal value As String) _salary = value End Set End Property End Class #End Region :‫اﻵن ﻳﻤﻜﻨﻚ ﻓﺘﺤﻬﺎ واﻏﻼﻗﻬﺎ ﻣﻦ اﻟﻄﺮف ، ﺑﺤﻴﺚ ﻳﻜﻮن ﻛﻮدك ﻣﻨﻈﻤﺎ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ ﻣﺜﻼ‬ ً ً265
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫اﻟﺼﻮرة 21. 3. اﺳﺘﻌﻤﺎل ﺧﺎﺻﻴﺔ ال ‪#region #endregion‬‬ ‫51. 2. ‪#if, #elif, #else, #endif‬‬‫ﻳﻄﻠﻖ ﻋﻠﻴﻬﺎ اﺳﻢ ‪ ، Conditional Code Compilation‬وﺗﺴﺘﺨﺪم ﻟﺘﻨﻔﻴﺬ اﺟﺰاء ﻣﻌﻴﻨﺔ ﻣﻦ اﻟﻜﻮد ﻓﻲ‬‫ﺣﺎﻻت ﻣﻌﻴﻨﺔ ﻓﻘﻂ ، ﻓﻤﺜﻼ ﻟﺠﻌﻞ ﺟﺰء ﻣﻦ اﻟﻜﻮد ﻻ ﻳﻌﻤﻞ ﻓﻘﻂ إﻻ وﻗﺖ ال ‪ Debug‬وﻟﻴﺲ ﻓﻲ وﻗﺖ‬ ‫ً‬ ‫ال ‪ Release‬ﻧﻜﺘﺐ اﻟﻜﻮد ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬‫662‬
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ C# ‫ﻛﻮد‬ #if DEBUG 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); #endif VB.NET ‫ﻛﻮد‬ #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 ‫ﺑﻨﻔﺲ اﻟﻄﺮﻳﻘﺔ ﻳﻤﻜﻦ اﺳﺘﺨﺪام‬ #define, #undef .3 .15 ‫ ، او ﻳﻤﻜﻨﻚ ﺗﻌﺮﻳﻒ‬Debug ‫ ﻟﻞ‬symbol ‫ ﻣﻌﻴﻦ ، ﻣﺜﻼ ﻳﻤﻜﻨﻚ ﺗﻌﺮﻳﻒ‬symbol ‫ﺗﺴﺘﺨﺪم ﻟﺘﻌﺮﻳﻒ‬ ً‫ ﻳﻌﻨﻲ ان‬Symbol ‫ ﺧﺎص ﺑﻚ ﺑﺄي اﺳﻢ ﻟﻴﺘﻢ اﺳﺘﺨﺪاﻣﻪ ﻻﺣﻘﺎ ، اﻟﻤﺜﺎل اﻟﺘﺎﻟﻲ ﻣﺜﻼ ﻟﺘﻌﺮﻳﻒ‬symbol ً . Mono ‫ ﻟﻪ ﻓﻘﻂ ﻋﻠﻰ‬Debug ‫ﻫﺬا اﻟﻜﻮد ﻳﺘﻢ ﻋﻤﻞ‬ .‫اﻟﺼﻮرة 21. 4. ﺧﺼﺎﺋﺺ اﻟﻤﺸﺮوع، اﺿﺎﻓﺔ رﻣﻮز ﺗﺮﺟﻤﺔ إﻟﻰ اﻟﻤﺸﺮوع‬ :‫ﻻﺣﻘﺎ ﻳﻤﻜﻨﻚ ﻛﺘﺎﺑﺔ ﻛﻮد ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ ً267
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ C# ‫ﻛﻮد‬ #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.NET ‫ﻛﻮد‬ #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() #End If End Sub End Class End Namespace268
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫61. ‪XML Commenting‬‬‫ﻓﻲ اﻟﻮاﻗﻊ ﻓﺈن ﻋﻤﻞ ‪ Comments‬ﻟﻸﻛﻮاد ﻳﻌﺪ أﻣﺮًا ﻓﻲ ﻏﺎﻳﺔ اﻷﻫﻤﻴﺔ ﺧﺼﻮﺻﺎ ﻓﻲ ﺣﺎﻟﺔ‬ ‫ً‬‫اﻟﻤﺸﺎرﻳﻊ اﻟﻜﺒﻴﺮة ، ﺣﻴﺚ ﺗﺴﺘﻄﻴﻊ ﻣﺮاﻗﺒﺔ ﻛﻮدك ﻛﻤﺎ ﻳﺴﺘﻄﻴﻊ اي ﺷﺨﺺ آﺧﺮ ﺑﻘﻠﻴﻞ ﻣﻦ اﻟﺠﻬﺪ‬ ‫ﻣﻌﺮﻓﺔ ﻛﻮدك واﻻﻛﻤﺎل ﻋﻠﻴﻪ ﺣﺘﻰ وﻟﻮ ﺑﻌﺪ ﺗﻮﻗﻔﻚ ﻋﻦ اﻟﻌﻤﻞ ﻓﻲ ﻧﻔﺲ اﻟﻜﻮد ﺑﻔﺘﺮة ﻃﻮﻳﻠﺔ ﺟﺪًا.‬ ‫وﻛﻤﺎ ﻋﺮﻓﻨﺎ ﻓﻲ ﺑﺪاﻳﺎت ﻫﺬه اﻟﺪروس ، ﻳﺘﻢ ﻋﻤﻞ ال ‪ Comment‬ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪// here we will do something, set x=startvalue‬‬ ‫;)(‪x = FirstClass.Default‬‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪ here we will do something, set x=startvalue‬‬ ‫)(‪x = FirstClass.Default‬‬‫اﻵن ﺳﻨﺘﻌﺮف ﻋﻠﻰ ﻃﺮﻳﻘﺔ ﺟﺪﻳﺪة ، ﺗﻤﻜﻨﻨﺎ ﻣﻦ ﻛﺘﺎﺑﺔ ال ‪ Comments‬ﺑﺄﺳﻠﻮب ‪ XML‬ﺑﻤﺎ ﻳﻮﻓﺮ ﻟﻨﺎ‬ ‫ﻋﺪة ﻣﺰاﻳﺎ ﺳﻨﺘﻌﺮف ﻋﻠﻴﻬﺎ ﺧﻼل اﻟﺪرس.‬ ‫ﻣﻼﺣﻈﺔ‬ ‫ﻣﻦ اواﺋﻞ اﻟﻠﻐﺎت اﻟﺘﻲ ﻃﺒﻘﺖ ﻫﺬه اﻟﻄﺮﻳﻘﺔ ﻛﺎﻧﺖ ‪ Java‬ﻣﻦ ﺧﻼل ‪.javadoc‬‬‫ﻳﺘﻢ ذﻟﻚ ﺑﺪاﻳﺔ ﻣﻦ ﺧﻼل وﺿﻊ /// ، ﺑﻌﺪ وﺿﻊ ﻫﺬه اﻟﻌﻼﻣﺔ ﺗﺴﺘﻄﻴﻊ وﺿﻊ أي ﻋﻼﻣﺎت ﺧﺎﺻﺔ ﺑﻚ‬‫ﻟﻠﻜﻮد واﻟﺬي ﺳﻴﺘﻢ اﻟﺘﻌﺎﻣﻞ ﻣﻊ ﻻﺣﻘﺎ ﻋﻠﻰ أن ‪ XML‬ﻣﺎ دام ﻳﻄﺒﻖ ﻣﺒﺎدئ ‪ ،XML‬ﻫﻨﺎك ﻣﺠﻤﻮﻋﺔ ﻣﻦ‬ ‫ً‬ ‫اﻟﻌﻨﺎﺻﺮ اﻟﻘﻴﺎﺳﻴﺔ اﻟﺘﻲ ﻳﻔﻀﻞ اﺳﺘﺨﺪاﻣﻬﺎ ﻟﺘﻮﺣﻴﺪ اﻟﻤﻔﺎﻫﻴﻢ.‬ ‫اﻻﺳﺘﺨﺪام‬ ‫اﻟﻌﻨﺼﺮ‬ ‫ﻟﺘﺤﺪﻳﺪ ان اﻟﻼﺣﻖ ﻻ ﺑﺪ أن ﻳﻌﺮض ﺑﺨﻂ ﻣﺨﺘﻠﻒ‬ ‫>‪<c‬‬ ‫ﻟﺘﺤﺪﻳﺪ ان ﺗﻌﺪد اﻻﺳﻄﺮ ﺳﻴﺘﻢ اﻟﺘﻌﺎﻣﻞ ﻣﻌﻪ ﻛﻜﻮد‬ ‫>‪<code‬‬ ‫ﺗﺤﺪﻳﺪ ﻣﺜﺎل ﻟﺸﺮح اﻟﻜﻮد اﻟﻤﻜﺘﻮب‬ ‫>‪<example‬‬ ‫اﻟﻤﻠﻒ اﻟﺬي ﻳﺤﺘﻮي ﻋﻠﻰ اﻻﺳﺘﺜﻨﺎءات واﻷﺧﻄﺎء اﻟﺘﻲ ﻳﻤﻜﻦ ان ﺗﻨﺘﺞ ﻋﻦ ﻫﺬا‬ ‫>‪<exception‬‬‫962‬
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ Documentation‫ادراج ﻗﺎﺋﻤﺔ ﺟﺪاول داﺧﻞ ال‬ <list> ‫ﻟﺸﺮح ﺑﺎرﻣﻴﺘﺮ ﻣﻌﻴﻦ‬ <param> ‫< وﺻﻒ وﺳﺎﺋﻞ اﻟﺤﻤﺎﻳﺔ ﻟﺠﺰء ﻣﻌﻴﻦ‬permission> Build‫ﺧﻴﺎرات ال‬ <remarks> return; ‫وﺻﻒ ﻧﺎﺗﺞ اﻟﺪاﻟﺔ‬ <returns> Documentation‫راﺑﻂ آﺧﺮ ﻟﺠﺰء آﺧﺮ ﻣﻦ ال‬ <see> (‫ﻣﺜﻞ اﻟﺴﺎﺑﻖ، وﻟﻜﻦ )اﻧﻈﺮ اﻳﻀﺎ‬ ً <seealso> ‫وﺻﻒ اﺟﻤﺎﻟﻲ ﻟﻠﺠﺰء اﻟﻤﺸﺮوح‬ <summary> ‫ﻟﻮﺻﻒ ﺧﺎﺻﻴﺔ ﻣﻌﻴﻨﺔ‬ <value> XML Documentation ‫اﻟﺠﺪول 21. 3. وﺳﻮم ﺗﻌﻠﻴﻘﺎت ال‬ ‫واﻵن، ﻣﺎ ﻫﻲ اﻟﻔﺎﺋﺪة اﻟﺘﻲ ﺳﺘﺠﻨﻴﻬﺎ إذا اﺳﺘﺨﺪﻣﺖ ﻫﺬه اﻟﻄﺮﻳﻘﺔ ﺑﺪﻻ ﻣﻦ اﻟﻄﺮﻳﻘﺔ اﻟﺘﻘﻠﻴﺪﻳﺔ ؟؟؟‬ ً :‫أوﻻ ، ﺟﺮب ﻣﺜﻼ ﻛﺘﺎﺑﺔ ﻣﺎ ﻳﻠﻲ ﻟﻔﺌﺔ اﻟﻤﻮﻇﻔﻴﻦ ﻣﺜﻼ‬ ً ً ً 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) { } }270
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ VB.NET ‫ﻛﻮد‬ <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 Sub New(ByVal Firstname As String, ByVal Lastname As String, ByVal age As Integer) End Sub End Class :‫وﺟﺮب اﻵن ﻋﻤﻞ اﻟﻜﻮد ، ﻻﺣﻆ اﻟﺼﻮرة اﻟﺘﺎﻟﻴﺔ‬ .XML ‫اﻟﺼﻮرة 21. 5. اﺳﺘﻌﻤﺎل ﺗﻌﻠﻴﻘﺎت ال‬ ‫ﻫﻞ ﻻﺣﻈﺖ اﻟﻔﺎرق ، اﺻﺒﺢ اﻟﻜﻮد ﻳﻈﻬﺮ واﺿﺤﺎ ﻟﺒﺎﻗﻲ ﻣﺒﺮﻣﺠﻲ ﻓﺮﻳﻘﻚ ، اﻟﻴﺲ ﻛﺬﻟﻚ ؟‬ ً Documentation ‫ﻧﻘﻄﺔ أﺧﺮى‬‫ ﻛﺎﻣﻠﺔ ﻟﻤﺸﺮوﻋﻚ‬Documentation ‫ ، ﻳﻤﻜﻨﻚ اﺧﺮاج‬Build ‫اﻳﻀﺎ وﻣﻦ ﺿﻤﻦ ﺧﻴﺎرات ال‬ ً‫ وﻗﻢ ﺑﺎﺧﺘﻴﺎر اﻧﺘﺎج ﻣﻠﻒ‬Build ‫اﻋﺘﻤﺎدًا ﻋﻠﻰ ﻫﺬه اﻟﻮﺳﻮم ، ﻟﺬا ﻣﻦ ﺧﺼﺎﺋﺺ اﻟﻤﺸﺮوع ﻗﻢ ﺑﺎﺧﺘﻴﺎر‬ :‫ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬XML271
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫اﻟﺼﻮرة 21. 6. ﺿﺒﻂ ﺧﻴﺎرات اﻟﻤﺸﺮوع ﻟﺒﻨﺎء ﻣﻠﻒ ال ‪Documentation‬‬ ‫ﺟﺮب اﻟﻮﺻﻮل ﻟﻬﺬا اﻟﻤﻠﻒ اﻟﺬي ﻗﻤﺖ ﺑﺎﺧﺘﻴﺎره، ﺳﺘﺠﺪ ﺷﻴﺌﺎ ﻣﺜﻞ ﻫﺬا:‬ ‫ً‬ ‫اﻟﺼﻮرة 21. 7. ﻣﻠﻒ ال ‪ Documentation‬اﻟﻨﺎﺗﺞ.‬ ‫272‬
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫ﻧﻘﻄﺔ ﺛﺎﻟﺜﺔ ‪ Documentation‬ﻣﺮة أﺧﺮى‬‫ﻟﻼﺳﻒ ﻻ ﻳﻮﻓﺮ 8002  ‪ Visual  Studio‬اداة اﻓﺘﺮاﺿﻴﺔ ﻟﺘﺤﻮﻳﻞ ال ‪ XML‬اﻟﺴﺎﺑﻖ ﻟﺼﻴﻐﺔ‬ ‫ﻣﻔﻬﻮﻣﺔ ، ﻟﻜﻦ ﻳﻤﻜﻦ اﺳﺘﺨﺪام أداة ﻣﺜﻞ ‪ NDoc‬ﻟﺘﺤﻮﻳﻞ اﻟﻤﻠﻒ اﻟﺴﺎﺑﻖ إﻟﻰ ﻣﺜﻞ ﻫﺬه اﻟﺼﻮرة:‬‫‪ Documetation‬إﻟﻰ ﻣﻠﻔﺎت ﻣﺴﺎﻋﺪة‬ ‫اﻟﺼﻮرة 21. 8. ﺑﺮﻧﺎﻣﺞ ال ‪ NDoc‬ﻟﺘﺤﻮﻳﻞ ﻣﻠﻔﺎت ال‬ ‫)‪.(Help‬‬ ‫ﻛﻞ ﻫﺬا ﻓﻘﻂ ﻣﻦ ال ‪... Comments‬‬ ‫ﻳﻤﻜﻨﻚ اﻟﻮﺻﻞ إﻟﻰ ﻧﺴﺨﺔ ﻋﻠﻰ ال ‪ Sourceforge‬ﻣﻦ اﻟﺮاﺑﻂ اﻟﺘﺎﻟﻲ :‬ ‫راﺑﻂ‬ ‫/‪http://ndoc.sourceforge.net‬‬‫372‬
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫71. ‪.net Assemblies‬‬ ‫ﻣﻮﻋﺪﻧﺎ ﻫﺬه اﻟﻔﺘﺮة ﻣﻊ ال ‪ ، .net assemblies‬ﻟﻦ ﻧﻄﻴﻞ ﻓﻴﻬﺎ ﻛﺜﻴﺮًا وﻟﻜﻨﻨﺎ ﺳﻨﻌﺮف اﻟﻨﻘﺎط اﻻﺳﺎﺳﻴﺔ‬ ‫ﻓﻴﻬﺎ ﻓﻴﻤﺎ ﻳﻤﻜﻨﻚ اﻻﻃﻼع ﻋﻠﻰ اﻟﻤﺰﻳﺪ ﻋﻨﻬﺎ ﻣﻦ ﺧﻼل ‪MSDN‬‬ ‫اﻟـ ‪namespace‬‬ ‫71. 1.‬ ‫ﻓﻲ ﻧﻔﺲ ال ‪ namespace‬ﻳﻤﻜﻦ ﻟﺠﻤﻴﻊ اﻟﻤﻜﻮﻧﺎت ﺗﺤﺘﻪ ان ﺗﺮى ﺑﻌﻀﻬﺎ اﻟﺒﻌﺾ ، ﻟﺬا دوﻣﺎ‬ ‫ً‬ ‫وﻓﻲ ﻣﺸﺎرﻳﻌﻚ اﻟﺠﺪﻳﺪة اﺟﻌﻞ ‪ namespace‬ﻣﻮﺣﺪ ﻟﺠﻤﻴﻊ ﻣﻜﻮﻧﺎت ﺑﺮﻧﺎﻣﺠﻚ‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫‪namespace example‬‬ ‫{‬ ‫‪class someclass‬‬ ‫{‬ ‫)(‪void method‬‬ ‫{‬ ‫}‬ ‫}‬ ‫}‬ ‫‪VB.NET‬‬ ‫ﻛﻮد‬ ‫‪Namespace example‬‬ ‫‪Class someclass‬‬ ‫)(‪Private Sub method‬‬ ‫‪End Sub‬‬ ‫‪End Class‬‬ ‫‪End Namespace‬‬ ‫أﻣﺎ ﻟﻮ ﻛﺎن ﻟﺪﻳﻨﺎ ﻓﺌﺔ ‪ classCar‬ﻓﻲ ‪ namespace‬ﺑﺎﺳﻢ آﺧﺮ، ﻓﻠﻦ ﻳﻤﻜﻨﻚ ﻛﺘﺎﺑﺔ اﻟﻜﻮد اﻟﺘﺎﻟﻲ‬ ‫ﺿﻤﻦ اﻟﺪاﻟﺔ اﻟﺴﺎﺑﻘﺔ ‪method‬‬ ‫#‪C‬‬ ‫ﻛﻮد‬ ‫)(‪void method‬‬ ‫{‬ ‫;)(‪classCar x = new classCar‬‬ ‫}‬ ‫472‬
  • .net ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال‬   ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ VB.NET ‫ﻛﻮد‬ Private Sub method() Dim x As New classCar() End Sub ‫ ﻟﺘﺘﻤﻜﻦ ﻣﻦ ﺗﻌﺮﻳﻒ اﻟﻔﺌﺔ ﺑﺎﻟﺸﻜﻞ اﻟﺘﺎﻟﻲ‬example ‫ ﻟﻞ‬import ‫ﻟﻜﻦ ﻳﻤﻜﻨﻨﺎ ﻋﻤﻞ‬ C# ‫ﻛﻮد‬ using example; namespace example { class someclass { void method() { } classCar x=new classCar(); } } VB.NET ‫ﻛﻮد‬ Imports example Namespace example Class someclass Private Sub method() End Sub Private x As New classCar() End Class End Namespace Default Namespace ‫71. 2. ﺗﻐﻴﻴﺮ ال‬ :‫ﻟﺘﻐﻴﻴﺮ ﻣﺠﺎل اﻻﺳﻤﺎء اﻻﻓﺘﺮاﺿﻲ‬ .‫اﻟﺼﻮرة 21. 9. ﺗﻐﻴﻴﺮ ﻣﺠﺎل اﻷﺳﻤﺎء اﻻﻓﺘﺮاﺿﻲ ﻣﻦ ﺧﺼﺎﺋﺺ اﻟﻤﺸﺮوع‬275
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫71. 3. ﺷﻜﻞ ﻣﻠﻒ اﻻﺳﻤﺒﻠﻲ  ‪Format of a .NET‬‬ ‫‪Assembly‬‬‫إذا ﻗﻤﺖ ﺑﻔﺘﺢ ﻣﻠﻒ اﻻﺳﻤﺒﻠﻲ ب  ‪ dumpbin.exe‬ﻣﺜﻼ ﻳﻤﻜﻨﻚ ان ﺗﻼﺣﻆ أن ﻣﻜﻠﻒ اﻻﺳﻤﺒﻠﻲ‬ ‫ً‬ ‫ﻳﺘﻜﻮن ﻣﻦ اﻟﻌﻨﺎﺻﺮ اﻟﺘﺎﻟﻴﺔ:‬ ‫‪Win32 file header‬‬‫ﻫﻨﺎ ﺳﺘﺠﺪ ﻣﻌﻠﻮﻣﺎت ﻋﻦ ﻧﻮع ﻫﺬا اﻟﻤﻠﻒ ، ﻫﻞ ﻫﻮ ‪ console‬ام ‪ GUI‬ام ‪ Dll‬وﻛﻴﻔﻴﺔ ﺗﻨﻔﻴﺬه‬ ‫ﻋﻠﻰ ﻧﻈﻢ اﻟﺘﺸﻐﻴﻞ ﻣﻦ وﻳﻨﺪوز .‬ ‫‪CLR file header‬‬‫ﻳﺤﺘﻮي ﻋﻠﻰ اﻟﻤﻌﻠﻮﻣﺎت اﻟﺘﻲ ﻻ ﺑﺪ ﻷي ‪ .net application‬ان ﻳﺪﻋﻤﻬﺎ ، ﻳﺤﺘﻮي ﻋﻠﻰ ﻃﺮﻳﻘﺔ‬ ‫ﻛﺘﺎﺑﺔ ال ‪ managed file‬ووﺟﻮد ال ‪ resources‬ﻣﻦ ﻋﺪﻣﻪ وﺧﻼﻓﻪ.‬‫ﻻ ﺗﻬﻤﻚ ﻛﺜﻴﺮًا اﻟﻤﻌﻠﻮﻣﺎت اﻟﺴﺎﺑﻘﺔ ﻟﻠﻨﻘﻄﺘﻴﻦ اﻟﺴﺎﺑﻘﺘﻴﻦ ، ﻹﻧﻚ ﻟﻦ ﺗﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﺳﻮى إذا ﻣﺎ ﻛﻨﺖ‬ ‫ﺗﺤﺘﺎج ﻟﺒﻨﺎء ﻛﻮﻣﺒﺎﻳﻠﺮ ﺧﺎص ﺑﻚ ﺗﺤﺖ ﺑﻴﺌﺔ ﻋﻤﻞ ‪. .net‬‬ ‫‪CIL code‬‬‫اﻟﻜﻮد اﻟﺨﺎص ﺑﺒﺮﻧﺎﻣﺠﻚ ، ﻳﺘﻢ ﺗﺮﺟﻤﺘﻪ ﻓﻮرًا ﺑﺎﺳﺘﺨﺪام ‪ JIT‬اﻟﺘﻲ ﺗﺤﺪﺛﻨﺎ ﻋﻨﻬﺎ ﺳﺎﺑﻘﺎ ، ﺳﻴﻜﻮن ﻋﻨﻬﺎ‬ ‫ً‬ ‫درس ﻣﺴﺘﻘﻞ إن ﺷﺎء اﷲ.‬ ‫‪Type metadata‬‬ ‫ﺗﺤﺘﻮي ﻋﻠﻰ ﺗﻔﺎﺻﻴﻞ اﻻﻧﻮاع اﻟﺨﺎرﺟﻴﺔ اﻟﺘﻲ ﺗﺴﺘﺨﺪﻣﻬﺎ ﻓﻲ ﺑﺮﻧﺎﻣﺠﻚ.‬ ‫‪An assembly manifest‬‬ ‫اﻟﺮاﺑﻂ ﺑﻴﻦ ﻣﻠﻔﺎت اﻻﺳﻤﺒﻠﻲ اﻟﻤﺨﺘﻠﻔﺔ ، ﺗﺤﺪد اﺻﺪار اﻻﺳﻤﺒﻠﻲ وﺧﻼﻓﻪ.‬‫672‬
  • ‫اﻟﺒﺮﻣﺠﺔ اﻟﻤﺘﻘﺪﻣﺔ ﻓﻲ ال ‪.net‬‬ ‫ ‬ ‫اﻟﺒﺎب اﻟﺜﺎﻧﻲ ﻋﺸﺮ‬ ‫‪Optional embedded resources‬‬ ‫اي ﻣﻠﻒ اﺳﻤﺒﻠﻲ ﻳﻤﻜﻦ ان ﻳﺤﺘﻮي ﻋﻠﻰ اي ﻋﺪد ﻣﻦ ﻣﻠﻔﺎت اﻟﺮﻳﺴﻮرس ﺗﺸﻴﺮ إﻟﻰ ﺻﻮر واﻳﻘﻮﻧﺎت‬ ‫وﺧﻼﻓﻪ.‬ ‫71. 4. ‪Private Assemblies‬‬ ‫ال  ‪ Private Assemblies‬ﻣﻠﻒ اﺳﻤﺒﻠﻲ ﻳﻌﻤﻞ ﻣﻦ ﺧﻼل ﻣﺴﺎر اﻟﺒﺮﻧﺎﻣﺞ او اﻟﺘﻄﺒﻴﻖ ، ﺣﻴﺚ ﻟﻦ ﻳﺒﺤﺚ‬ ‫ال  ‪ Visual  Studio‬ﻋﻦ ﻫﺬا اﻟﻤﻠﻒ ﺳﻮاء ﻓﻲ اﻟﺮﻳﺠﺴﺘﺮي او ﻓﻲ أي ﻣﻜﺎن آﺧﺮ ، ﻓﻘﻂ ﺳﻴﺒﺤﺚ ﻓﻲ‬ ‫ﻣﺴﺎر اﻟﺒﺮﻧﺎﻣﺞ ﻋﻨﻪ.‬ ‫ﻓﻲ ﺣﺎﻟﺔ ﺣﺬف ﺑﺮﻧﺎﻣﺠﻚ ﻳﺘﻢ ﺣﺬف ﻫﺬه اﻟﻤﻠﻔﺎت ﻣﻌﻪ ، اﻳﻀﺎ ﻳﻤﻜﻨﻚ ﻧﻘﻞ اﻟﺘﻄﺒﻴﻖ ﺑﻌﺪ ﻋﻤﻞ ‪setup‬‬ ‫ً‬ ‫ﻟﻪ ﻣﺒﺎﺷﺮة ﻛﻮﻧﻪ ﻻ ﻳﺘﻌﺎﻣﻞ ﻣﻊ أي ﺷﻲء ﻳﺨﺺ اﻟﻨﻈﺎم.‬ ‫ﻣﻠﻔﺎت اﻻﺳﻤﺒﻠﻲ اﻻﻓﺘﺮاﺿﻴﺔ او ال ‪ dll‬اﻟﺘﻲ ﺗﻘﻮم ﺑﻌﻤﻠﻬﺎ ﻫﻲ ﻣﻦ ﻫﺬا اﻟﻨﻮع.‬ ‫71. 5. ‪Shared Assemblies‬‬ ‫ﻫﺬا ﻫﻮ اﻟﻨﻮع اﻟﺜﺎﻧﻲ ، ﻫﻨﺎ ﻟﻦ ﺗﻜﻮن وﺣﺪك ﻣﻦ ﻳﺴﺘﺨﺪم ﻣﻠﻒ ال ‪ dll‬ﻫﺬا ، ﺑﻞ إن ﺑﺈﻣﻜﺎن اﻟﻤﻠﻒ‬ ‫اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻛﺜﺮ ﻣﻦ ﺗﻄﺒﻴﻖ ﻋﻠﻰ ﻧﻔﺲ اﻟﺠﻬﺎز ، ﻣﺜﻼ ‪ ،  System.Windows.Forms.dl‬ﻋﺎدة ﻣﺎ‬ ‫ً‬ ‫ﺗﺠﺪﻫﺎ ﻓﻲ ﻣﻠﻒ اﻻﺳﻤﺒﻠﻲ اﻟﻤﻮﺟﻮد ﻓﻲ اﻟﻮﻳﻨﺪوز وﻻ ﻳﺘﻢ ﺣﺬﻓﻬﺎ ﻣﻊ ﺣﺬف ﺑﺮﻧﺎﻣﺠﻚ.‬ ‫اول ﻧﻘﻄﺔ ﺳﺘﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﻹﻧﺸﺎء ﻣﻠﻒ اﺳﻤﺒﻠﻲ ﻣﻦ ﻫﺬا اﻟﻨﻮع ﻫﻮ ﺿﺮورة وﺟﻮد اﺳﻢ ‪ unique‬ﻟﻬﺬا‬ ‫اﻟﻤﻠﻒ ﺣﺘﻰ ﻻ ﻳﺘﻀﺎرب ﻣﻊ ﺑﺎﻗﻲ اﻟﻤﻠﻔﺎت اﻷﺧﺮى ، أﻳﺎم ال‪ COM‬ﻛﺎن ﻫﻨﺎك ﻣﺎ ﻳﻌﺮف ﺑﺎﺳﻢ