Сţµç×ÓÊé > ÆäËûµç×ÓÊé > VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ) >

µÚ83ÕÂ

VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ83ÕÂ

С˵£º VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ) ×ÖÊý£º ÿҳ3500×Ö

°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡






¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Some¡¡Things¡¡for¡¡You¡¡to¡¡Do¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡are¡¡some¡¡exercises¡¡that¡¡will¡¡help¡¡you¡¡apply¡¡the¡¡concepts¡¡you¡¡learned¡¡in¡¡this¡¡chapter¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡£¡¡¡¡The¡¡LightingController¡£AddRoomGrouping£¨£©¡¡method¡¡has¡¡a¡¡mistake¡£¡¡Write¡¡some¡¡tests¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡find¡¡the¡¡error£»¡¡and¡¡then¡¡fix¡¡the¡¡code¡¡and¡¡rerun¡¡your¡¡tests¡¡to¡¡verify¡¡that¡¡the¡¡error¡¡has¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡been¡¡fixed¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2¡£¡¡¡¡The¡¡TestInsert£¨£©¡¡test¡¡method¡¡is¡¡one¡¡example¡¡of¡¡an¡¡insertion¡¡test£»¡¡but¡¡not¡¡all¡¡variations¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡have¡¡been¡¡tested¡£¡¡Write¡¡another¡¡test¡¡method¡¡that¡¡implements¡¡the¡¡remaining¡¡variation£¨s£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡need¡¡to¡¡be¡¡tested¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡3¡£¡¡¡¡The¡¡declarations¡¡of¡¡RoomGrouping¡¡and¡¡Room¡¡are¡¡not¡¡optimal¡£¡¡Fix¡¡the¡¡declarations¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡4¡£¡¡¡¡Implement¡¡a¡¡general¡¡collection¡¡class¡¡based¡¡on¡¡the¡¡experience¡¡of¡¡using¡¡the¡¡class¡¡in¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡class¡¡LightingController¡£¡¡Hint£º¡¡look¡¡at¡¡how¡¡the¡¡linked¡¡list¡¡for¡¡Room¡¡is¡¡declared¡¡and¡¡figure¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡out¡¡a¡¡way¡¡to¡¡abstract¡¡that¡¡into¡¡some¡¡general¡¡collection¡¡class¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡5¡£¡¡¡¡When¡¡the¡¡method¡¡¡¡LightingController¡£AddRoom£¨£©¡¡is¡¡called£»¡¡the¡¡method¡¡is¡¡tested¡¡internally¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡see¡¡if¡¡the¡¡handle¡¡is¡¡of¡¡type¡¡RoomGrouping¡£¡¡Can¡¡you¡¡think¡¡of¡¡a¡¡more¡¡defensive¡¡pro

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡gramming¡¡technique¡¡to¡¡make¡¡sure¡¡that¡¡the¡¡code¡¡someone¡¡else¡¡passes¡¡to¡¡the¡¡kernel¡¡will¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡not¡¡cause¡¡the¡¡kernel¡¡to¡¡fail£¿¡¡Hint£º¡¡think¡¡about¡¡the¡¡methods¡¡to¡¡turn¡¡on¡¡or¡¡off¡¡the¡¡lights¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡think¡¡of¡¡what¡¡could¡¡go¡¡wrong¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡251¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

C¡¡¡¡H¡¡¡¡A¡¡¡¡P¡¡¡¡T¡¡¡¡E¡¡¡¡R¡¡¡¡¡¡¡¡¡¡9¡¡



¡ö¡¡¡ö¡¡¡ö¡¡



Learning¡¡About¡¡Lists£»¡¡Delegates£»¡¡¡¡

and¡¡Lambda¡¡Expressions¡¡¡¡



One¡¡of¡¡the¡¡most¡¡mon¡¡pieces¡¡of¡¡code¡¡that¡¡you¡¡will¡¡write¡¡is¡¡code¡¡that¡¡manages¡¡many¡¡object¡¡¡¡

instances¡£¡¡In¡¡the¡¡previous¡¡examples£»¡¡many¡¡object¡¡instances¡¡were¡¡managed¡¡using¡¡an¡¡array¡£¡¡In¡¡¡¡

Chapter¡¡8£»¡¡you¡¡learned¡¡that¡¡a¡¡linked¡¡list¡¡used¡¡in¡¡conjunction¡¡with¡¡a¡¡default¡¡property¡¡could¡¡make¡¡a¡¡¡¡

plain¡­vanilla¡¡object¡¡look¡¡like¡¡a¡¡collection¡£¡¡This¡¡chapter¡¡introduces¡¡the¡¡¡¡collection¡¡classes£»¡¡¡¡

which¡¡provide¡¡an¡¡easy¡¡way¡¡to¡¡manage¡¡a¡¡set¡¡of¡¡object¡¡instances¡£¡¡Think¡¡of¡¡a¡¡collection¡¡object¡¡as¡¡¡¡

an¡¡infinite¡¡sack¡¡where¡¡things¡¡can¡¡be¡¡added£»¡¡iterated¡¡through£»¡¡and¡¡retrieved¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡chapter¡¡begins¡¡with¡¡a¡¡discussion¡¡of¡¡how¡¡to¡¡manage¡¡collections¡£¡¡Then¡¡we¡¡will¡¡look¡¡at¡¡¡¡

different¡¡ways¡¡of¡¡iterating¡¡the¡¡data¡¡using¡¡a¡¡delegate¡£¡¡Finally£»¡¡we¡¡will¡¡look¡¡at¡¡lambda¡¡expressions¡¡¡¡

and¡¡closures¡¡to¡¡illustrate¡¡another¡¡way¡¡of¡¡processing¡¡data¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡project¡¡structure¡¡used¡¡in¡¡this¡¡chapter¡¡is¡¡a¡¡single¡¡console¡¡application¡£¡¡As¡¡we¡¡will¡¡not¡¡be¡¡¡¡

building¡¡an¡¡overall¡¡application£»¡¡but¡¡rather¡¡a¡¡set¡¡of¡¡sample¡¡code¡¡snippets£»¡¡no¡¡tests¡¡or¡¡libraries¡¡¡¡

are¡¡involved¡£¡¡



Managing¡¡Collections¡¡



When¡¡you¡¡have¡¡a¡¡collection£»¡¡what¡¡you¡¡actually¡¡have¡¡is¡¡an¡¡object¡¡that¡¡happens¡¡to¡¡point¡¡to¡¡many¡¡¡¡

other¡¡objects¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡Visual¡¡Basic¡¡provides¡¡collection¡¡classes¡¡for¡¡managing¡¡collections¡£¡¡Visual¡¡Basic¡¡2005¡¡intro

duced¡¡a¡¡different¡¡approach¡¡to¡¡collections£»¡¡which¡¡solved¡¡many¡¡of¡¡the¡¡problems¡¡that¡¡came¡¡up¡¡¡¡

in¡¡earlier¡¡Visual¡¡Basic¡¡versions¡£¡¡Here£»¡¡we¡¯ll¡¡look¡¡at¡¡managing¡¡collections¡¡both¡¡before¡¡and¡¡after¡¡¡¡

Visual¡¡Basic¡¡2005£»¡¡which¡¡will¡¡help¡¡you¡¡to¡¡understand¡¡how¡¡collections¡¡are¡¡used¡£¡¡¡¡



Managing¡¡a¡¡Collection¡¡Before¡¡Visual¡¡Basic¡¡2005¡¡



Before¡¡Visual¡¡Basic¡¡2005£»¡¡the¡¡main¡¡collection¡¡classes¡¡were¡¡stored¡¡in¡¡the¡¡namespace¡¡System¡£¡¡

Collections¡¡£¨and£»¡¡of¡¡course£»¡¡these¡¡classes¡¡are¡¡still¡¡available¡¡for¡¡you¡¡to¡¡use£©¡£¡¡The¡¡following¡¡are¡¡¡¡

some¡¡of¡¡the¡¡classes¡¡and¡¡interfaces¡¡in¡¡that¡¡namespace£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡229¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡252¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

230¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡9¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡L¡¡I¡¡ST¡¡S£»¡¡¡¡¡¡D¡¡E¡¡L¡¡E¡¡G¡¡A¡¡T¡¡E¡¡S£»¡¡¡¡¡¡A¡¡N¡¡D¡¡¡¡¡¡L¡¡A¡¡M¡¡B¡¡DA¡¡¡¡¡¡E¡¡X¡¡P¡¡R¡¡E¡¡S¡¡SI¡¡ON¡¡S¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡ArrayList£º¡¡A¡¡general¡¡collection¡¡that¡¡manages¡¡all¡¡of¡¡the¡¡referenced¡¡objects¡¡using¡¡an¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡internal¡¡array¡£¡¡This¡¡class¡¡manages¡¡the¡¡problem¡¡of¡¡increasing¡¡the¡¡size¡¡of¡¡an¡¡array¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Hashtable£º¡¡A¡¡collection¡¡class¡¡where¡¡the¡¡individual¡¡objects¡¡are¡¡stored¡¡using¡¡key/value¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡pairs¡£¡¡In¡¡the¡¡previous¡¡chapter£»¡¡the¡¡indexer¡¡was¡¡used¡¡to¡¡retrieve¡¡a¡¡room¡¡grouping¡¡based¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡on¡¡its¡¡identifier¡£¡¡You¡¡could¡¡use¡¡a¡¡Hashtable¡¡to¡¡acplish¡¡the¡¡same¡¡thing¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡ICollection£º¡¡An¡¡interface¡¡implement¡¡by¡¡ArrayList¡¡that¡¡provides¡¡basic¡¡functionality¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡copies¡¡the¡¡references¡¡to¡¡another¡¡array¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡IDictionary£º¡¡An¡¡interface¡¡implemented¡¡by¡¡Hashtable¡¡that¡¡allows¡¡a¡¡programmer¡¡to¡¡asso

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ciate¡¡a¡¡key¡¡with¡¡a¡¡value¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡IList£º¡¡An¡¡interface¡¡implemented¡¡by¡¡ArrayList¡¡that¡¡provides¡¡a¡¡general¡­access¡¡mechanism¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡for¡¡manipulating¡¡a¡¡collection¡¡of¡¡items¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Queue£º¡¡A¡¡collection¡¡that¡¡implements¡¡the¡¡first¡¡in£»¡¡first¡¡out¡¡£¨FIFO£©¡¡mechanism¡£¡¡You¡¡could¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡use¡¡a¡¡queue¡¡when¡¡you¡¡are¡¡processing¡¡a¡¡set¡¡of¡¡instructions¡£¡¡The¡¡first¡¡instruction¡¡to¡¡process¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡would¡¡be¡¡the¡¡first¡¡instruction¡¡added¡¡to¡¡the¡¡collection¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Stack£º¡¡A¡¡collection¡¡that¡¡implements¡¡the¡¡last¡¡in£»¡¡first¡¡out¡¡£¨LIFO£©¡¡mechanism¡£¡¡Think¡¡of¡¡it¡¡as¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡stack¡¡of¡¡papers¡£¡¡When¡¡one¡¡piece¡¡of¡¡paper¡¡is¡¡laid¡¡on¡¡top¡¡of¡¡another£»¡¡the¡¡first¡¡piece¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡paper¡¡that¡¡is¡¡processed¡¡is¡¡the¡¡last¡¡piece¡¡of¡¡paper¡¡added¡¡to¡¡the¡¡stack¡¡of¡¡papers¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡All¡¡of¡¡the¡¡collection¡¡types¡ªArrayList£»¡¡Hashtable£»¡¡Queue£»¡¡and¡¡Stack¡ªimplement¡¡a¡¡way¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡store¡¡a¡¡set¡¡of¡¡types¡£¡¡The¡¡difference¡¡in¡¡the¡¡collection¡¡types¡¡lies¡¡in¡¡how¡¡the¡¡individual¡¡objects¡¡are¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡stored¡¡and¡¡retrieved¡¡from¡¡the¡¡collection¡£¡¡For¡¡examples¡¡of¡¡using¡¡these¡¡collection¡¡types£»¡¡see¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡°Learning¡¡More¡¡About¡¡Collection¡¡Types¡±¡¡section¡¡later¡¡in¡¡this¡¡chapter¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Let¡¯s¡¡walk¡¡through¡¡an¡¡example¡¡of¡¡using¡¡these¡¡collection¡¡classes¡£¡¡Begin¡¡by¡¡creating¡¡a¡¡console¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡application¡¡and¡¡call¡¡it¡¡OneToManySamples¡£¡¡Then¡¡add¡¡a¡¡new¡¡class¡¡£¨right¡­click¡¡your¡¡console¡¡appli

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡cation¡¡project¡¡and¡¡select¡¡Add¡¡¡¡Class£©¡£¡¡Call¡¡it¡¡¡¡Example¡£vb¡¡and¡¡add¡¡all¡¡of¡¡the¡¡following¡¡code¡¡to¡¡it£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡Example¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Property¡¡Value£¨£©¡¡As¡¡Integer¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Get¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡_value¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Get¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Set£¨ByVal¡¡value¡¡As¡¡Integer£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_value¡¡=¡¡value¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Set¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Property¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡_value¡¡As¡¡Integer¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Friend¡¡Module¡¡Tests¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡Sub¡¡PlainVanillaObjects£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡objects¡¡As¡¡IList¡¡=¡¡New¡¡ArrayList£¨£©¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡253¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡C¡¡HA¡¡P¡¡TE¡¡R¡¡¡¡¡¡9¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡O¡¡U¡¡T¡¡¡¡L¡¡I¡¡ST¡¡S£»¡¡¡¡¡¡DE¡¡L¡¡E¡¡G¡¡AT¡¡E¡¡S¡¡£»¡¡¡¡¡¡AN¡¡D¡¡¡¡L¡¡A¡¡M¡¡B¡¡D¡¡A¡¡¡¡E¡¡X¡¡PR¡¡E¡¡SSI¡¡O¡¡N¡¡S¡¡¡¡231¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡objects¡£Add£¨New¡¡Example¡¡With¡¡£û¡£Value¡¡=¡¡10£ý£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡objects¡£Add£¨New¡¡Example¡¡With¡¡£û¡£Value¡¡=¡¡20£ý£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡Each¡¡obj¡¡As¡¡Example¡¡In¡¡objects¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Object¡¡value¡¡£¨¡¨¡¡&¡¡obj¡£Value¡¡&¡¡¡¨£©¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Next¡¡

¡¡¡¡¡¡¡¡End¡¡Sub¡¡

¡¡¡¡¡¡¡¡Public¡¡Sub¡¡RunAll£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡PlainVanillaObjects£¨£©¡¡

¡¡¡¡¡¡¡¡End¡¡Sub¡¡

End¡¡Module¡¡



¡¡¡¡¡¡¡¡¡¡This¡¡is¡¡the¡¡type¡¡of¡¡code¡¡written¡¡before¡¡Visual¡¡Basic¡¡2005£»¡¡and¡¡it¡¡follows¡¡a¡¡standard¡¡set¡¡of¡¡steps£º¡¡



¡¡¡¡¡¡¡¡¡¡1¡£¡¡¡¡You¡¡define¡¡a¡¡custom¡¡type¡¡£¨¡¡Example¡¡in¡¡this¡¡example£©¡£¡¡



¡¡¡¡¡¡¡¡¡¡2¡£¡¡¡¡You¡¡instantiate¡¡the¡¡custom¡¡type¡¡and¡¡add¡¡the¡¡instances¡¡to¡¡a¡¡collection¡£¡¡In¡¡the¡¡example£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡two¡¡instances¡¡of¡¡Example¡¡are¡¡added¡¡to¡¡the¡¡collection¡¡type¡¡ArrayList¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡3¡£¡¡¡¡The¡¡collection¡¡is¡¡manipulated¡¡to¡¡allow¡¡you¡¡to¡¡access¡¡and¡¡manipulate¡¡the¡¡instances¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡custom¡¡types¡£¡¡In¡¡the¡¡example£»¡¡the¡¡collection¡¡ArrayList¡¡is¡¡an¡¡interface¡¡instance¡¡of¡¡IList¡£¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡bolded¡¡code¡¡in¡¡the¡¡example¡¡is¡¡where¡¡the¡¡action

·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨2£© ²È£¨2£©

Äã¿ÉÄÜϲ»¶µÄ