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

µÚ102ÕÂ

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

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

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






¡¡¡¡¡¡¡¡¡¡Reading¡¡the¡¡sentence£»¡¡you¡¡get¡¡an¡¡idea¡¡of¡¡what¡¡is¡¡being¡¡said£»¡¡but¡¡you¡¡are¡¡not¡¡pletely¡¡¡¡

sure¡£¡¡Visual¡¡Basic¡¡without¡¡¡¡generics¡¡is¡¡like¡¡this¡¡sentence£»¡¡in¡¡that¡¡you¡¡express¡¡your¡¡ideas¡¡in¡¡¡¡

code£»¡¡but¡¡some¡¡things¡¡are¡¡not¡¡as¡¡clear¡¡as¡¡you¡¡would¡¡like¡£¡¡

¡¡¡¡¡¡¡¡¡¡Visual¡¡Basic¡¡with¡¡¡¡generics¡¡is¡¡like¡¡this¡¡sentence£º¡¡



¡¡¡¡¡¡¡¡¡¡Ducks¡¡walk¡¡in¡¡a¡¡funny¡¡manner¡¡due¡¡to¡¡their¡¡flat¡¡feet£»¡¡and¡¡when¡¡they¡¡quack£»¡¡it¡¡is¡¡very¡¡

¡¡¡¡¡¡¡¡¡¡loud¡£¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡sentence¡¡is¡¡clearer¡¡and¡¡uses¡¡more¡¡words¡¡to¡¡describe¡¡the¡¡same¡¡thing¡£¡¡The¡¡reason¡¡we¡¡¡¡

talk¡¡using¡¡a¡¡more¡¡sophisticated¡¡language¡¡is¡¡that¡¡we¡¡want¡¡to¡¡explain¡¡concepts¡¡and¡¡be¡¡under

stood¡£¡¡If¡¡you¡¡accept¡¡that£»¡¡then¡¡you¡¡can¡¡accept¡¡why¡¡there¡¡is¡¡a¡¡need¡¡and¡¡context¡¡for¡¡¡¡generics¡£¡¡¡¡

And¡¡if¡¡not£»¡¡feel¡¡free¡¡to¡¡skip¡¡this¡¡chapter¡¡and¡¡read¡¡the¡¡next¡¡one¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡An¡¡example¡¡that¡¡illustrates¡¡how¡¡using¡¡¡¡generics¡¡makes¡¡your¡¡code¡¡clearer£»¡¡as¡¡well¡¡as¡¡¡¡

more¡¡concise£»¡¡than¡¡code¡¡that¡¡does¡¡not¡¡use¡¡¡¡generics¡¡is¡¡a¡¡container¡£¡¡A¡¡¡¡container¡¡is¡¡a¡¡type¡¡¡¡

that¡¡is¡¡used¡¡to¡¡manage¡¡other¡¡types£»¡¡lists¡¡and¡¡collections¡¡are¡¡examples¡¡of¡¡containers¡£¡¡To¡¡keep¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡285¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡308¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

286¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡¡£¡¡N¡¡E¡¡T¡¡¡¡G¡¡E¡¡N¡¡E¡¡R¡¡I¡¡CS¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡things¡¡simple£»¡¡let¡¯s¡¡look¡¡at¡¡a¡¡container¡¡that¡¡manages¡¡a¡¡single¡¡reference¡£¡¡The¡¡following¡¡is¡¡the¡¡less¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡concise¡¡version¡¡that¡¡uses¡¡the¡¡Object¡¡type¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Class¡¡Container¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡_managed¡¡As¡¡Object¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡New£¨ByVal¡¡toManage¡¡As¡¡Object£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_managed¡¡=¡¡toManage¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡Managed£¨£©¡¡As¡¡Object¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡_managed¡¡

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

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



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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡code£»¡¡the¡¡class¡¡Container¡¡has¡¡a¡¡constructor¡¡with¡¡a¡¡parameter¡¡and¡¡a¡¡single¡¡property£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Managed£»¡¡which¡¡references¡¡the¡¡variable¡¡_managed¡£¡¡The¡¡idea¡¡behind¡¡this¡¡class¡¡is¡¡to¡¡assign¡¡an¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡object¡¡in¡¡the¡¡constructor¡¡that¡¡can¡¡be¡¡referenced¡¡using¡¡the¡¡property¡£¡¡The¡¡class¡¡Container¡¡does¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡not¡¡know¡¡what¡¡the¡¡variable¡¡_managed¡¡does¡¡or¡¡its¡¡capabilities¡£¡¡Container¡¡does¡¡not¡¡care£»¡¡because¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Container¡¡is¡¡acting¡¡like¡¡a¡¡basket¡¡that¡¡holds¡¡an¡¡instance¡¡of¡¡whatever¡¡is¡¡given¡¡to¡¡it¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡Container¡¡class¡¡could¡¡be¡¡used¡¡as¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡container¡¡As¡¡Container¡¡=¡¡New¡¡Container£¨New¡¡MyType£¨£©£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡TryCast£¨container¡£Managed£»¡¡MyType£©¡£Method£¨£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡Container¡¡is¡¡instantiated£»¡¡the¡¡_managed¡¡data¡¡member¡¡is¡¡assigned¡¡an¡¡instance¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡MyType¡£¡¡MyType¡¡is¡¡a¡¡type¡¡that¡¡is¡¡used¡¡for¡¡illustrative¡¡purposes¡¡and¡¡has¡¡a¡¡single¡¡method£»¡¡Method£¨£©¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡retrieve¡¡and¡¡use¡¡the¡¡managed¡¡type£»¡¡the¡¡property¡¡Managed¡¡is¡¡referenced¡£¡¡However£»¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡method¡¡Method£¨£©¡¡cannot¡¡be¡¡called¡¡directly¡¡because¡¡the¡¡property¡¡Managed¡¡is¡¡of¡¡type¡¡Object£»¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡thus¡¡you¡¡need¡¡to¡¡cast¡¡the¡¡property¡¡to¡¡type¡¡MyType¡¡so¡¡that¡¡the¡¡call¡¡to¡¡Method£¨£©¡¡is¡¡legal¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡cast¡¡using¡¡TryCast¡¡will¡¡result¡¡in¡¡a¡¡valid¡¡instance¡¡of¡¡MyType¡¡or¡¡a¡¡Nothing¡¡value£»¡¡resulting¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡in¡¡a¡¡null¡¡object¡¡reference¡¡exception¡£¡¡Here¡¯s¡¡a¡¡safe¡¡way¡¡of¡¡using¡¡the¡¡Managed¡¡property£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡container¡¡As¡¡Container¡¡=¡¡New¡¡Container£¨New¡¡MyType£¨£©£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡TypeOf¡¡container¡£Managed¡¡Is¡¡MyType¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡TryCast£¨container¡£Managed£»¡¡MyType£©¡£Method£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡bolded¡¡code¡¡is¡¡the¡¡addition¡¡of¡¡the¡¡If¡¡block¡¡to¡¡test¡¡whether¡¡the¡¡container¡¡references¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡type¡¡MyType¡£¡¡Not¡¡shown¡¡is¡¡what¡¡the¡¡code¡¡should¡¡do¡¡if¡¡the¡¡property¡¡Managed¡¡is¡¡not¡¡MyType¡£¡¡The¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡fact¡¡that¡¡you¡¡need¡¡to¡¡verify¡¡that¡¡the¡¡container¡¡references¡¡the¡¡correct¡¡type£»¡¡and¡¡you¡¡also¡¡need¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡think¡¡of¡¡an¡¡alternative¡¡plan¡¡if¡¡the¡¡type¡¡is¡¡incorrect£»¡¡adds¡¡quite¡¡a¡¡bit¡¡of¡¡code¡£¡¡It¡¯s¡¡like¡¡that¡¡sentence¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡about¡¡the¡¡duck¡ªsure£»¡¡you¡¡get¡¡the¡¡general¡¡idea¡¡of¡¡what¡¡is¡¡being¡¡said£»¡¡but¡¡are¡¡you¡¡100£¥¡¡sure¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡meaning£¿¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡309¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡¡£¡¡N¡¡E¡¡T¡¡¡¡G¡¡E¡¡N¡¡E¡¡R¡¡I¡¡CS¡¡287¡¡



¡¡¡¡¡¡¡¡¡¡Now¡¡look¡¡at¡¡the¡¡following¡¡code£»¡¡which¡¡implements¡¡a¡¡container¡¡using¡¡¡¡generics¡£¡¡



¡¡¡¡¡¡¡¡Public¡¡Class¡¡GenericsContainer£¨Of¡¡ManagedType£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡_managed¡¡As¡¡ManagedType¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡New£¨ByVal¡¡toManage¡¡As¡¡ManagedType£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_managed¡¡=¡¡toManage¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡Managed£¨£©¡¡As¡¡ManagedType¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡_managed¡¡

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

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

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



¡¡¡¡¡¡¡¡¡¡You¡¡can¡¡write¡¡code¡¡that¡¡uses¡¡¡¡generics¡¡and¡¡code¡¡that¡¡provides¡¡types¡¡based¡¡on¡¡¡¡¡¡

generics¡£¡¡The¡¡definition¡¡of¡¡GenericsContainer¡¡demonstrates¡¡code¡¡that¡¡provides¡¡types¡¡based¡¡on¡¡¡¡

¡¡generics¡£¡¡You¡¯ll¡¡see¡¡the¡¡code¡¡that¡¡uses¡¡¡¡generics¡¡next¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡generics¡¡parameters¡¡are¡¡associated¡¡with¡¡types£»¡¡such¡¡as¡¡classes¡¡and¡¡interfaces£»¡¡or¡¡with¡¡¡¡

methods¡£¡¡In¡¡the¡¡case¡¡of¡¡GenericsContainer£»¡¡the¡¡¡¡generics¡¡parameter¡¡ManagedType¡¡is¡¡a¡¡¡¡

placeholder¡¡for¡¡an¡¡actual¡¡type¡£¡¡



¡öNote¡¡¡¡monly£»¡¡developers¡¡use¡¡the¡¡notation¡¡of¡¡a¡¡single¡¡letter¡¡when¡¡defining¡¡a¡¡¡¡generics¡¡parameter¡£¡¡¡¡

I¡¡am¡¡not¡¡a¡¡fan¡¡of¡¡that¡¡notation£»¡¡because¡¡it¡¡tells¡¡me¡¡nothing£»¡¡especially¡¡when¡¡there¡¡are¡¡multiple¡¡parameters¡£¡¡I¡¡¡¡

remend¡¡using¡¡an¡¡identifier¡¡that¡¡describes¡¡what¡¡the¡¡parameter¡¡does£»¡¡appended¡¡with¡¡the¡¡word¡¡Type£»¡¡to¡¡¡¡

indicate¡¡a¡¡¡¡generics¡¡parameter¡¡is¡¡being¡¡defined¡£¡¡



¡¡¡¡¡¡¡¡¡¡With¡¡GenericsContainer£»¡¡ManagedType¡¡is¡¡used¡¡as¡¡an¡¡identifier¡¡in¡¡the¡¡place¡¡of¡¡the¡¡identifier¡¡¡¡

object¡¡in¡¡the¡¡type¡¡Container¡£¡¡This¡¡is¡¡a¡¡rule¡¡of¡¡thumb¡£¡¡Whenever¡¡you¡¡find¡¡yourself¡¡using¡¡an¡¡object¡¡¡¡

generically¡¡to¡¡define¡¡a¡¡type£»¡¡you¡¡probably¡¡could¡¡use¡¡¡¡generics¡£¡¡Think¡¡of¡¡¡¡generics¡¡¡¡

types¡¡as¡¡general¡¡things¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡code¡¡demonstrates¡¡how¡¡to¡¡use¡¡GenericsContainer¡¡with¡¡MyType¡£¡¡



Dim¡¡container¡¡As¡¡GenericsContainer£¨Of¡¡MyType£©¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡New¡¡GenericsContainer£¨Of¡¡MyType£©£¨New¡¡MyType£¨£©£©¡¡

container¡£Managed¡£Method£¨£©¡¡



¡¡¡¡¡¡¡¡¡¡When¡¡instantiating¡¡GenericsContainer£»¡¡notice¡¡how¡¡the¡¡identifier¡¡ManagedType¡¡must¡¡be¡¡¡¡

replaced¡¡with¡¡an¡¡identifier¡¡that¡¡represents¡¡an¡¡already¡¡existing¡¡type¡£¡¡This¡¡identifier¡¡replacement¡¡¡¡

results¡¡in¡¡a¡¡new¡¡and¡¡unique¡¡type¡¡£¨also¡¡called¡¡a¡¡concrete¡¡type£©¡£¡¡The¡¡advantage¡¡of¡¡¡¡generics¡¡is¡¡¡¡

that¡¡when¡¡you¡¡provide¡¡a¡¡concrete¡¡type£»¡¡you¡¡don¡¯t¡¡need¡¡to¡¡check¡¡to¡¡make¡¡sure¡¡that¡¡everything¡¡is¡¡¡¡

correct¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡¡¡runtime¡¡will¡¡generate¡¡a¡¡type¡¡that¡¡has¡¡an¡¡intent¡¡similar¡¡to¡¡the¡¡following¡¡code¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡310¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

288¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡¡£¡¡N¡¡E¡¡T¡¡¡¡G¡¡E¡¡N¡¡E¡¡R¡¡I¡¡CS¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Class¡¡GenericsContainerMyType¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡_managed¡¡As¡¡MyType¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡New£¨ByVal¡¡toManage¡¡As¡¡MyType£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_managed¡¡=¡¡toManage¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡Managed£¨£©¡¡As¡¡MyType¡¡¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡_managed¡¡

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

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

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Visual¡¡Basic¡¡piles¡¡a¡¡¡¡generics¡¡type¡¡as¡¡an¡¡inplete¡¡type¡£¡¡When¡¡the¡¡inplete¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡type¡¡is¡¡concretized£»¡¡¡¡creates¡¡a¡¡brand¡­new¡¡type£»¡¡and¡¡does¡¡this¡¡without¡¡requiring¡¡the¡¡devel

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡oper¡¡to¡¡do¡¡anything¡¡in¡¡particular¡£¡¡This¡¡means¡¡that¡¡if¡¡you¡¡use¡¡GenericsContainer¡¡with¡¡15¡¡different¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡types£»¡¡¡¡will¡¡generate¡¡15¡¡definitions¡¡of¡¡GenericsContainer¡¡while¡¡the¡¡program¡¡is¡¡executing¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ABSTRACTION¡¡AND¡¡¡¡GENERICS¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡With¡¡¡¡generics£»¡¡you¡¡can¡¡verify¡¡and¡¡ensure¡¡that¡¡everything¡¡is¡¡being¡¡said¡¡properly£»¡¡with¡¡the¡¡cost¡¡being¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡plexity¡£¡¡Consider¡¡the¡¡sentence¡¡that¡¡clearly¡¡described¡¡the¡¡duck¡£¡¡To¡¡produce¡¡it£»¡¡you¡¡need¡¡to¡¡have¡¡learned¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡

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

Äã¿ÉÄÜϲ»¶µÄ