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

µÚ114²¿·Ö

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

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

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





¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡426¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

404¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡5¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡L¡¡I¡¡N¡¡Q¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Looking¡¡at¡¡the¡¡From¡¡statement£»¡¡you¡¡could¡¡get¡¡the¡¡idea¡¡that¡¡it¡¡is¡¡a¡¡¡¡For¡¡Each¡¡statement¡¡without¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡types¡£¡¡Indeed£»¡¡the¡¡iteration¡¡happens¡¡only¡¡when¡¡you¡¡actually¡¡try¡¡to¡¡use¡¡the¡¡result¡¡of¡¡the¡¡LINQ¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡query¡£¡¡The¡¡From¡¡statement¡¡is¡¡saying¡¡to¡¡iterate¡¡the¡¡data¡¡source¡¡and¡¡assign¡¡each¡¡element¡¡£¨a¡¡Ticket£©¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡variable¡¡ticket¡£¡¡Note£»¡¡however£»¡¡that¡¡there¡¡is¡¡no¡¡explicit¡¡type¡¡information£»¡¡which¡¡is¡¡one¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡strengths¡¡of¡¡LINQ¡ªyou¡¡have¡¡the¡¡ability¡¡to¡¡easily¡¡slice¡¡and¡¡dice¡¡data¡¡to¡¡suit¡¡your¡¡needs¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡As¡¡you¡¡retrieve¡¡each¡¡item£»¡¡you¡¡want¡¡to¡¡verify¡¡whether¡¡the¡¡item¡¡matches¡¡your¡¡needs¡£¡¡If¡¡you¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡look¡¡at¡¡the¡¡code¡¡that¡¡isn¡¯t¡¡reusable£»¡¡you¡¯ll¡¡see¡¡that¡¡it¡¡checks¡¡this¡¡with¡¡an¡¡If¡¡statement¡£¡¡In¡¡LINQ£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡you¡¡use¡¡the¡¡Where¡¡statement£»¡¡which¡¡is¡¡similar¡¡to¡¡its¡¡SQL¡¡equivalent¡£¡¡With¡¡the¡¡Where¡¡statement£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡you¡¡test¡¡to¡¡see¡¡if¡¡the¡¡item¡¡matches¡¡your¡¡criteria¡£¡¡In¡¡our¡¡case£»¡¡we¡¡check¡¡each¡¡number¡¡in¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Ticket¡¡instance¡¡to¡¡see¡¡if¡¡it¡¡matches¡¡the¡¡number¡¡we¡¯re¡¡currently¡¡seeking¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡the¡¡Where¡¡returns¡¡True£»¡¡we¡¡have¡¡a¡¡match¡¡and¡¡we¡¡will¡¡want¡¡to¡¡do¡¡something¡£¡¡In¡¡the¡¡code¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡isn¡¯t¡¡reusable£»¡¡that¡¡means¡¡incrementing¡¡the¡¡runningTotal¡¡integer¡£¡¡In¡¡LINQ£»¡¡the¡¡aim¡¡is¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡filter¡¡the¡¡data¡¡source¡¡£¨_tickets¡¡in¡¡our¡¡case£©£»¡¡and¡¡thus¡¡the¡¡¡¡Select¡¡statement¡¡is¡¡used¡¡to¡¡create¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡new¡¡result¡¡set¡¡of¡¡drawn¡¡numbers¡£¡¡This¡¡result¡¡set¡¡contains¡¡all¡¡of¡¡the¡¡draws¡¡with¡¡the¡¡number¡¡we¡¯re¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡looking¡¡for¡¡£¨numberToSearch£©£»¡¡and¡¡if¡¡the¡¡draws¡¡are¡¡counted£»¡¡we¡¡can¡¡get¡¡the¡¡frequency¡¡of¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡number£»¡¡which¡¡we¡¡then¡¡return¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Let¡¯s¡¡look¡¡at¡¡the¡¡LINQ¡¡that¡¡could¡¡be¡¡used¡¡to¡¡find¡¡the¡¡frequency¡¡of¡¡two¡¡numbers¡¡being¡¡drawn¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Function¡¡FrequencyOfTwoNumbers£¨ByVal¡¡number1ToSearch¡¡As¡¡Integer£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ByVal¡¡number2ToSearch¡¡As¡¡Integer£©¡¡As¡¡Integer¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡query¡¡=¡¡From¡¡ticket2¡¡In¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨From¡¡ticket¡¡In¡¡_tickets¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Where¡¡ticket¡£Numbers£¨0£©¡¡=¡¡number1ToSearch¡¡¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨1£©¡¡=¡¡number1ToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨2£©¡¡=¡¡number1ToSearch¡¡¡¡¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨3£©¡¡=¡¡number1ToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨4£©¡¡=¡¡number1ToSearch¡¡¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨5£©¡¡=¡¡number1ToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Select¡¡ticket£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Where¡¡ticket2¡£Numbers£¨0£©¡¡=¡¡number2ToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket2¡£Numbers£¨1£©¡¡=¡¡number2ToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket2¡£Numbers£¨2£©¡¡=¡¡number2ToSearch¡¡¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket2¡£Numbers£¨3£©¡¡=¡¡number2ToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket2¡£Numbers£¨4£©¡¡=¡¡number2ToSearch¡¡¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket2¡£Numbers£¨5£©¡¡=¡¡number2ToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Select¡¡ticket2¡£Numbers¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡query¡£Count£¨£©¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡LINQ¡¡statement¡¡is¡¡a¡¡concatenation¡¡of¡¡two¡¡LINQ¡¡queries£»¡¡where¡¡one¡¡LINQ¡¡query¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡bolded¡£¡¡When¡¡the¡¡query¡¡is¡¡executed£»¡¡the¡¡embedded¡¡query¡¡is¡¡executed¡¡and¡¡generates¡¡a¡¡result¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡set¡£¡¡The¡¡result¡¡set¡¡is¡¡a¡¡data¡¡source¡¡on¡¡which¡¡the¡¡outer¡¡and¡¡second¡¡query¡¡operates£»¡¡which¡¡then¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡generates¡¡another¡¡result¡¡set¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡You¡¡do¡¡not¡¡need¡¡to¡¡embed¡¡LINQ¡¡queries¡¡as¡¡in¡¡the¡¡preceding¡¡code¡£¡¡You¡¡could¡¡write¡¡functions¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡embed¡¡the¡¡result¡¡of¡¡a¡¡LINQ¡¡query¡¡as¡¡the¡¡data¡¡source¡¡of¡¡another¡¡LINQ¡¡query¡£¡¡The¡¡power¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡LINQ¡¡is¡¡that¡¡you¡¡can£»¡¡in¡¡theory£»¡¡arbitrarily¡¡embed¡¡many¡¡queries¡¡within¡¡other¡¡queries£»¡¡since¡¡you¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡are¡¡creating¡¡a¡¡filtering¡¡mechanism¡¡where¡¡one¡¡result¡¡set¡¡is¡¡the¡¡data¡¡source¡¡of¡¡another¡¡query¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡427¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡5¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡L¡¡I¡¡N¡¡Q¡¡405¡¡



¡öNote¡¡¡¡LINQ¡¯s¡¡strength¡¡is¡¡in¡¡its¡¡ability¡¡to¡¡slice¡¡and¡¡dice¡¡data¡¡to¡¡find¡¡the¡¡information¡¡that¡¡you¡¡want¡¡£¨which¡¡is¡¡¡¡

easy¡¡because¡¡it¡¡is¡¡data¡¡source¨Cagnostic£©¡£¡¡LINQ¡¡requires¡¡more¡¡resources¡¡than¡¡similar¡¡Visual¡¡Basic¡¡code¡¡in¡¡¡¡

longhand¡¡format¡£¡¡But¡¡the¡¡benefit¡¡you¡¡get¡¡with¡¡LINQ¡¡is¡¡reusable¡¡code¡¡that¡¡you¡¡can¡¡maintain¡£¡¡



¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡preceding¡¡section£»¡¡we¡¡used¡¡LINQ¡¡to¡¡solve¡¡the¡¡frequency¡¡problem¡¡in¡¡a¡¡manner¡¡that¡¡¡¡

promoted¡¡reusability¡£¡¡For¡¡example£»¡¡if¡¡you¡¡wanted¡¡to¡¡find¡¡out¡¡more¡¡statistics¡¡of¡¡the¡¡lottery¡¡draws£»¡¡all¡¡¡¡

you¡¡would¡¡need¡¡to¡¡do¡¡is¡¡write¡¡more¡¡LINQ¡¡statements¡¡that¡¡sliced¡¡and¡¡diced¡¡the¡¡existing¡¡list¡¡¡¡

of¡¡lottery¡¡draws¡£¡¡It¡¡would¡¡require¡¡adding¡¡only¡¡the¡¡method¡¡calls¡¡to¡¡the¡¡IExtendedProcessor¡£¡¡

Destroy£¨£©¡¡method¡£¡¡However£»¡¡let¡¯s¡¡consider¡¡the¡¡problem¡¡solved¡¡and¡¡think¡¡about¡¡what¡¡else¡¡can¡¡¡¡

be¡¡done¡¡with¡¡LINQ¡£¡¡¡¡



Learning¡¡More¡¡LINQ¡¡Tricks¡¡



LINQ¡¡is¡¡not¡¡the¡¡only¡¡way¡¡to¡¡filter¡¡data¡£¡¡Associated¡¡with¡¡LINQ¡¡are¡¡a¡¡number¡¡of¡¡extension¡¡methods¡¡¡¡

that¡¡can¡¡be¡¡applied¡¡to¡¡lists¡£¡¡For¡¡example£»¡¡to¡¡filter¡¡for¡¡the¡¡frequency¡¡of¡¡a¡¡particular¡¡number£»¡¡the¡¡¡¡

following¡¡code¡¡could¡¡also¡¡have¡¡been¡¡used¡£¡¡



¡¡¡¡¡¡¡¡Function¡¡FrequencyOfANumber£¨ByVal¡¡numberToSearch¡¡As¡¡Integer£©¡¡As¡¡Integer¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡query¡¡=¡¡_tickets¡£Where£¨¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Function£¨ticket£»¡¡index£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ticket¡£Numbers£¨0£©¡¡=¡¡numberToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨1£©¡¡=¡¡numberToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨2£©¡¡=¡¡numberToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨3£©¡¡=¡¡numberToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨4£©¡¡=¡¡numberToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨5£©¡¡=¡¡numberToSearch£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡query¡£Count£¨£©¡¡

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



¡¡¡¡¡¡¡¡¡¡The¡¡ideas¡¡of¡¡LINQ¡¡that¡¡include¡¡From£»¡¡Where£»¡¡and¡¡Select¡¡are¡¡not¡¡lost£»¡¡they¡¡just¡¡have¡¡not¡¡been¡¡¡¡

used¡£¡¡The¡¡From¡¡part¡¡is¡¡the¡¡_tickets¡¡variable¡¡itself¡£¡¡The¡¡Where¡¡part¡¡is¡¡the¡¡method¡¡Where£¨£©£»¡¡and¡¡the¡¡¡¡

Select¡¡part¡¡is¡¡a¡¡default¡¡selection¡¡of¡¡the¡¡currently¡¡selected¡¡node¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡To¡¡specify¡¡an¡¡action¡¡with¡¡Where£¨£©£»¡¡you¡¡use¡¡a¡¡lambda¡¡expression£»¡¡which¡¡has¡¡two¡¡parame

ters£º¡¡the¡¡object¡¡and¡¡the¡¡index¡¡of¡¡the¡¡object¡£¡¡The¡¡lambda¡¡expression¡¡expects¡¡that¡¡you¡¡return¡¡a¡¡¡¡

Boolean¡¡value¡¡indicating¡¡whether¡¡the¡¡ticket¡¡item¡¡should¡¡be¡¡added¡¡to¡¡a¡¡returned¡¡list¡£¡¡

¡¡¡¡¡¡¡¡¡¡LINQ¡¡is¡¡a¡¡syntax¡¡that¡¡wraps¡¡SQL¡­like¡¡text¡£¡¡LINQ¡¡is¡¡much¡¡easier¡¡to¡¡understand¡¡and¡¡program¡¡¡¡

than¡¡using¡¡the¡¡method¡­call¡¡syntax¡¡of¡¡the¡¡previous¡¡example¡£¡¡Using¡¡the¡¡methods¡¡gives¡¡you¡¡more¡¡¡¡

flexibility£»¡¡but¡¡they¡¡also¡¡are¡¡more¡¡plicated¡¡to¡¡write¡£¡¡

¡¡¡¡¡¡¡¡¡¡For¡¡example£»¡¡if¡¡you¡¡wanted¡¡to¡¡find¡¡the¡¡frequency¡¡of¡¡two¡¡numbers¡¡in¡¡a¡¡list£»¡¡you¡¡could¡¡use¡¡¡¡

this¡¡code£º¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡428¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

406¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡5¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡L¡¡I¡¡N¡¡Q¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Function¡¡FrequencyOfTwoNumbersList£¨ByVal¡¡number1ToSearch¡¡As¡¡Integer¡¡£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ByVal¡¡number2ToSearch¡¡As¡¡Integer£©¡¡As¡¡Integer¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡query¡¡=¡¡_tickets¡£Where£¨¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Function£¨ticket£»¡¡index£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ticket¡£Numbers£¨0£©¡¡=¡¡number1ToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨1£©¡¡=¡¡number1ToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨2£©¡¡=¡¡number1ToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨3£©¡¡=¡¡number1ToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨4£©¡¡=¡¡number1ToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨5£©¡¡=¡¡number1ToSearch£©¡£Where£¨¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Function£¨ticket£»¡¡index£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ticket¡£Numbers£¨0£©¡¡=¡¡number2ToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨1£©¡¡=¡¡number2ToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨2£©¡¡=¡¡number2ToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨3£©¡¡=¡¡number2ToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨4£©¡¡=¡¡number2ToSearch¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Or¡¡ticket¡£Numbers£¨5£©¡¡=¡¡number2ToSearch£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡query¡£Count£¨£©¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡code£»¡¡the¡¡bolded¡¡line¡¡demonstrates¡¡how¡¡the¡¡output¡¡of¡¡one¡¡method¡¡can¡¡serve¡¡as¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡input¡¡for¡¡another¡¡method¡£¡¡This¡¡chaining¡¡of¡¡methods¡¡works¡¡because¡¡the¡¡list¡¡method¡¡returns¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡other¡¡lists¡£¡¡Thus£»¡¡you¡¡could¡¡add¡¡multiple¡¡criteria¡¡by¡¡concatenating¡¡multiple¡¡Where£¨£©¡¡method¡¡calls¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡methods¡¡are¡¡used¡¡to¡¡filter¡¡or¡¡manipulate¡¡the¡¡set¡¡where¡¡the¡¡details¡¡of¡¡the¡¡method¡¡are¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡provided¡¡by¡¡a¡¡lambda¡¡expression¡£¡¡Table¡¡15¡­1¡¡briefly¡¡describes¡¡some¡¡of¡¡the¡¡useful¡¡methods¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡you¡¡can¡¡use¡¡to¡¡filter¡¡and¡¡manipulate¡¡a¡¡list¡£¡¡The¡¡best¡¡way¡¡to¡¡learn¡¡about¡¡all¡¡of¡¡the¡¡methods¡¡is¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡use¡¡Visual¡¡Basic¡¡Express£»¡¡declare¡¡a¡¡list£»¡¡and¡¡use¡¡IntelliSense¡¡to¡¡discover¡¡the¡¡different¡¡methods¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡available¡£¡¡Also£»¡¡see¡¡http£º//msdn2¡£microsoft¡£/en¡­us/vbasic/bb688088¡£aspx¡¡for¡¡many¡¡exam

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ples¡¡that¡¡demonstrate¡¡the¡¡various¡¡list¡­manipulation¡¡methods¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Table¡¡15¡­1¡£¡¡Some¡¡Methods¡¡for¡¡Filtering¡¡and¡¡Manipulating¡¡Lists¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Method¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Description¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Aggregate£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Returns¡¡a¡¡fact¡¡about¡¡the¡¡list¡£¡¡A¡¡fact¡¡could¡¡be¡¡how¡¡many¡¡even¡¡numbers¡¡there¡¡are¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡or¡¡the¡¡frequency¡¡of¡¡a¡¡particular¡¡number¡£¡¡All¡¡of¡¡the¡¡elements¡¡in¡¡the¡¡list¡¡are¡¡iterated¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡returned¡¡as¡¡a¡¡single¡¡fact£»¡¡not¡¡as¡¡a¡¡list¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡All£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Iterates¡¡all¡¡elements¡¡of¡¡the¡¡list¡¡and¡¡tests¡¡according¡¡to¡¡a¡¡lambda¡¡expression£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡where¡¡a¡¡True¡¡or¡¡False¡¡is¡¡returned¡£¡¡For¡¡example£»¡¡the¡¡test¡¡could¡¡be¡¡to¡¡find¡¡out¡¡if¡¡all¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡objects¡¡have¡¡a¡¡value¡¡greater¡¡than¡¡10¡£¡¡The¡¡test¡¡needs¡¡to¡¡return¡¡only¡¡a¡¡True¡¡or¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡False¡¡value¡¡for¡¡the¡¡individual¡¡object£»¡¡where¡¡the¡¡All£¨£©¡¡method¡¡will¡¡correlate¡¡the¡¡¡¡

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

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

Äã¿ÉÄÜϲ»¶µÄ