VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ71²¿·Ö
°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·ҳ£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡parameter¡¡results¡¡in¡¡a¡¡False¡¡value¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Another¡¡variation¡¡of¡¡the¡¡¡¡If¡¡function¡¡is¡¡a¡¡two¡parameter¡¡version¡¡that¡¡can¡¡be¡¡used¡¡to¡¡test¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡whether¡¡or¡¡not¡¡an¡¡object¡¡has¡¡a¡¡value¡¡of¡¡¡¡Nothing£»¡¡as¡¡follows£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡cleanUpList¡¡=¡¡Function£¨defaultObject¡¡As¡¡Object£©_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Function£¨objToTest¡¡As¡¡Object£©¡¡If£¨objToTest£»¡¡defaultObject£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡267¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡¡¡245¡¡
¡¡¡¡¡¡¡¡¡¡The¡¡implementation¡¡of¡¡the¡¡lambda¡¡expression¡¡has¡¡an¡¡¡¡If¡¡with¡¡two¡¡parameters¡£¡¡The¡¡first¡¡¡¡
parameter¡¡is¡¡the¡¡object¡¡to¡¡test¡¡for¡¡Nothing£»¡¡and¡¡the¡¡second¡¡parameter¡¡represents¡¡the¡¡expression¡¡¡¡
to¡¡execute¡¡if¡¡the¡¡object¡¡is¡¡Nothing¡£¡¡¡¡
Learning¡¡More¡¡About¡¡Collection¡¡Types¡¡
In¡¡the¡¡beginning¡¡of¡¡this¡¡chapter£»¡¡I¡¡talked¡¡about¡¡the¡¡different¡¡collection¡¡types£»¡¡but¡¡not¡¡how¡¡to¡¡use¡¡¡¡
them¡£¡¡This¡¡section¡¡presents¡¡examples¡¡of¡¡using¡¡the¡¡types¡£¡¡
Using¡¡a¡¡Plain¡Vanilla¡¡List¡¡
A¡¡plain¡vanilla¡¡list¡¡is¡¡a¡¡list¡¡of¡¡specific¡¡types¡¡such¡¡as¡¡¡¡Integer£»¡¡Double£»¡¡or¡¡some¡¡other¡¡object¡¡type¡£¡¡¡¡
Instantiate¡¡the¡¡list¡¡as¡¡follows£º¡¡
Dim¡¡lst¡¡As¡¡List£¨Of¡¡MyType£©¡¡=¡¡New¡¡List£¨Of¡¡MyType£©£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡The¡¡default¡¡type¡¡¡¡List¡¡is¡¡used¡¡for¡¡most¡¡of¡¡your¡¡coding¡¡situations£»¡¡but¡¡if¡¡you¡¡are¡¡adding¡¡and¡¡¡¡
removing¡¡elements¡¡frequently£»¡¡the¡¡following¡¡code¡¡is¡¡better¡£¡¡
Dim¡¡lst¡¡As¡¡IList£¨Of¡¡MyType£©¡¡=¡¡New¡¡LinkedList£¨Of¡¡MyType£©£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡The¡¡type¡¡¡¡LinkedList¡¡implements¡¡the¡¡logic¡¡that¡¡was¡¡presented¡¡in¡¡the¡¡previous¡¡chapter£»¡¡¡¡
whereas¡¡¡¡List¡¡manipulates¡¡a¡¡fixed¡length¡¡array¡£¡¡¡¡LinkedList¡¡has¡¡a¡¡downside¡¡in¡¡that¡¡it¡¡does¡¡not¡¡¡¡
support¡¡the¡¡IList¡¡interface£»¡¡and¡¡the¡¡sample¡¡code¡¡will¡¡not¡¡pile¡£¡¡Thus£»¡¡to¡¡make¡¡the¡¡code¡¡¡¡
work£»¡¡you¡¡would¡¡need¡¡to¡¡use¡¡¡¡ICollection£º¡¡
Dim¡¡lst¡¡As¡¡ICollection£¨Of¡¡MyType£©¡¡=¡¡New¡¡LinkedList£¨Of¡¡MyType£©£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡Add¡¡an¡¡element¡¡to¡¡¡¡IList¡¡as¡¡follows£º¡¡
lst¡£Add£¨New¡¡MyType£¨£©£©¡¡
¡¡¡¡¡¡¡¡¡¡To¡¡add¡¡elements¡¡to¡¡your¡¡list¡¡according¡¡to¡¡an¡¡order£»¡¡use¡¡the¡¡following¡¡form¡¡£¨note¡¡that¡¡¡¡
ICollection¡¡doesn¡¯t¡¡have¡¡this¡¡method£©¡£¡¡
lst¡£Insert£¨0£»¡¡New¡¡MyType£¨£©£©¡¡
¡¡¡¡¡¡¡¡¡¡This¡¡adds¡¡an¡¡element¡¡to¡¡the¡¡front¡¡of¡¡the¡¡list¡£¡¡If¡¡you¡¡are¡¡adding¡¡elements¡¡at¡¡the¡¡beginning¡¡of¡¡¡¡
the¡¡list¡¡or¡¡somewhere¡¡in¡¡the¡¡list£»¡¡it¡¡is¡¡better¡¡to¡¡use¡¡the¡¡¡¡LinkedList¡¡type£»¡¡as¡¡it¡¡is¡¡more¡¡efficient¡£¡¡¡¡
Using¡¡the¡¡class¡¡¡¡List¡¡incurs¡¡an¡¡array¡¡copy¡¡resource¡¡penalty¡£¡¡
¡¡¡¡¡¡¡¡¡¡You¡¡can¡¡also¡¡add¡¡one¡¡list¡¡to¡¡another£º¡¡
Dim¡¡lst¡¡As¡¡List£¨Of¡¡MyType£©¡¡=¡¡New¡¡List£¨Of¡¡MyType£©£¨£©¡¡
Dim¡¡lstToBeAdded¡¡As¡¡List£¨Of¡¡MyType£©¡¡
lst¡£AddRange£¨lstToBeAdded£©¡¡
lst¡£InsertRange£¨0£»¡¡lstToBeAdded£©¡¡
¡¡¡¡¡¡¡¡¡¡The¡¡AddRange£¨£©¡¡method¡¡is¡¡used¡¡to¡¡append¡¡the¡¡list¡¡lstToBeAdded¡¡to¡¡lst¡£¡¡The¡¡InsertRange£¨£©¡¡¡¡
method¡¡inserts¡¡all¡¡of¡¡the¡¡elements¡¡in¡¡lstToBeAdded¡¡to¡¡the¡¡front¡¡of¡¡the¡¡list¡¡lst¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡268¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
246¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Delete¡¡an¡¡element¡¡from¡¡the¡¡list¡¡like¡¡this£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡lst¡£Remove£¨existingMyType£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡Remove£¨£©¡¡method¡¡expects¡¡an¡¡instance¡¡of¡¡a¡¡type¡¡to¡¡remove¡¡from¡¡the¡¡list¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡delete¡¡a¡¡particular¡¡element¡¡at¡¡a¡¡particular¡¡index£»¡¡use¡¡the¡¡following¡¡form¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡lst¡£RemoveAt£¨0£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡code¡¡would¡¡remove¡¡the¡¡element¡¡at¡¡the¡¡front¡¡of¡¡the¡¡list¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Using¡¡a¡¡Key/Value¡¡Pair¡¡List¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡A¡¡key/value¡¡pair¡¡list¡¡is¡¡a¡¡list¡¡that¡¡has¡¡a¡¡cross¡reference¡£¡¡It¡¡is¡¡like¡¡a¡¡dictionary¡¡where¡¡you¡¡have¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡word¡¡and¡¡associated¡¡meaning¡£¡¡In¡¡puting¡¡terms£»¡¡the¡¡word¡¡is¡¡a¡¡type¡¡and¡¡its¡¡definition¡¡is¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡another¡¡type¡£¡¡The¡¡word¡¡is¡¡a¡¡key¡¡and¡¡the¡¡definition¡¡is¡¡a¡¡value¡£¡¡A¡¡key/value¡¡pair¡¡definition¡¡would¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡be¡¡as¡¡follows£»¡¡using¡¡the¡¡¡¡IDictionary¡¡interface¡¡and¡¡Dictionary¡¡class¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡dictionary¡¡As¡¡IDictionary£¨Of¡¡String£»¡¡Object£©¡¡=¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡New¡¡Dictionary£¨Of¡¡String£»¡¡Object£©£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡You¡¡could¡¡also¡¡use¡¡SortedDictionary£»¡¡but¡¡that¡¡implies¡¡the¡¡elements¡¡within¡¡the¡¡list¡¡are¡¡sorted¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡add¡¡values¡¡to¡¡the¡¡dictionary£»¡¡use¡¡the¡¡Add£¨£©¡¡method£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡dictionary¡£Add£¨¡¨List¡¨£»¡¡lst£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡dictionary¡£Add£¨¡¨List¡¡To¡¡Be¡¡Added¡¨£»¡¡lstToBeAdded£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡working¡¡with¡¡¡¡IDictionary¡¡objects£»¡¡you¡¡might¡¡want¡¡to¡¡know¡¡whether¡¡or¡¡not¡¡a¡¡key¡¡is¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡available¡£¡¡The¡¡following¡¡code¡¡is¡¡used¡¡to¡¡verify¡¡if¡¡a¡¡key¡¡exists¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡dictionary¡£ContainsKey£¨¡¨List¡¨£©¡¡Then¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¡¡¡£¡¡¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡you¡¡want¡¡to¡¡iterate¡¡the¡¡keys£»¡¡use¡¡this¡¡form£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡Each¡¡key¡¡As¡¡String¡¡In¡¡dictionary¡£Keys¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Next¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Iterate¡¡the¡¡values¡¡as¡¡follows£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡Each¡¡value¡¡As¡¡Object¡¡In¡¡dictionary¡£Values¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Next¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Using¡¡a¡¡Stack¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡A¡¡¡¡Stack¡¡is¡¡a¡¡special¡¡list¡¡that¡¡behaves¡¡like¡¡a¡¡stack¡¡of¡¡paper¡¡on¡¡a¡¡table¡£¡¡When¡¡you¡¡add¡¡three¡¡items¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡on¡¡the¡¡Stack£»¡¡the¡¡last¡¡one¡¡added¡¡to¡¡the¡¡Stack¡¡is¡¡the¡¡first¡¡one¡¡off¡¡the¡¡Stack¡£¡¡Here¡¡is¡¡an¡¡example¡¡of¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡using¡¡a¡¡Stack£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡269¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡¡¡247¡¡
Dim¡¡stack¡¡As¡¡Stack£¨Of¡¡String£©¡¡=¡¡New¡¡Stack£¨Of¡¡String£©£¨£©¡¡
stack¡£Push£¨¡¨first¡¨£©¡¡
stack¡£Push£¨¡¨second¡¨£©¡¡
stack¡£Push£¨¡¨third¡¨£©¡¡
Dim¡¡popped¡¡As¡¡String¡¡=¡¡stack¡£Pop£¨£©¡¡
If¡¡popped¡£pareTo£¨¡¨third¡¨£©¡¡=¡¡0¡¡Then¡¡
¡¡¡¡¡¡'¡¡This¡¡is¡¡what¡¡we¡¡expect¡¡
End¡¡If¡¡
¡¡¡¡¡¡¡¡¡¡The¡¡code¡¡demonstrates¡¡using¡¡the¡¡Push£¨£©¡¡method¡¡to¡¡push¡¡items¡¡on¡¡the¡¡stack¡¡and¡¡the¡¡Pop£¨£©¡¡¡¡
method¡¡to¡¡remove¡¡items¡¡from¡¡the¡¡stack¡£¡¡Remember¡¡that¡¡Push£¨£©¡¡is¡¡an¡¡explicit¡¡addition£»¡¡and¡¡¡¡
Pop£¨£©¡¡an¡¡explicit¡¡removal¡¡£¨though¡¡a¡¡call¡¡to¡¡Pop£¨£©¡¡returns¡¡the¡¡object¡¡removed¡¡from¡¡the¡¡stack¡¡so¡¡¡¡
you¡¡can¡¡do¡¡something¡¡with¡¡it£»¡¡as¡¡shown¡¡in¡¡the¡¡code£©¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡If¡¡you¡¡want¡¡to¡¡know¡¡what¡¡is¡¡on¡¡the¡¡top¡¡of¡¡the¡¡stack£»¡¡use¡¡Peek£¨£©£»¡¡which¡¡acts¡¡like¡¡Pop£¨£©£»¡¡except¡¡¡¡
it¡¡does¡¡not¡¡remove¡¡the¡¡item¡¡from¡¡the¡¡list¡£¡¡
Using¡¡a¡¡Queue¡¡
A¡¡Queue¡¡is¡¡another¡¡special¡¡type¡¡of¡¡list¡¡that¡¡behaves¡¡like¡¡a¡¡queue¡¡that¡¡you¡¡would¡¡encounter¡¡at¡¡¡¡
ticket¡¡counter¡£¡¡As¡¡people¡¡start¡¡queuing£»¡¡the¡¡first¡¡person¡¡to¡¡be¡¡served¡¡is¡¡the¡¡one¡¡at¡¡the¡¡front¡¡of¡¡the¡¡¡¡
line¡£¡¡Here¡¡is¡¡an¡¡example¡¡of¡¡using¡¡a¡¡Queue£º¡¡
Dim¡¡queue¡¡As¡¡Queue£¨Of¡¡String£©¡¡=¡¡New¡¡Queue£¨Of¡¡String£©£¨£©¡¡
queue¡£Enqueue£¨¡¨first¡¨£©¡¡
queue¡£Enqueue£¨¡¨second¡¨£©¡¡
queue¡£Enqueue£¨¡¨third¡¨£©¡¡
Dim¡¡dequeued¡¡As¡¡String¡¡=¡¡queue¡£Dequeue£¨£©¡¡
If¡¡dequeued¡¡=¡¡¡¨first¡¨¡¡Then¡¡
¡¡¡¡¡¡¡¡'¡¡This¡¡is¡¡what¡¡we¡¡expect¡¡
End¡¡If¡¡
The¡¡Important¡¡Stuff¡¡to¡¡Remember¡¡
In¡¡this¡¡chapter£»¡¡you¡¡learned¡¡about¡¡using¡¡delegates£»¡¡lambda¡¡expressions£»¡¡extension¡¡methods£»¡¡¡¡
and¡¡lists¡£¡¡The¡¡main¡¡items¡¡to¡¡remember¡¡are¡¡as¡¡follows£º¡¡
¡¡¡¡¡¡¡¡¡¡o¡¡You¡¡are¡¡using¡¡Visual¡¡Basic¡¡2008£»¡¡and¡¡thus¡¡you¡¡should¡¡use¡¡the¡¡¡¡generics¡based¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡collection¡¡classes¡£¡¡
¡¡¡¡¡¡¡¡¡¡o¡¡There¡¡are¡¡many¡¡different¡¡types¡¡of¡¡lists¡£¡¡The¡¡main¡¡types¡¡are¡¡the¡¡simple¡¡object¡¡collection£»¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡key/value¡¡collection£»¡¡stack£»¡¡and¡¡queue¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡270¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
248¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡¡¡¡¡generics¡based¡¡classes¡¡are¡¡type¡safe¡¡and¡¡have¡¡better¡¡performance¡¡than¡¡old¡style¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡collections¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Delegates¡¡help¡¡you¡¡define¡¡a¡¡generic¡¡method¡calling¡¡mechanism¡¡without¡¡needing¡¡to¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡implement¡¡an¡¡interface¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Delegates¡¡can¡¡be¡¡shared¡¡methods£»¡¡instance¡¡methods£»¡¡or¡¡module¡¡methods¡£¡¡The¡¡only¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡important¡¡aspect¡¡to¡¡the¡¡method¡¡is¡¡to¡¡make¡¡sure¡¡the¡¡method¡¡signature¡¡matches¡¡the¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡delegate¡¡declaration¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Lambda¡¡expressions¡¡are¡¡a¡¡specialized¡¡form¡¡of¡¡delegate¡¡method¡¡that¡¡enable¡¡you¡¡to¡¡write¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡deferred¡¡execution¡¡code¡£¡¡The¡¡advantage¡¡of¡¡deferred¡¡execution¡¡is¡¡that¡¡the¡¡code¡¡can¡¡contain¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡state¡¡whenever¡¡it¡¡is¡¡executed¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Some¡¡Things¡¡for¡¡You¡¡to¡¡Do¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡are¡¡some¡¡things¡¡for¡¡you¡¡to¡¡do¡¡to¡¡start¡¡applying¡¡your¡¡budding¡¡knowledge¡¡of¡¡soft
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ware¡¡engineering¡¡to¡¡improving¡¡the¡¡code¡¡base¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡£¡¡Collection¡¡classes¡¡before¡¡Visual¡¡Basic¡¡2005¡¡allowed¡¡you¡¡to¡¡mix¡¡types¡£¡¡With¡¡Visual¡¡Basic¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2005¡¡and¡¡later£»¡¡the¡¡¡¡generics¡¡classes¡¡do¡¡not¡¡allow¡¡you¡¡to¡¡mix¡¡types¡£¡¡Provide¡¡a¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡solution¡¡where¡¡you¡¡could¡¡mix¡¡types¡¡with¡¡Visual¡¡Basic¡¡2005¡¡and¡¡later¡¡collections¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2¡£¡¡Create¡¡a¡¡list¡¡that¡¡contains¡¡the¡¡numbers¡¡1¡¡to¡¡20¡£¡¡Remove¡¡the¡¡numbers£»¡¡15£»¡¡10£»¡¡and¡¡3¡¡to¡¡7¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡3¡£¡¡Create¡¡a¡¡list¡¡with¡¡an¡¡object¡¡that¡¡is¡¡defined¡¡as¡¡follows£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡MyType¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Value¡¡as¡¡String¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Class¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡4¡£¡¡Add¡¡ten¡¡elements¡¡to¡¡the¡¡list£»¡¡and¡¡then¡¡sort¡¡the¡¡list¡¡alphabetically¡¡from¡¡A¡¡to¡¡Z¡£¡¡Hint£º¡¡look¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡at¡¡the¡¡method¡¡Sort£¨£©¡¡and¡¡implement¡¡a¡¡custom¡¡Iparer£¨Of¡¡£©¡£¡¡As¡¡part¡¡of¡¡this¡¡exercise£»¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡you¡¡need¡¡to¡¡investigate¡¡and¡¡figure¡¡out¡¡how¡¡to¡¡use¡¡¡¡Iparer£¨Of¡¡£©¡£¡¡My¡¡suggestion¡¡is¡¡to¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡search¡¡the¡¡MSDN¡¡and¡¡Code¡¡Project¡¡web¡¡sites¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡271¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
C¡¡¡¡H¡¡¡¡A¡¡¡¡P¡¡¡¡T¡¡¡¡E¡¡¡¡R¡¡¡¡¡¡¡¡¡¡1¡¡¡¡0¡¡
¡ö¡¡¡ö¡¡¡ö¡¡
Learning¡¡About¡¡Persistence¡¡
Your¡¡programs¡¡will¡¡probably¡¡need¡¡to¡¡read¡¡and/or¡¡write¡¡data¡¡to¡¡some¡¡type¡¡of¡¡storage¡¡device¡£¡¡¡¡
That¡¡storage¡¡device¡¡might¡¡be¡¡a¡¡hard¡¡disk£»¡¡USB¡¡drive£»¡¡or¡¡even¡¡the¡¡network¡£¡¡The¡¡key¡¡concept¡¡is¡¡¡¡
that¡¡you¡¡are¡¡taking¡¡information¡¡from¡¡memory¡¡and¡¡transferring¡¡it¡¡to¡¡some¡¡other¡¡location¡£¡¡Later£»¡¡¡¡
you¡¡will¡¡retrieve¡¡that¡¡information¡¡and¡¡use¡¡it¡¡to¡¡execute¡¡some¡¡task¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡Taking¡¡data¡¡from¡¡memory¡¡and¡¡transferring¡¡it¡¡to¡¡another¡¡place¡¡is¡¡referred¡¡to¡¡as¡¡persistence¡£¡¡¡¡
Most¡¡examples¡¡of¡¡persistence¡¡involve¡¡creating¡¡an¡¡object£»¡¡and¡¡then¡¡saving¡¡that¡¡object¡¡via¡¡a¡¡file¡¡¡¡