ÓÑÇéÌáʾ£ºÈç¹û±¾ÍøÒ³´ò¿ªÌ«Âý»òÏÔʾ²»ÍêÕû£¬Çë³¢ÊÔÊó±êÓÒ¼ü¡°Ë¢Ð¡±±¾ÍøÒ³£¡
¸»Ê¿¿µÐ¡ËµÍø ·µ»Ø±¾ÊéĿ¼ ¼ÓÈëÊéÇ© ÎÒµÄÊé¼Ü ÎÒµÄÊéÇ© TXTÈ«±¾ÏÂÔØ ¡ºÊղص½ÎÒµÄä¯ÀÀÆ÷¡»

VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ57²¿·Ö

¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿! Èç¹û±¾ÊéûÓÐÔĶÁÍ꣬ÏëÏ´μÌÐø½Ó×ÅÔĶÁ£¬¿ÉʹÓÃÉÏ·½ "Êղص½ÎÒµÄä¯ÀÀÆ÷" ¹¦ÄÜ ºÍ "¼ÓÈëÊéÇ©" ¹¦ÄÜ£¡



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

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡OneLeft£¨£©¡¡As¡¡SheetCoordinate¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡New¡¡SheetCoordinate£¨Me¡£Row£»¡¡£¨Me¡£Column¡¡1£©£©¡¡

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

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡OneRight£¨£©¡¡As¡¡SheetCoordinate¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡New¡¡SheetCoordinate£¨Me¡£Row£»¡¡£¨Me¡£Column¡¡£«¡¡1£©£©¡¡

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

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Structure¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡declaration¡¡of¡¡SheetCoordinate£»¡¡notice¡¡that¡¡Structure¡¡is¡¡used¡¡rather¡¡than¡¡Class¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡We¡¡could¡¡have¡¡used¡¡a¡¡class£»¡¡but¡¡SheetCoordinate¡¡serves¡¡the¡¡purpose¡¡of¡¡being¡¡a¡¡piece¡¡of¡¡data¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡SheetCoordinate¡¡is¡¡a¡¡type¡¡where¡¡you¡¡store¡¡information¡¡that¡¡is¡¡used¡¡by¡¡another¡¡type¡£¡¡A¡¡data¡¡type¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡might¡¡do¡¡some¡¡processing£»¡¡but¡¡only¡¡to¡¡make¡¡it¡¡easier¡¡to¡¡manipulate¡¡the¡¡data¡£¡¡For¡¡example£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡notice¡¡how¡¡SheetCoordinate¡¡has¡¡properties¡¡to¡¡generate¡¡a¡¡new¡¡instance¡¡of¡¡SheetCoordinate¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡might¡¡be¡¡one¡¡row¡¡higher¡¡or¡¡lower£»¡¡or¡¡a¡¡column¡¡to¡¡the¡¡right¡¡or¡¡left¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡next¡¡step¡¡is¡¡to¡¡extend¡¡the¡¡worksheet¡¡definition¡¡and¡¡use¡¡¡¡generics¡¡to¡¡define¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡type¡¡of¡¡worksheet¡£¡¡The¡¡following¡¡is¡¡the¡¡plete¡¡definition¡¡of¡¡the¡¡¡¡IWorksheet¡£¡¡These¡¡methods¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡319¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡297¡¡



are¡¡used¡¡to¡¡calculate¡¡the¡¡values¡¡of¡¡cells¡¡in¡¡the¡¡worksheet¡¡and¡¡work¡¡with¡¡the¡¡contents¡¡of¡¡individual¡¡¡¡

cells¡¡£¨the¡¡state¡¡of¡¡those¡¡cells£©¡£¡¡We¡¡can¡¡also¡¡assign¡¡the¡¡function¡¡that¡¡carries¡¡out¡¡the¡¡calculation¡¡of¡¡¡¡

a¡¡cell¡¯s¡¡contents£»¡¡using¡¡either¡¡a¡¡SheetCoordinate¡¡type¡¡or¡¡the¡¡row¡¡and¡¡column¡¡coordinates¡£¡¡



Public¡¡Interface¡¡IWorksheet£¨Of¡¡BaseType£©¡¡

¡¡¡¡¡¡¡¡Inherits¡¡IWorksheetBase¡¡



¡¡¡¡¡¡¡¡Sub¡¡AssignCellCalculation£¨ByVal¡¡coords¡¡As¡¡SheetCoordinate£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ByVal¡¡cb¡¡As¡¡Func£¨Of¡¡IWorksheet£¨Of¡¡BaseType£©£»¡¡Integer£»¡¡Integer£»¡¡BaseType£©£©¡¡



¡¡¡¡¡¡¡¡Sub¡¡AssignCellCalculation£¨ByVal¡¡row¡¡As¡¡Integer£»¡¡ByVal¡¡col¡¡As¡¡Integer£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ByVal¡¡cb¡¡As¡¡Func£¨Of¡¡IWorksheet£¨Of¡¡BaseType£©£»¡¡Integer£»¡¡Integer£»¡¡BaseType£©£©¡¡



¡¡¡¡¡¡¡¡Sub¡¡AssignColCalculation£¨ByVal¡¡col¡¡As¡¡Integer£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ByVal¡¡cb¡¡As¡¡Func£¨Of¡¡IWorksheet£¨Of¡¡BaseType£©£»¡¡_¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Integer£»¡¡Integer£»¡¡BaseType£©£©¡¡

¡¡¡¡¡¡¡¡Sub¡¡Calculate£¨£©¡¡



¡¡¡¡¡¡¡¡Function¡¡Calculate£¨ByVal¡¡coords¡¡As¡¡SheetCoordinate£©¡¡As¡¡BaseType¡¡

¡¡¡¡¡¡¡¡¡¡

¡¡¡¡¡¡¡¡Function¡¡Calculate£¨ByVal¡¡row¡¡As¡¡Integer£»¡¡ByVal¡¡col¡¡As¡¡Integer£©¡¡As¡¡BaseType¡¡



¡¡¡¡¡¡¡¡Sub¡¡CalculateCol£¨ByVal¡¡col¡¡As¡¡Integer£©¡¡



¡¡¡¡¡¡¡¡Sub¡¡CalculateRow£¨ByVal¡¡row¡¡As¡¡Integer£©¡¡



¡¡¡¡¡¡¡¡Function¡¡GetCellState£¨ByVal¡¡coords¡¡As¡¡SheetCoordinate£©¡¡As¡¡BaseType¡¡



¡¡¡¡¡¡¡¡Function¡¡GetCellState£¨ByVal¡¡row¡¡As¡¡Integer£»¡¡ByVal¡¡col¡¡As¡¡Integer£©¡¡As¡¡BaseType¡¡



¡¡¡¡¡¡¡¡Sub¡¡SetCellState£¨ByVal¡¡coords¡¡As¡¡SheetCoordinate£»¡¡ByVal¡¡val¡¡As¡¡BaseType£©¡¡



¡¡¡¡¡¡¡¡Sub¡¡SetCellState£¨ByVal¡¡row¡¡As¡¡Integer£»¡¡ByVal¡¡col¡¡As¡¡Integer£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ByVal¡¡val¡¡As¡¡BaseType£©¡¡



¡¡¡¡¡¡¡¡ReadOnly¡¡Property¡¡Data£¨£©¡¡As¡¡BaseType¡¡£¨£»£©¡¡

End¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡declaration¡¡of¡¡IWorksheet¡¡is¡¡as¡¡a¡¡¡¡generics¡¡type£»¡¡where¡¡BaseType¡¡is¡¡a¡¡¡¡generics¡¡¡¡

parameter¡¡that¡¡represents¡¡the¡¡type¡¡of¡¡the¡¡spreadsheet¡£¡¡Since¡¡IWorksheet¡¡is¡¡a¡¡type¡¡of¡¡spreadsheet£»¡¡¡¡

it¡¡subclasses¡¡the¡¡IWorksheetBase¡¡interface£»¡¡allowing¡¡IWorksheet¡¡to¡¡be¡¡part¡¡of¡¡a¡¡mixed¡¡collection¡¡¡¡

of¡¡IWorksheet¡¡instances¡£¡¡The¡¡IWorksheet¡¡interface¡¡is¡¡fairly¡¡plex¡¡and¡¡contains¡¡many¡¡methods¡£¡¡¡¡

However£»¡¡here¡¡we¡¡are¡¡focusing¡¡on¡¡the¡¡interface¡¡concept£»¡¡rather¡¡than¡¡the¡¡individual¡¡methods¡£¡¡

¡¡¡¡¡¡¡¡¡¡Look¡¡at¡¡the¡¡bolded¡¡parts¡¡and¡¡notice¡¡how¡¡the¡¡interface¡¡is¡¡specific¡¡about¡¡the¡¡operations£»¡¡but¡¡¡¡

vague¡¡about¡¡the¡¡type¡¡used¡¡in¡¡the¡¡operations¡£¡¡This¡¡is¡¡what¡¡you¡¡want¡¡to¡¡achieve¡¡when¡¡using¡¡¡¡¡¡

generics¡£¡¡You¡¡want¡¡to¡¡take¡¡a¡¡high¡­level¡¡approach¡¡and¡¡indicate¡¡which¡¡operations¡¡are¡¡available£»¡¡¡¡

but¡¡leave¡¡out¡¡the¡¡types¡¡being¡¡manipulated¡¡in¡¡the¡¡operations¡£¡¡The¡¡types¡¡will¡¡be¡¡specified¡¡later¡¡by¡¡¡¡

another¡¡programmer¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡320¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

298¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡The¡¡technique¡¡of¡¡having¡¡a¡¡¡¡generics¡¡type¡¡£¨such¡¡as¡¡IWorksheet£©¡¡subclass¡¡a¡¡non¡­¡¡generics¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡type¡¡£¨such¡¡as¡¡¡¡IWorksheetBase£©¡¡allows¡¡you¡¡to¡¡identify¡¡the¡¡general¡¡type¡¡that¡¡you¡¡are¡¡trying¡¡to¡¡describe¡¡with¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡some¡¡specialization¡¡in¡¡the¡¡¡¡generics¡¡type¡¡declaration¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Defining¡¡the¡¡IWorkbook¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Now¡¡that¡¡we¡¯ve¡¡pleted¡¡the¡¡IWorksheet£¨Of¡¡BaseType£©¡¡and¡¡¡¡IWorksheetBase¡¡interfaces£»¡¡we¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡can¡¡define¡¡the¡¡workbook¡¡interface¡£¡¡The¡¡workbook¡¡interface¡¡will¡¡not¡¡be¡¡a¡¡¡¡generics¡¡type£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡since¡¡a¡¡workbook¡¡will¡¡contain¡¡multiple¡¡worksheet¡¡types¡£¡¡However£»¡¡as¡¡you¡¡will¡¡see£»¡¡we¡¡can¡¡optimize¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this¡¡interface¡¡to¡¡make¡¡it¡¡easier¡¡to¡¡use¡¡the¡¡workbook¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡the¡¡moment£»¡¡let¡¯s¡¡consider¡¡the¡¡plain¡­vanilla¡¡IWorkbook¡¡interface¡¡with¡¡no¡¡¡¡generics¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡types£»¡¡which¡¡is¡¡defined¡¡as¡¡follows¡¡in¡¡the¡¡ServerSideSpreadsheet£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Imports¡¡System¡£Reflection¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Imports¡¡Devspace¡£Trader¡£mon¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Interface¡¡IWorkbook¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡IDebug¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ReadOnly¡¡Property¡¡Identifier£¨£©¡¡As¡¡String¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Default¡¡Property¡¡Item£¨ByVal¡¡identifier¡¡As¡¡String£©¡¡As¡¡IWorksheetBase¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡IWorkbook¡¡interface¡¡defines¡¡an¡¡Identifier¡¡property¡¡and¡¡a¡¡default¡¡property¡¡Item¡£¡¡Notice¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡how¡¡the¡¡attribute¡¡DefaultMember¡¡is¡¡defined¡¡to¡¡indicate¡¡the¡¡default¡¡property¡¡identifier¡¡£¨it¡¡is¡¡from¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡System¡£Reflection¡¡namespace£©¡£¡¡Any¡¡class¡¡that¡¡implements¡¡IWorkbook¡¡is¡¡expected¡¡to¡¡contain¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡multiple¡¡references¡¡to¡¡IWorksheet£¨Of¡¡BaseType£©¡¡instances¡£¡¡How¡¡those¡¡references¡¡are¡¡managed¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡not¡¡the¡¡responsibility¡¡of¡¡the¡¡IWorkbook¡¡interface£»¡¡but¡¡of¡¡the¡¡IWorkbook¡¡interface¡¡implementation¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡The¡¡IWorkbook¡¡interface¡¡does¡¡not¡¡provide¡¡a¡¡Clear£¨£©¡¡method¡¡to¡¡reset¡¡the¡¡workbook¡¡and¡¡delete¡¡all¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡of¡¡the¡¡referenced¡¡worksheets¡£¡¡It¡¡would¡¡seem¡¡logical¡¡to¡¡have¡¡a¡¡Clear£¨£©¡¡method£»¡¡but¡¡in¡¡a¡¡garbage¡­collected¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡environment£»¡¡that¡¯s¡¡pletely¡¡unnecessary¡£¡¡If¡¡you¡¡don¡¯t¡¡want¡¡to¡¡use¡¡a¡¡workbook¡¡anymore£»¡¡just¡¡don¡¯t¡¡refer

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ence¡¡it£»¡¡and¡¡the¡¡garbage¡¡collector¡¡will¡¡take¡¡care¡¡of¡¡the¡¡rest¡£¡¡Think¡¡of¡¡it¡¡as¡¡having¡¡the¡¡option¡¡of¡¡serving¡¡dinner¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡your¡¡guests¡¡on¡¡real¡¡plates¡¡or¡¡paper¡¡plates¡£¡¡Real¡¡plates¡¡might¡¡seem¡¡better£»¡¡but¡¡they¡¡break¡¡and¡¡you¡¡need¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡wash¡¡them¡£¡¡Paper¡¡plates¡¡are¡¡used¡¡once¡¡and¡¡thrown¡¡away¡£¡¡Of¡¡course£»¡¡with¡¡paper¡¡plates¡¡you¡¡have¡¡recycling¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡issues¡¡that¡¡you¡¡don¡¯t¡¡have¡¡in¡¡£»¡¡because¡¡the¡¡memory¡¡is¡¡recycled¡¡for¡¡you¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡property¡¡¡¡Identifier¡¡identifies¡¡the¡¡workbook¡¡represented¡¡by¡¡the¡¡current¡¡¡¡IWorkbook¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡object¡£¡¡The¡¡identifier¡¡might¡¡be¡¡a¡¡path¡¡or¡¡file¡¡name¡¡and¡¡is¡¡pletely¡¡dependent¡¡on¡¡the¡¡imple

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mentation¡¡of¡¡IWorkbook¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡321¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡299¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡default¡¡property£»¡¡Item£»¡¡is¡¡the¡¡primary¡¡way¡¡of¡¡getting¡¡and¡¡retrieving¡¡worksheets£»¡¡where¡¡¡¡

each¡¡worksheet¡¡is¡¡referenced¡¡using¡¡a¡¡string¡¡identifier¡£¡¡The¡¡identifier¡¡does¡¡not¡¡need¡¡to¡¡be¡¡a¡¡string¡ª¡¡

it¡¡could¡¡have¡¡been¡¡a¡¡custom¡¡type£»¡¡enumeration£»¡¡or¡¡interface¡¡that¡¡is¡¡implemented¡£¡¡Using¡¡a¡¡string¡¡¡¡

keeps¡¡things¡¡simple£»¡¡but¡¡there¡¡are¡¡maintenance¡¡issues¡£¡¡

¡¡¡¡¡¡¡¡¡¡Let¡¯s¡¡say¡¡all¡¡workbooks¡¡have¡¡a¡¡configuration¡¡worksheet¡£¡¡So¡¡for¡¡most¡¡of¡¡the¡¡code£»¡¡the¡¡string¡¡¡¡

identifier¡¡¡¡¡¨configuration¡¨¡¡is¡¡used¡£¡¡However£»¡¡a¡¡new¡¡programmer¡¡decides¡¡to¡¡use¡¡¡¡¡¨Configuration¡¨¡¡¡¡

£¨with¡¡a¡¡capital¡¡C£©¡£¡¡This¡¡slight¡¡change¡¡will¡¡cause¡¡problems¡¡because¡¡¡¡¡¨configuration¡¨¡¡is¡¡meant¡¡to¡¡¡¡

have¡¡a¡¡lowercase¡¡c¡£¡¡Here¡¯s¡¡the¡¡example£º¡¡



Dim¡¡workbook¡¡As¡¡IWorkbook¡¡

Dim¡¡worksheet1¡¡As¡¡IWorksheetBase¡¡=¡¡workbook£¨¡¨configuration¡¨£©¡¡

Dim¡¡worksheet2¡¡As¡¡IWorksheetBase¡¡=¡¡workbook£¨¡¨Configuration¡¨£©¡¡



¡¡¡¡¡¡¡¡¡¡This¡¡approach¡¡uses¡¡a¡¡buffer¡¡that¡¡is¡¡typed¡¡in¡¡by¡¡hand¡¡and¡¡is¡¡considered¡¡hard¡­coded¡£¡¡The¡¡¡¡

preferred¡¡alternative¡¡is¡¡to¡¡hard¡­code¡¡a¡¡structure¡¡that¡¡is¡¡then¡¡referenced¡¡throughout¡¡the¡¡source¡¡¡¡

code£»¡¡like¡¡this£º¡¡



Public¡¡Module¡¡WorksheetIdentifiers¡¡¡¡¡¡

¡¡¡¡¡¡¡¡Public¡¡Const¡¡Configuration¡¡As¡¡String¡¡=¡¡¡¨configuration¡¨¡¡

End¡¡Module¡¡



Dim¡¡workbook¡¡As¡¡IWorkbook¡¡

Dim¡¡worksheet1¡¡As¡¡IWorksheetBase¡¡=¡¡workbook£¨WorksheetIdentifiers¡£Configuration£©¡¡

Dim¡¡worksheet2¡¡As¡¡IWorksheetBase¡¡=¡¡workbook£¨WorksheetIdentifiers¡£Configuration£©¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡module¡¡WorksheetIdentifiers¡¡still¡¡contains¡¡a¡¡hard¡­coded¡¡string¡¡buffer£»¡¡but¡¡this¡¡buffer¡¡¡¡

has¡¡been¡¡centralized¡¡to¡¡a¡¡single¡¡location¡£¡¡The¡¡workbook¡¡default¡¡property¡¡references¡¡the¡¡identifier¡¡¡¡

within¡¡the¡¡class¡¡WorksheetIdentifiers¡£¡¡Thus£»¡¡if¡¡you¡¡change¡¡the¡¡class¡¡WorksheetIdentifiers£»¡¡you¡¡¡¡

also¡¡change¡¡the¡¡identifiers¡¡used¡¡by¡¡the¡¡default¡¡property¡£¡¡That¡¡way£»¡¡the¡¡chances¡¡of¡¡having¡¡a¡¡typo¡¡¡¡

break¡¡an¡¡application¡¡are¡¡reduced¡£¡¡

¡¡¡¡¡¡¡¡¡¡Let¡¯s¡¡get¡¡back¡¡to¡¡the¡¡IWorkbook¡¡interface¡¡and£»¡¡in¡¡particular£»¡¡the¡¡default¡¡property¡£¡¡The¡¡default¡¡¡¡

property¡¡is¡¡of¡¡the¡¡type¡¡IWorksheetBase£»¡¡which¡¡is¡¡a¡¡bit¡¡tedious¡¡because¡¡the¡¡IWorksheetBase¡¡inter

face¡¡is¡¡a¡¡rudimentary¡¡interface¡¡and¡¡most¡¡likely¡¡not¡¡the¡¡interface¡¡that¡¡you¡¡will¡¡use£»¡¡because¡¡we¡¡¡¡

have¡¡¡¡IWorksheet£¨Of¡¡BaseType£©£»¡¡and¡¡therein¡¡lies¡¡the¡¡problem¡£¡¡To¡¡get¡¡an¡¡IWorksheet¡¡instance£»¡¡¡¡

you¡¡would¡¡need¡¡a¡¡cast£»¡¡as¡¡follows£º¡¡



Dim¡¡workbook¡¡As¡¡IWorkbook¡¡

Dim¡¡worksheet¡¡As¡¡IWorksheet£¨Of¡¡String£©¡¡=¡¡_¡¡¡¡

¡¡¡¡¡¡¡¡TryCast£¨workbook£¨WorksheetIdentifiers¡£Configuration£©£»¡¡IWorksheet£¨Of¡¡String£©£©¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡bolded¡¡code¡¡is¡¡the¡¡cast¡¡you¡¡need¡¡each¡¡and¡¡every¡¡time¡¡you¡¡want¡¡to¡¡reference¡¡an¡¡IWorksheet¡¡¡¡

instance¡£¡¡The¡¡cast¡¡is¡¡not¡¡a¡¡big¡¡deal£»¡¡but¡¡it¡¡is¡¡tedious¡£¡¡I¡¡personally¡¡would¡¡prefer¡¡being¡¡able¡¡to¡¡call¡¡¡¡

a¡¡property£»¡¡method£»¡¡or¡¡default¡¡property¡¡that¡¡returns¡¡the¡¡type¡¡I¡¡want¡£¡¡

¡¡¡¡¡¡¡¡¡¡Therein¡¡lies¡¡the¡¡problem£»¡¡because¡¡the¡¡way¡¡I¡¡want¡¡to¡¡use¡¡a¡¡default¡¡property£»¡¡property£»¡¡or¡¡¡¡

method¡¡is¡¡as¡¡a¡¡mixed¡¡type£»¡¡and¡¡you¡¡can¡¯t¡¡define¡¡a¡¡default¡¡property¡¡with¡¡mixed¡¡types¡£¡¡You¡¡can¡¡¡¡

define¡¡a¡¡default¡¡property¡¡that¡¡is¡¡a¡¡fixed¡¡type¡£¡¡To¡¡understand¡¡this¡¡problem£»¡¡look¡¡at¡¡the¡¡following¡¡¡¡

declaration¡¡of¡¡a¡¡workbook£»¡¡which¡¡does¡¡pile¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡322¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

300¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Imports¡¡System¡£Reflection¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Imports¡¡Devspace¡£Trader¡£mon¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Interface¡¡IWorkbook£¨Of¡¡BaseType£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡IDebug¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Default¡¡Property¡¡Item£¨ByVal¡¡identifier¡¡As¡¡String£©¡¡As¡¡IWorksheet£¨Of¡¡BaseType£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ReadOnly¡¡Property¡¡Identifier£¨£©¡¡As¡¡String¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡this¡¡declaration¡¡of¡¡IWorkbook£»¡¡a¡¡¡¡generics¡¡type¡¡is¡¡used£»¡¡but¡¡then¡¡the¡¡problem¡¡is¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡default¡¡property¡¡can¡¡return¡¡only¡¡IWorksheet¡¡instances¡¡of¡¡a¡¡single¡¡type£»¡¡such¡¡as¡¡Double¡¡or¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡String¡£¡¡Remember¡¡that¡¡there¡¡are¡¡multiple¡¡worksheet¡¡types¡¡£¨as¡¡illustrated¡¡in¡¡Figure¡¡11¡­2£©¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡What¡¡we¡¡want¡¡to¡¡do¡¡is¡¡use¡¡method¡­level¡¡¡¡generics¡¡declarations£»¡¡like¡¡this£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Interface¡¡IMixedType¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Default¡¡Property¡¡Item£¨Of¡¡BaseType£©£¨ByVal¡¡identifier¡¡As¡¡String£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡As¡¡IWorksheet£¨Of¡¡BaseType£©¡¡¡¡¡¡¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡problem¡¡with¡¡the¡¡method¡­level¡¡declaration¡¡is¡¡that¡¡it¡¡does¡¡not¡¡pile¡£¡¡There¡¡are¡¡two¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ways¡¡to¡¡declare¡¡a¡¡¡¡generics¡¡parameter¡£¡¡The¡¡first¡¡is¡¡what¡¡you¡¡have¡¡seen¡¡the¡¡most¡¡often£»¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡is¡¡at¡¡the¡¡type¡¡level£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡MyType£¨Of¡¡GenericType£©¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Declaring¡¡at¡¡the¡¡type¡¡level¡¡means¡¡that¡¡whenever¡¡you¡¡use¡¡the¡¡type¡¡and¡¡specify¡¡a¡¡type¡¡for¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡generics¡¡parameter£»¡¡MyType¡¡bees¡¡fixed¡¡to¡¡a¡¡certain¡¡type¡£¡¡So¡¡say¡¡you¡¡declared¡¡MyType¡¡as¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡cls¡¡As¡¡MyType¡¡=¡¡New¡¡MyType£¨Of¡¡Integer£©¡¡£¨£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Now¡¡any¡¡references¡¡to¡¡GenericType¡¡within¡¡MyType¡¡will¡¡bee¡¡¡¡Integer¡£¡¡This¡¡form¡¡of¡¡¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡generics¡¡solves¡¡many¡¡problems£»¡¡as¡¡illustrated¡¡in¡¡Chapter¡¡9¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡But¡¡in¡¡the¡¡case¡¡of¡¡the¡¡IWorkbook£»¡¡we¡¡don¡¯t¡¡want¡¡a¡¡fixed¡¡type¡£¡¡We¡¡want¡¡the¡¡ability¡¡to¡¡have¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡collection¡¡type¡¡contain¡¡mixed¡¡types¡¡of¡¡IWorksheet¡£¡¡The¡¡way¡¡to¡¡achieve¡¡that¡¡is¡¡to¡¡use¡¡¡¡generics¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡methods£»¡¡like¡¡this£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Function¡¡Method£¨Of¡¡GenericType£©£¨£©¡¡As¡¡MyType£¨Of¡¡GenericType£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Function¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Now¡¡the¡¡¡¡generics¡¡parameter¡¡is¡¡associated¡¡with¡¡the¡¡method£»¡¡rather¡¡than¡¡the¡¡type¡£¡¡And¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡means¡¡MyType¡¡can¡¡mix¡¡types¡£¡¡So¡¡we¡¡could¡¡have¡¡different¡¡IWorksheet¡¡types¡¡in¡¡a¡¡single¡¡work

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡book¡£¡¡And¡¡wouldn¡¯t¡¡it¡¡be¡¡great¡¡if¡¡there¡¡were¡¡a¡¡default¡¡property¡¡with¡¡mixed¡¡types£¿¡¡But¡¡you¡¡can¡¯t¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡have¡¡¡¡generics¡¡default¡¡properties¡¡and¡¡properties¡¡that¡¡are¡¡not¡¡declared¡¡at¡¡the¡¡type¡¡level¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Thus£»¡¡the¡¡use¡¡of¡¡a¡¡¡¡generics¡¡parameter¡¡with¡¡a¡¡default¡¡property¡¡or¡¡property¡¡will¡¡not¡¡work¡£¡¡In¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡my¡¡opinion£»¡¡that¡¡is¡¡a¡¡real¡¡design¡¡flaw¡¡in¡¡Visual¡¡Basic£»¡¡because¡¡it¡¡means¡¡we¡¡need¡¡to¡¡write¡¡code¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡like¡¡this£º¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡323¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡301¡¡



Imports¡¡Devspace¡£Trader¡£mon¡¡

Imports¡¡System¡£Reflection¡¡



¡¡_¡¡

Public¡¡Interface¡¡IWorkbook¡¡

¡¡¡¡¡¡¡¡Inherits¡¡IDebug¡¡



¡¡¡¡¡¡¡¡Function¡¡GetSheet£¨Of¡¡BaseType£©£¨ByVal¡¡identifier¡¡As¡¡String£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡As¡¡IWorksheet£¨Of¡¡BaseType£©¡¡

¡¡¡¡¡¡¡¡ReadOnly¡¡Property¡¡Identifier£¨£©¡¡As¡¡String¡¡

¡¡¡¡¡¡¡¡Default¡¡Property¡¡Item£¨ByVal¡¡identifier¡¡As¡¡String£©¡¡As¡¡IWorksheetBase¡¡

End¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡In¡¡this¡¡modified¡¡declaration£»¡¡the¡¡method¡¡GetSheet£¨£©¡¡acts¡¡like¡¡the¡¡Get¡¡part¡¡of¡¡the¡¡default¡¡¡¡

property£»¡¡but¡¡notice¡¡where¡¡the¡¡¡¡generics¡¡parameter¡¡BaseType¡¡is¡¡declared¡£¡¡The¡¡declaration¡¡¡¡

is¡¡after¡¡the¡¡method¡¡identifier¡¡and¡¡before¡¡the¡¡first¡¡bracket¡£¡¡In¡¡the¡¡case¡¡of¡¡IWorkbook£»¡¡we¡¡use¡¡the¡¡¡¡

method¡­level¡¡¡¡generics¡¡parameter¡¡to¡¡allow¡¡the¡¡caller¡¡to¡¡determine¡¡the¡¡type¡¡of¡¡the¡¡work

sheet¡¡instances¡£¡¡The¡¡implementation¡¡of¡¡IWorkbook¡¡has¡¡to¡¡do¡¡nothing¡¡other¡¡than¡¡perform¡¡the¡¡¡¡

appropriate¡¡cast¡£¡¡Method¡­level¡¡¡¡generics¡¡parameters¡¡are¡¡great¡¡when¡¡you¡¡are¡¡dealing¡¡with¡¡¡¡

mixed¡¡types£»¡¡as¡¡in¡¡the¡¡case¡¡of¡¡IWorkbook¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡code¡¡to¡¡retrieve¡¡a¡¡worksheet¡¡that¡¡previously¡¡needed¡¡a¡¡cast¡¡is¡¡rewritten¡¡as¡¡follows£º¡¡



Dim¡¡workbook¡¡As¡¡IWorkbook¡¡

Dim¡¡worksheet¡¡As¡¡IWorksheet£¨Of¡¡String£©¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡workbook¡£GetSheet£¨Of¡¡String£©£¨WorksheetIdentifiers¡£Configuration£©¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡cast¡¡has¡¡not¡¡disappeared¡¡pletely¡£¡¡It¡¡is¡¡done¡¡for¡¡us¡¡in¡¡the¡¡implementation¡¡of¡¡the¡¡¡¡

GetSheet£¨Of¡¡BaseType£©£¨£©¡¡method£»¡¡as¡¡demonstrated¡¡by¡¡the¡¡following¡¡code¡£¡¡



Friend¡¡Class¡¡Workbook¡¡

¡¡¡¡¡¡¡¡Implemen
·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨11£© ²È£¨11£©
¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿!
ÎÂÜ°Ìáʾ£º ο´Ð¡ËµµÄͬʱ·¢±íÆÀÂÛ£¬Ëµ³ö×Ô¼ºµÄ¿´·¨ºÍÆäËüС»ï°éÃÇ·ÖÏíÒ²²»´íŶ£¡·¢±íÊéÆÀ»¹¿ÉÒÔ»ñµÃ»ý·ÖºÍ¾­Ñé½±Àø£¬ÈÏÕæдԭ´´ÊéÆÀ ±»²ÉÄÉΪ¾«ÆÀ¿ÉÒÔ»ñµÃ´óÁ¿½ð±Ò¡¢»ý·ÖºÍ¾­Ñé½±ÀøŶ£¡