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

µÚ24²¿·Ö

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

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

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




¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡four£»¡¡but¡¡with¡¡a¡¡German¡¡culture£»¡¡it¡¡is¡¡one¡¡point¡¡two¡¡three¡¡four¡¡£¨for¡¡those¡¡who¡¡do¡¡not¡¡know¡¡about¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡German¡¡formatting£»¡¡a¡¡ma¡¡is¡¡used¡¡as¡¡a¡¡decimal¡¡separator£»¡¡and¡¡a¡¡period¡¡is¡¡used¡¡as¡¡a¡¡thousands¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡separator£©¡£¡¡One¡¡way¡¡to¡¡change¡¡the¡¡culture¡¡is¡¡with¡¡the¡¡dialog¡¡box¡¡shown¡¡earlier¡¡in¡¡Figure¡¡3¡­12¡£¡¡The¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡second¡¡way¡¡to¡¡change¡¡the¡¡culture¡¡is¡¡at¡¡a¡¡programmatic¡¡level£»¡¡as¡¡in¡¡this¡¡code£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Imports¡¡System¡£Threading¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Thread¡£CurrentThread¡£CurrentCulture¡¡=¡¡new¡¡CultureInfo£¨¡¨en¡­CA¡¨£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡example£»¡¡a¡¡new¡¡instance¡¡of¡¡CultureInfo¡¡is¡¡created¡¡with¡¡the¡¡culture¡¡information¡¡en¡­CA¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Next¡¡is¡¡an¡¡example¡¡that¡¡processes¡¡a¡¡double¡¡number¡¡encoded¡¡using¡¡German¡¡formatting¡¡rules£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡TestGermanParseNumber£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Thread¡£CurrentThread¡£CurrentCulture¡¡=¡¡new¡¡CultureInfo£¨¡¨de¡­DE¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡value¡¡As¡¡Double¡¡=¡¡Double¡£Parse£¨¡¨1£»234¡¨£©¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡example¡¡assigns¡¡the¡¡de¡­DE¡¡culture¡¡information¡¡to¡¡the¡¡currently¡¡executing¡¡thread¡£¡¡Then¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡whenever¡¡any¡¡parsing¡¡routines¡¡are¡¡used£»¡¡German¡¡from¡¡Germany¡¡is¡¡used¡¡as¡¡the¡¡basis¡¡for¡¡the¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡95¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡3¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡ST¡¡R¡¡I¡¡N¡¡G¡¡¡¡¡¡M¡¡A¡¡N¡¡I¡¡PU¡¡L¡¡A¡¡TI¡¡O¡¡N¡¡S¡¡¡¡73¡¡



formatting¡¡rules¡£¡¡Changing¡¡the¡¡culture¡¡information¡¡does¡¡not¡¡affect¡¡the¡¡formatting¡¡rules¡¡of¡¡the¡¡¡¡

programming¡¡language¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡It¡¡is¡¡also¡¡possible¡¡to¡¡parse¡¡dates¡¡and¡¡times¡¡using¡¡the¡¡Parse£¨£©¡¡and¡¡TryParse£¨£©¡¡routines£»¡¡as¡¡¡¡

demonstrated¡¡by¡¡the¡¡following¡¡examples£º¡¡



Public¡¡Sub¡¡TestGermanParseDate£¨£©¡¡

¡¡¡¡¡¡¡¡Dim¡¡datetime¡¡As¡¡Date¡¡=¡¡Date¡£Parse£¨¡¨May¡¡10£»¡¡2008¡¨£©¡¡

¡¡¡¡¡¡¡¡If¡¡5¡¡=¡¡datetime¡£Month¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¡¡¨correct¡¨£©¡¡

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

¡¡¡¡¡¡¡¡Thread¡£CurrentThread¡£CurrentCulture¡¡=¡¡new¡¡CultureInfo£¨¡¨de¡­DE¡¨£©¡¡

¡¡¡¡¡¡¡¡datetime¡¡=¡¡Date¡£Parse£¨¡¨10¡¡Mai£»¡¡2008¡¨£©¡¡

¡¡¡¡¡¡¡¡If¡¡5¡¡=¡¡datetime¡£Month¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¡¡¨correct¡¨£©¡¡

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

¡¡¡¡¡¡¡¡¡¡

End¡¡Sub¡¡



¡¡¡¡¡¡¡¡¡¡Notice¡¡how¡¡the¡¡first¡¡Date¡£Parse£¨£©¡¡processed¡¡English¡­Canadian¡¡formatted¡¡text¡¡and¡¡knew¡¡¡¡

that¡¡the¡¡identifier¡¡May¡¡equaled¡¡the¡¡fifth¡¡month¡¡of¡¡the¡¡year¡£¡¡For¡¡the¡¡second¡¡Date¡£Parse£¨£©¡¡method¡¡¡¡

call£»¡¡the¡¡culture¡¡was¡¡changed¡¡to¡¡German£»¡¡and¡¡it¡¡was¡¡possible¡¡to¡¡process¡¡10¡¡Mai£»¡¡2008¡£¡¡In¡¡both¡¡¡¡

cases£»¡¡processing¡¡the¡¡buffer¡¡posed¡¡no¡¡major¡¡problems£»¡¡as¡¡long¡¡as¡¡you¡¡knew¡¡that¡¡the¡¡buffer¡¡was¡¡¡¡

a¡¡German¡¡or¡¡English¡­Canadian¡¡date¡£¡¡Where¡¡things¡¡can¡¡go¡¡awry¡¡is¡¡when¡¡you¡¡have¡¡a¡¡German¡¡¡¡

date¡¡and¡¡an¡¡English¡¡culture¡£¡¡

¡¡¡¡¡¡¡¡¡¡Converting¡¡a¡¡data¡¡type¡¡to¡¡a¡¡buffer¡¡is¡¡relatively¡¡easy¡¡because¡¡the¡¡ToString£¨£©¡¡methods¡¡have¡¡¡¡

been¡¡implemented¡¡to¡¡generate¡¡the¡¡desired¡¡output¡£¡¡Consider¡¡the¡¡following¡¡example£»¡¡which¡¡¡¡

generates¡¡a¡¡buffer¡¡from¡¡an¡¡integer¡¡value£º¡¡



Public¡¡Sub¡¡TestGenerateString£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡Dim¡¡iValue¡¡As¡¡Integer¡¡=¡¡123¡¡

¡¡¡¡¡¡¡¡Dim¡¡buffer¡¡As¡¡String¡¡=¡¡iValue¡£ToString£¨£©¡¡

¡¡¡¡¡¡¡¡If¡¡buffer¡¡=¡¡¡¨123¡¨¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¡¡¨correct¡¨£©¡¡

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

End¡¡Sub¡¡



¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡example£»¡¡the¡¡value¡¡123¡¡has¡¡been¡¡assigned¡¡to¡¡¡¡iValue£»¡¡which¡¡is¡¡of¡¡type¡¡Integer£»¡¡and¡¡¡¡

then¡¡its¡¡ToString£¨£©¡¡method¡¡is¡¡called£»¡¡which¡¡generates¡¡a¡¡buffer¡¡that¡¡contains¡¡¡¡¡¨123¡¨¡£¡¡The¡¡same¡¡¡¡

thing¡¡can¡¡be¡¡done¡¡to¡¡a¡¡Double¡¡value£»¡¡as¡¡in¡¡this¡¡example£º¡¡



Dim¡¡number¡¡As¡¡Double¡¡=¡¡123¡£5678¡¡

Dim¡¡buffer¡¡As¡¡String¡¡=¡¡number¡£ToString£¨¡¨0¡£00¡¨£©¡¡



¡¡¡¡¡¡¡¡¡¡Here£»¡¡the¡¡number¡¡123¡£5678¡¡is¡¡converted¡¡to¡¡a¡¡buffer¡¡using¡¡the¡¡ToString£¨£©¡¡method£»¡¡but¡¡¡¡

ToString£¨£©¡¡has¡¡a¡¡parameter£»¡¡which¡¡is¡¡a¡¡formatting¡¡instruction¡¡that¡¡indicates¡¡how¡¡the¡¡double¡¡¡¡

number¡¡should¡¡be¡¡generated¡¡as¡¡a¡¡buffer¡£¡¡The¡¡desired¡¡result¡¡is¡¡a¡¡buffer¡¡with¡¡a¡¡maximum¡¡of¡¡two¡¡¡¡

digits¡¡after¡¡the¡¡decimal¡¡point¡£¡¡Because¡¡the¡¡third¡¡digit¡¡after¡¡the¡¡decimal¡¡is¡¡a¡¡7£»¡¡the¡¡value¡¡is¡¡¡¡

rounded¡¡up£»¡¡resulting¡¡in¡¡the¡¡buffer¡¡123¡£57¡£¡¡

¡¡¡¡¡¡¡¡¡¡Let¡¯s¡¡see¡¡an¡¡example¡¡where¡¡the¡¡culture¡¡information¡¡also¡¡applies¡¡to¡¡generating¡¡a¡¡buffer¡£¡¡¡¡

Here£»¡¡a¡¡Double¡¡value¡¡is¡¡generated¡¡in¡¡the¡¡format¡¡of¡¡the¡¡culture£º¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡96¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

74¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡3¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡ST¡¡R¡¡I¡¡N¡¡G¡¡¡¡¡¡M¡¡A¡¡N¡¡I¡¡P¡¡U¡¡L¡¡AT¡¡IO¡¡N¡¡S¡¡¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡TestGenerateGermanNumber£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡number¡¡As¡¡Double¡¡=¡¡123¡£5678¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Thread¡£CurrentThread¡£CurrentCulture¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡new¡¡CultureInfo£¨¡¨de¡­DE¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡buffer¡¡As¡¡String¡¡=¡¡number¡£ToString£¨¡¨0¡£00¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡buffer¡¡=¡¡¡¨123£»57¡¨¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¡¡¨correct¡¨£©¡¡

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

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡As¡¡in¡¡the¡¡previous¡¡examples£»¡¡the¡¡CurrentCulture¡¡property¡¡is¡¡assigned¡¡the¡¡desired¡¡culture¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Then¡¡when¡¡the¡¡Double¡¡variable¡¡number¡¡has¡¡its¡¡ToString£¨£©¡¡method¡¡called£»¡¡the¡¡buffer¡¡¡¡¡¨123£»57¡¨¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡generated¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡Important¡¡Stuff¡¡to¡¡Remember¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡this¡¡chapter£»¡¡you¡¡learned¡¡about¡¡strings¡¡and¡¡writing¡¡code¡£¡¡Here¡¡are¡¡the¡¡keys¡¡points¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡remember£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Writing¡¡tests¡¡is¡¡an¡¡important¡¡part¡¡of¡¡your¡¡development¡¡practice¡£¡¡A¡¡test¡¡is¡¡not¡¡just¡¡a¡¡mech

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡anism¡¡to¡¡catch¡¡errors£»¡¡but¡¡also¡¡a¡¡mechanism¡¡used¡¡to¡¡understand¡¡the¡¡dynamics¡¡of¡¡your¡¡code¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡String¡¡type¡¡is¡¡a¡¡special¡¡reference¡¡type¡¡that¡¡has¡¡many¡¡methods¡¡and¡¡properties¡£¡¡You¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡are¡¡advised¡¡to¡¡look¡¡at¡¡the¡¡MSDN¡¡documentation¡¡to¡¡see¡¡what¡¡a¡¡string¡¡can¡¡do¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡IntelliSense¡¡and¡¡the¡¡MSDN¡¡documentation¡¡are¡¡your¡¡best¡¡bets¡¡when¡¡you¡¡want¡¡to¡¡find¡¡out¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡about¡¡specific¡¡methods£»¡¡properties£»¡¡or¡¡types¡£¡¡Books¡¡and¡¡web¡¡sites¡¡such¡¡as¡¡Code¡¡Project¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡are¡¡good¡¡resources¡¡to¡¡help¡¡you¡¡understand¡¡concepts¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡All¡¡variables¡¡and¡¡types¡¡are¡¡based¡¡on¡¡the¡¡object¡¡type¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡When¡¡writing¡¡code£»¡¡you¡¡need¡¡to¡¡define¡¡responsibilities¡¡and¡¡contexts¡£¡¡Don¡¯t¡¡fix¡¡bugs¡¡or¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡write¡¡code¡¡using¡¡knee¡­jerk¡¡reactions¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡All¡¡strings¡¡are¡¡based¡¡on¡¡Unicode¡£¡¡Each¡¡Unicode¡¡character¡¡is¡¡16¡¡bits¡¡wide¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡When¡¡translating¡¡buffers£»¡¡you¡¡need¡¡to¡¡deal¡¡with¡¡the¡¡translation¡¡of¡¡text¡¡and¡¡the¡¡translation¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡numbers¡¡and¡¡dates¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡¡¡includes¡¡sophisticated¡¡technology¡¡to¡¡help¡¡you¡¡translate¡¡numbers¡¡and¡¡dates¡¡using¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡bination¡¡of¡¡language¡¡and¡¡culture¡¡information¡£¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡97¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡3¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡ST¡¡R¡¡I¡¡N¡¡G¡¡¡¡¡¡M¡¡A¡¡N¡¡I¡¡PU¡¡L¡¡A¡¡TI¡¡O¡¡N¡¡S¡¡¡¡75¡¡



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



The¡¡following¡¡are¡¡some¡¡exercises¡¡that¡¡relate¡¡to¡¡what¡¡you¡¯ve¡¡learned¡¡in¡¡this¡¡chapter¡£¡¡



¡¡¡¡¡¡¡¡¡¡1¡£¡¡¡¡Finish¡¡the¡¡application¡¡to¡¡translate¡¡from¡¡one¡¡language¡¡to¡¡another¡¡language£»¡¡allowing¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡user¡¡to¡¡choose¡¡which¡¡direction¡¡the¡¡translation¡¡takes¡£¡¡



¡¡¡¡¡¡¡¡¡¡2¡£¡¡¡¡Extend¡¡the¡¡¡¡LanguageTranslator¡¡ponent¡¡to¡¡be¡¡able¡¡to¡¡translate¡¡the¡¡words¡¡¡¡au¡¡revoir¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡auf¡¡wiedersehen¡¡to¡¡good¡¡bye¡£¡¡



¡¡¡¡¡¡¡¡¡¡3¡£¡¡¡¡You¡¡can¡¡bine¡¡strings¡¡by¡¡using¡¡the¡¡plus¡¡sign£»¡¡but¡¡doing¡¡many¡¡additions¡¡will¡¡slow¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡down¡¡your¡¡code¡£¡¡Use¡¡the¡¡StringBuilder¡¡class¡¡to¡¡concatenate¡¡two¡¡buffers¡¡together¡£¡¡Hint£º¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡you¡¡want¡¡to¡¡convert¡¡the¡¡code¡¡String¡¡c¡¡=¡¡a¡¡£«¡¡b£»¡¡and¡¡make¡¡a¡¡and¡¡b¡¡use¡¡the¡¡StringBuilder¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡class¡£¡¡The¡¡result¡¡of¡¡the¡¡StringBuilder¡¡is¡¡assigned¡¡to¡¡the¡¡variable¡¡c¡£¡¡



¡¡¡¡¡¡¡¡¡¡4¡£¡¡¡¡Create¡¡a¡¡test¡¡that¡¡demonstrates¡¡what¡¡happens¡¡when¡¡a¡¡number¡¡value¡¡is¡¡added¡¡to¡¡a¡¡string¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡value¡£¡¡Write¡¡the¡¡appropriate¡¡tests¡¡to¡¡verify¡¡your¡¡conclusion¡£¡¡



¡¡¡¡¡¡¡¡¡¡5¡£¡¡¡¡Extend¡¡the¡¡¡¡LanguageTranslator¡¡ponent¡¡to¡¡include¡¡methods¡¡to¡¡translate¡¡English¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡numbers¡¡into¡¡German¡¡numbers¡£¡¡



¡¡¡¡¡¡¡¡¡¡6¡£¡¡¡¡Extend¡¡the¡¡LanguageTranslator¡¡ponent¡¡to¡¡include¡¡methods¡¡to¡¡translate¡¡dates¡¡from¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡American¡¡or¡¡Canadian¡¡dates¡¡into¡¡German¡¡dates¡£¡¡Note¡¡that¡¡the¡¡added¡¡wrinkle¡¡is¡¡that¡¡you¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡could¡¡input¡¡an¡¡American¡¡or¡¡Canadian¡¡date¡£¡¡



¡¡¡¡¡¡¡¡¡¡7¡£¡¡¡¡Implement¡¡the¡¡Windows¡¡application¡¡that¡¡calls¡¡the¡¡¡¡LanguageTranslator¡¡ponent¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡98¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡99¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



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



Learning¡¡About¡¡Data¡¡Structures£»¡¡¡¡

¡¡Decisions£»¡¡and¡¡Loops¡¡



When¡¡you¡¡are¡¡creating¡¡applications£»¡¡the¡¡source¡¡code¡¡will¡¡need¡¡to¡¡make¡¡decisions£»¡¡such¡¡as¡¡¡¡

should¡¡you¡¡open¡¡the¡¡file¡¡or¡¡save¡¡the¡¡file£¿¡¡And¡¡if¡¡you¡¡open¡¡the¡¡file£»¡¡what¡¡kind¡¡of¡¡iterative¡¡code¡¡is¡¡¡¡

going¡¡to¡¡read¡¡the¡¡contents¡¡of¡¡the¡¡file£¿¡¡These¡¡sorts¡¡of¡¡questions¡¡are¡¡answered¡¡by¡¡employing¡¡data¡¡¡¡

structures£»¡¡decisions£»¡¡and¡¡loops¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡easiest¡¡way¡¡to¡¡demonstrate¡¡how¡¡to¡¡make¡¡a¡¡decision¡¡is¡¡to¡¡write¡¡a¡¡miniature¡¡artificial¡¡¡¡

intelligence¡¡£¨AI£©¡¡system¡£¡¡The¡¡AI¡¡system¡¡will¡¡be¡¡extremely¡¡primitive£»¡¡but¡¡AI¡¡is¡¡interesting¡¡because¡¡¡¡

it¡¡makes¡¡extensive¡¡use¡¡of¡¡decision¡¡and¡¡loop¡¡constructs¡£¡¡The¡¡AI¡¡system¡¡iterates¡¡and¡¡makes¡¡deci

sions¡¡based¡¡on¡¡data¡¡defined¡¡in¡¡a¡¡neat¡¡and¡¡orderly¡¡custom¡¡data¡¡structure¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡Using¡¡the¡¡example¡¡of¡¡creating¡¡an¡¡algorithm£»¡¡the¡¡following¡¡topics¡¡will¡¡be¡¡covered¡¡in¡¡this¡¡¡¡

chapter£º¡¡



¡¡¡¡¡¡¡¡o¡¡¡¡Data¡¡structures£»¡¡including¡¡custom¡¡types¡¡



¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡restrictions¡¡of¡¡value¡¡types¡¡



¡¡¡¡¡¡¡¡o¡¡¡¡Algorithm¡¡design¡¡



¡¡¡¡¡¡¡¡o¡¡¡¡Class¡¡constructors£»¡¡which¡¡allow¡¡you¡¡to¡¡initialize¡¡an¡¡object¡¡



¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡For¡¡loop£»¡¡which¡¡allows¡¡you¡¡to¡¡iterate¡¡over¡¡sets¡¡of¡¡data¡¡



¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡If¡¡statement£»¡¡which¡¡allows¡¡you¡¡to¡¡execute¡¡specific¡¡code¡¡based¡¡on¡¡logic¡¡



Understanding¡¡the¡¡Depth¡­First¡¡Search¡¡Algorithm¡¡



AI¡¡involves¡¡searching¡¡for¡¡data£»¡¡and¡¡a¡¡core¡¡algorithm¡¡of¡¡AI¡¡is¡¡searching¡£¡¡The¡¡search¡¡algorithm¡¡¡¡

that¡¡we¡¡will¡¡develop¡¡for¡¡this¡¡chapter¡¯s¡¡example¡¡is¡¡a¡¡depth¡­first¡¡search¡¡system¡£¡¡AI¡¡has¡¡other¡¡types¡¡¡¡

of¡¡searches£»¡¡such¡¡as¡¡an¡¡A*¡¡or¡¡a¡¡breadth¡­first¡¡search£»¡¡but¡¡they¡¡are¡¡all¡¡based¡¡on¡¡the¡¡same¡¡idea¡¡as¡¡¡¡

the¡¡depth¡­search¡¡algorithm¡£¡¡This¡¡idea¡¡is¡¡searching¡¡for¡¡information¡¡that¡¡is¡¡arranged¡¡in¡¡a¡¡tree¡¡¡¡

structure¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡77¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡100¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

78¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡4¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I

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

Äã¿ÉÄÜϲ»¶µÄ