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

µÚ108ÕÂ

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

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

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






¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡retval¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡SyncLock¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡FunctionEnd¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡bolded¡¡code¡¡shows¡¡that¡¡there¡¡is¡¡still¡¡a¡¡cast£»¡¡but¡¡the¡¡type¡¡cast¡¡is¡¡in¡¡the¡¡method£»¡¡and¡¡it¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡uses¡¡the¡¡¡¡generics¡¡parameter¡¡declared¡¡at¡¡the¡¡method¡¡level¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡The¡¡SyncLock¡¡keyword¡¡ensures¡¡that¡¡the¡¡code¡¡in¡¡this¡¡method¡¡is¡¡not¡¡executed¡¡by¡¡more¡¡than¡¡one¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡thread¡¡at¡¡a¡¡time¡£¡¡That¡¡way£»¡¡the¡¡calling¡¡code¡¡always¡¡gets¡¡back¡¡the¡¡correct¡¡sheet¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implementing¡¡the¡¡Server¡¡Spreadsheet¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Now¡¡let¡¯s¡¡look¡¡at¡¡how¡¡the¡¡workbook¡¡and¡¡worksheet¡¡are¡¡implemented¡£¡¡I¡¡will¡¡explain¡¡only¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡important¡¡pieces£»¡¡but¡¡all¡¡of¡¡the¡¡code¡¡is¡¡available¡¡for¡¡download¡¡from¡¡the¡¡Source/Downloads¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡area¡¡of¡¡the¡¡Apress¡¡web¡¡site¡¡£¨http£º//apress¡££©¡£¡¡The¡¡class¡¡Worksheet£¨Of¡¡BaseType£©¡¡imple

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ments¡¡the¡¡interface¡¡IWorksheet£»¡¡but¡¡does¡¡not¡¡specify¡¡on¡¡which¡¡type¡¡the¡¡worksheet¡¡should¡¡be¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡based¡£¡¡In¡¡this¡¡application£»¡¡we¡¡also¡¡have¡¡a¡¡class¡¡called¡¡TraderBaseClass¡£¡¡In¡¡most¡¡applications£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡there¡¡is¡¡some¡¡functionality¡¡that¡¡most¡¡classes¡¡will¡¡need¡£¡¡That¡¡mon¡¡functionality¡¡is¡¡what¡¡I¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡call¡¡a¡¡domain¡­specific¡¡base¡¡class¡£¡¡In¡¡the¡¡case¡¡of¡¡TraderBaseClass£»¡¡that¡¡is¡¡the¡¡implementation¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡IDebug¡¡interface¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Using¡¡Lambda¡¡Expressions¡¡in¡¡the¡¡Spreadsheet¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡data¡¡members¡¡of¡¡Worksheet£¨Of¡¡BaseType£©¡¡are¡¡very¡¡similar¡¡to¡¡the¡¡previously¡¡defined¡¡spread

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡sheet¡¡class£»¡¡except¡¡the¡¡declarations¡¡are¡¡lambda¡­ready¡£¡¡Lambda¡­ready¡¡means¡¡that¡¡you¡¡use¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Func£¨Of¡¡£©¡¡type¡¡whenever¡¡you¡¡want¡¡to¡¡declare¡¡a¡¡variable¡¡that¡¡references¡¡a¡¡lambda¡¡expression¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡three¡¡data¡¡members¡¡are¡¡used¡¡to¡¡store¡¡the¡¡state¡¡of¡¡the¡¡cell£»¡¡cell¡¡calculations¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡will¡¡calculate¡¡the¡¡state¡¡of¡¡a¡¡cell£»¡¡and¡¡cell¡¡calculations¡¡that¡¡calculate¡¡the¡¡state¡¡of¡¡cells¡¡for¡¡an¡¡entire¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡column¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡Cells¡¡As¡¡Func£¨Of¡¡IWorksheet£¨Of¡¡BaseType£©£»¡¡Integer£»¡¡Integer£»¡¡BaseType£©£¨£»£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡CellState¡¡As¡¡BaseType£¨£»£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡ColCells¡¡As¡¡Func£¨Of¡¡IWorksheet£¨Of¡¡BaseType£©£»¡¡Integer£»¡¡Integer£»¡¡BaseType£©£¨£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡data¡¡member¡¡CellState¡¡contains¡¡the¡¡state¡¡of¡¡the¡¡worksheet¡¡cell£»¡¡and¡¡its¡¡type¡¡is¡¡BaseType£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡meaning¡¡that¡¡the¡¡type¡¡of¡¡the¡¡worksheet¡¡cell¡¡is¡¡whatever¡¡BaseType¡¡is¡¡declared¡¡as¡£¡¡The¡¡data¡¡members¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Cells¡¡and¡¡ColCells¡¡are¡¡declared¡¡as¡¡lambda¡¡expression¡¡references£»¡¡where¡¡there¡¡are¡¡three¡¡param

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡eters¡¡and¡¡a¡¡return¡¡value¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Before¡¡I¡¡continue¡¡with¡¡the¡¡lambda¡¡expression¡¡explanation£»¡¡I¡¡want¡¡to¡¡shift¡¡focus¡¡to¡¡illustrate¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡problem¡£¡¡We¡¡are¡¡going¡¡to¡¡play¡¡a¡¡game¡¡of¡¡what¡¡animal¡¡am¡¡I£»¡¡where¡¡we¡¯ll¡¡use¡¡lambda¡¡expressions¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡in¡¡conjunction¡¡with¡¡a¡¡closure¡£¡¡The¡¡idea¡¡is¡¡to¡¡store¡¡the¡¡identifier¡¡of¡¡the¡¡animal¡¡in¡¡a¡¡closure¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡then¡¡return¡¡it¡¡when¡¡it¡¯s¡¡requested¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡325¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡animals£¨1£©¡¡As¡¡Func£¨Of¡¡String£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡animal¡¡As¡¡String¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡animal¡¡=¡¡¡¨cow¡¨¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡animals£¨0£©¡¡=¡¡Function£¨£©¡¡animal¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡animal¡¡=¡¡¡¨horse¡¨¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡animals£¨1£©¡¡=¡¡Function£¨£©¡¡animal¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡Each¡¡callAnimal¡¡In¡¡animals¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£Write¡¡£¨¡¨£¨¡¨¡¡&¡¡callAnimal£¨£©¡¡&¡¡¡¨£©¡¨£©¡¡

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



¡¡¡¡¡¡¡¡¡¡The¡¡example¡¡creates¡¡an¡¡array¡¡of¡¡lambda¡¡expressions¡¡£¨animals£©¡¡where¡¡space¡¡for¡¡two¡¡lambda¡¡¡¡

expressions¡¡is¡¡allocated¡£¡¡The¡¡individual¡¡lambda¡¡expressions¡¡will¡¡reference¡¡a¡¡variable¡¡animal£»¡¡¡¡

which¡¡contains¡¡the¡¡animal¡¡of¡¡the¡¡lambda¡¡expression¡£¡¡In¡¡the¡¡code£»¡¡the¡¡lambda¡¡expressions¡¡are¡¡¡¡

assigned¡¡when¡¡the¡¡state¡¡of¡¡animal¡¡changes¡¡from¡¡cow¡¡to¡¡¡¡horse¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡Let¡¯s¡¡say¡¡you¡¡run¡¡the¡¡code£»¡¡and¡¡Console¡£WriteLine£¨£©¡¡generates¡¡its¡¡output¡£¡¡What¡¡do¡¡you¡¡¡¡

think¡¡the¡¡animals¡¡will¡¡be£¿¡¡Do¡¡you¡¡expect¡¡cow¡¡and¡¡¡¡horse£»¡¡respectively£¿¡¡Here¡¯s¡¡the¡¡output£º¡¡



£¨horse£©¡¡£¨horse£©¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡generated¡¡output¡¡is¡¡not¡¡what¡¡you¡¡would¡¡expect¡£¡¡This¡¡demonstrates¡¡that¡¡lambda¡¡expres

sions¡¡are¡¡stateless¡£¡¡Yet¡¡in¡¡earlier¡¡explanations¡¡of¡¡lambda¡¡expressions¡¡and¡¡closures£»¡¡I¡¡said¡¡that¡¡¡¡

variables¡¡can¡¡be¡¡stored¡¡in¡¡lambda¡¡expressions¡£¡¡Since¡¡animal¡¡is¡¡a¡¡value¡¡type£»¡¡you¡¡would¡¡expect¡¡¡¡

two¡¡copies¡¡of¡¡animal£»¡¡right£¿¡¡Wrong¡£¡¡

¡¡¡¡¡¡¡¡¡¡Closures¡¡do¡¡work£»¡¡and¡¡variable¡¡state¡¡is¡¡kept¡¡across¡¡lambda¡¡expressions¡£¡¡The¡¡mistake¡¡in¡¡this¡¡¡¡

code¡¡is¡¡that¡¡the¡¡same¡¡variable¡¡is¡¡referenced¡¡by¡¡two¡¡lambda¡¡expressions¡£¡¡Thus£»¡¡when¡¡the¡¡two¡¡¡¡

lambda¡¡expressions¡¡execute£»¡¡they¡¡will¡¡reference¡¡the¡¡same¡¡animal£»¡¡which¡¡was¡¡last¡¡assigned¡¡to¡¡be¡¡¡¡

a¡¡horse¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡The¡¡code¡¡that¡¡solves¡¡the¡¡problem¡¡uses¡¡two¡¡unique¡¡variables£»¡¡as¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡animals£¨1£©¡¡As¡¡Func£¨Of¡¡String£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡animal1¡¡=¡¡¡¨cow¡¨¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡animals£¨0£©¡¡=¡¡Function£¨£©¡¡animal1¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡animal2¡¡=¡¡¡¨horse¡¨¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡animals£¨1£©¡¡=¡¡Function£¨£©¡¡animal2¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡Each¡¡callAnimal¡¡In¡¡animals¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨callAnimal£¨£©£©¡¡

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


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡326¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡time¡¡when¡¡you¡¡run¡¡the¡¡code£»¡¡you¡¡get¡¡the¡¡following¡¡output¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡cow¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡horse¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Returning¡¡to¡¡the¡¡spreadsheet¡¡example£»¡¡the¡¡problem¡¡is¡¡that¡¡the¡¡behavior¡¡just¡¡described¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡means¡¡this¡¡code¡¡won¡¯t¡¡work£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡myWorksheet¡¡As¡¡IWorksheet£¨Of¡¡Double£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡row¡¡As¡¡Integer¡¡=¡¡0¡¡To¡¡10¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡myWorksheet¡£AssignCellCalculation£¨row£»¡¡1£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Function£¨worksheet£»¡¡cellRow£»¡¡cellCol£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡myWorksheet¡£GetCellState£¨row£»¡¡0£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡myWorksheet¡£Calculate£¨10£»¡¡0£©£©¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡whereas¡¡this¡¡code¡¡would¡¡work£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡myWorksheet¡¡As¡¡IWorksheet£¨Of¡¡Double£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡row¡¡As¡¡Integer¡¡=¡¡0¡¡To¡¡10¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡temp¡¡=¡¡row¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡myWorksheet¡£AssignCellCalculation£¨row£»¡¡1£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Function£¨worksheet£»¡¡cellRow£»¡¡cellCol£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡myWorksheet¡£GetCellState£¨temp£»¡¡0£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡myWorksheet¡£Calculate£¨10£»¡¡0£©£©¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡difference¡¡between¡¡the¡¡two¡¡pieces¡¡of¡¡code¡¡is¡¡that¡¡the¡¡second¡¡one¡¡has¡¡the¡¡lambda¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡expression¡¡that¡¡uses¡¡the¡¡variable¡¡declared¡¡temp¡¡in¡¡the¡¡context¡¡of¡¡a¡¡loop¡£¡¡For¡¡each¡¡iteration¡¡of¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡loop£»¡¡a¡¡new¡¡instance¡¡of¡¡temp¡¡is¡¡allocated£»¡¡and¡¡hence¡¡each¡¡lambda¡¡expression¡¡has¡¡its¡¡own¡¡instance¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡of¡¡the¡¡row¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Assigning¡¡State¡¡Without¡¡Knowing¡¡the¡¡Type¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡using¡¡¡¡generics¡¡types£»¡¡one¡¡of¡¡the¡¡most¡¡mon¡¡problems¡¡occurs¡¡when¡¡you¡¡need¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡work¡¡with¡¡proper¡¡types¡£¡¡In¡¡the¡¡implementation¡¡of¡¡the¡¡IWorksheet¡¡interface£»¡¡it¡¡is¡¡necessary¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡implement¡¡the¡¡AssignCellState£¨£©¡¡method¡¡defined¡¡in¡¡the¡¡interface¡¡¡¡IWorksheetSerialize¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡explanation¡¡of¡¡IWorksheetSerialize¡¡is¡¡slightly¡¡plicated¡¡and¡¡relates¡¡to¡¡the¡¡problem¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡of¡¡loading¡¡an¡¡IWorksheet¡¡without¡¡knowing¡¡the¡¡type¡£¡¡Say¡¡that¡¡you¡¡are¡¡saving¡¡an¡¡¡¡IWorkbook¡¡with¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡multiple¡¡IWorksheet¡¡instances¡£¡¡Each¡¡¡¡IWorksheet¡¡instance¡¡is¡¡a¡¡specific¡¡type¡£¡¡When¡¡you¡¡want¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡load¡¡an¡¡¡¡IWorkbook£»¡¡how¡¡does¡¡the¡¡loader¡¡know¡¡which¡¡types¡¡there¡¡are£¿¡¡The¡¡answer¡¡is¡¡that¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡loader¡¡does¡¡not£»¡¡and¡¡thus¡¡must¡¡first¡¡load¡¡a¡¡general¡¡type£»¡¡and¡¡then¡¡make¡¡a¡¡specific¡¡cast¡£¡¡Take¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡look¡¡at¡¡the¡¡serialization¡¡source¡¡code¡¡in¡¡the¡¡project¡¡Devspace¡£Trader¡£mon¡¡and¡¡the¡¡namespace¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Devspace¡£Trader¡£mon¡£ServerSpreadsheet¡£SerializerImpls£»¡¡available¡¡as¡¡part¡¡of¡¡the¡¡down

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡loadable¡¡code¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡327¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A

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

Äã¿ÉÄÜϲ»¶µÄ