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

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

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


ate¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡results¡¡and¡¡return¡¡a¡¡True¡¡or¡¡¡¡False¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Any£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Like¡¡All£¨£©£»¡¡except¡¡that¡¡the¡¡question¡¡is¡¡changed¡¡to¡¡test¡¡if¡¡any¡¡of¡¡the¡¡objects¡¡meet¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡criteria£»¡¡such¡¡as¡¡having¡¡a¡¡value¡¡greater¡¡than¡¡10¡£¡¡If¡¡so£»¡¡then¡¡a¡¡True¡¡value¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡returned£»¡¡otherwise£»¡¡a¡¡False¡¡value¡¡is¡¡returned¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Average£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Calculates¡¡the¡¡average¡¡of¡¡a¡¡sequence¡¡of¡¡values¡£¡¡The¡¡average¡¡value¡¡returned¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡numeric¡¡Decimal¡¡value¡£¡¡This¡¡method¡¡is¡¡a¡¡bit¡¡odd£»¡¡because¡¡to¡¡calculate¡¡an¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡average£»¡¡you¡¡need¡¡numbers£»¡¡even¡¡though¡¡the¡¡lambda¡¡expression¡¡could¡¡calcu

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡late¡¡the¡¡average¡¡of¡¡objects¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡429¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



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



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



Cast£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Returns¡¡a¡¡list¡¡where¡¡each¡¡item¡¡is¡¡converted¡¡from¡¡the¡¡list¡¡type¡¡to¡¡another¡¡type¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡is¡¡a¡¡good¡¡method¡¡to¡¡use¡¡when¡¡you¡¡need¡¡to¡¡perform¡¡bulk¡¡conversions¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡instance¡¡types¡¡in¡¡a¡¡list¡£¡¡



Concat£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Concatenates¡¡two¡¡lists¡£¡¡¡¡



Contains£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Verifies¡¡whether¡¡an¡¡item¡¡is¡¡present¡¡in¡¡the¡¡list¡£¡¡The¡¡method¡¡uses¡¡a¡¡lambda¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡expression¡¡to¡¡determine¡¡whether¡¡the¡¡specified¡¡item¡¡is¡¡in¡¡the¡¡list£»¡¡and¡¡returns¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡True¡¡or¡¡¡¡False¡¡accordingly¡£¡¡



ConvertAll£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Returns¡¡a¡¡list¡¡where¡¡each¡¡item¡¡is¡¡converted¡¡from¡¡the¡¡list¡¡type¡¡to¡¡another¡¡type¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡is¡¡a¡¡good¡¡method¡¡to¡¡use¡¡when¡¡you¡¡need¡¡to¡¡perform¡¡bulk¡¡conversions¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡instance¡¡types¡¡in¡¡a¡¡list¡£¡¡



Distinct£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Removes¡¡all¡¡duplicates¡¡from¡¡a¡¡list¡£¡¡By¡¡default£»¡¡the¡¡implementation¡¡of¡¡Distinct£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡checks¡¡for¡¡equality¡¡by¡¡calling¡¡GetHashCode£¨£©¡¡first£»¡¡and¡¡then¡¡calling¡¡¡¡Equals£¨£©¡¡if¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡necessary¡£¡¡A¡¡variation¡¡of¡¡the¡¡Distinct£¨£©¡¡method¡¡is¡¡to¡¡supply¡¡an¡¡¡¡IEqualityparer¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡interface¡¡instance¡¡that¡¡can¡¡be¡¡used¡¡to¡¡determine¡¡whether¡¡two¡¡types¡¡are¡¡equal¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡However£»¡¡a¡¡better¡¡approach¡¡would¡¡be¡¡to¡¡implement¡¡GetHashCode£¨£©¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Equals£¨£©¡£¡¡



Except£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Takes¡¡the¡¡current¡¡list¡¡and¡¡a¡¡passed¡­in¡¡list¡¡and¡¡performs¡¡a¡¡difference¡¡between¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡two¡¡sets£»¡¡which¡¡is¡¡returned¡¡to¡¡the¡¡caller¡¡as¡¡a¡¡new¡¡dataset¡£¡¡The¡¡equality¡¡tests¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡are¡¡identical¡¡to¡¡Distinct£¨£©¡£¡¡



Find£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Finds¡¡an¡¡element¡¡of¡¡a¡¡particular¡¡list¡£¡¡Note¡¡that¡¡the¡¡lambda¡¡expression¡¡you¡¡use¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡when¡¡it¡¡has¡¡found¡¡an¡¡element¡¡will¡¡cause¡¡the¡¡¡¡Find£¨£©¡¡method¡¡to¡¡stop¡¡processing¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡list¡¡and¡¡return¡¡what¡¡you¡¡marked¡¡as¡¡found¡£¡¡¡¡



FindAll£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Like¡¡Find£¨£©£»¡¡except¡¡you¡¡can¡¡find¡¡multiple¡¡elements¡¡in¡¡a¡¡list¡£¡¡This¡¡is¡¡like¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Where£¨£©¡¡method¡£¡¡



FindLast£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Like¡¡Find£¨£©£»¡¡except¡¡the¡¡search¡¡starts¡¡at¡¡the¡¡end¡¡of¡¡the¡¡list¡£¡¡



ForEach£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡An¡¡iterator¡¡that¡¡uses¡¡a¡¡lambda¡¡expression¡¡to¡¡process¡¡each¡¡element¡£¡¡The¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ForEach£¨£©¡¡method¡¡is¡¡a¡¡simplification¡¡of¡¡the¡¡code¡¡illustrated¡¡in¡¡Chapter¡¡9¡£¡¡



GroupBy£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Takes¡¡a¡¡list¡¡and¡¡splits¡¡it¡¡into¡¡specific¡¡groupings¡¡as¡¡per¡¡the¡¡provided¡¡lambda¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡expression¡£¡¡For¡¡example£»¡¡you¡¡could¡¡use¡¡it¡¡to¡¡split¡¡the¡¡earnings¡¡of¡¡individuals¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡into¡¡brackets¡£¡¡



Intersect£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Takes¡¡the¡¡current¡¡list¡¡and¡¡a¡¡provided¡¡list¡¡and¡¡determines¡¡the¡¡elements¡¡that¡¡are¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mon¡¡to¡¡both¡¡lists¡£¡¡Uses¡¡the¡¡same¡¡equality¡¡tests¡¡as¡¡Distinct£¨£©¡£¡¡



Max£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Finds¡¡the¡¡maximum¡¡value¡¡of¡¡a¡¡list¡£¡¡



Min£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Finds¡¡the¡¡minimum¡¡value¡¡of¡¡a¡¡list¡£¡¡



Reverse£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Reverses¡¡the¡¡order¡¡of¡¡the¡¡list¡£¡¡



Select£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Selects¡¡from¡¡the¡¡iteration¡¡being¡¡executed¡£¡¡



SelectMany£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Selects¡¡many¡¡items¡¡from¡¡a¡¡list¡¡where¡¡the¡¡selected¡¡items¡¡form¡¡another¡¡list¡£¡¡



Sum£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Calculates¡¡the¡¡sum¡¡of¡¡a¡¡list¡£¡¡



Union£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Takes¡¡the¡¡list¡¡and¡¡the¡¡passed¡­in¡¡list¡¡and¡¡calculates¡¡the¡¡union¡¡of¡¡the¡¡two¡¡lists¡£¡¡Uses¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡equality¡¡test¡¡as¡¡defined¡¡in¡¡the¡¡Distinct£¨£©¡¡method¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡430¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡With¡¡Visual¡¡Basic¡¡2008£»¡¡lists¡¡and¡¡the¡¡manipulation¡¡of¡¡lists¡¡have¡¡dramatically¡¡changed¡¡for¡¡the¡¡better¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡general¡¡structure¡¡is¡¡to¡¡define¡¡methods¡¡that¡¡allow¡¡a¡¡developer¡¡to¡¡specify¡¡a¡¡lambda¡¡expression¡¡that¡¡is¡¡then¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡chained¡¡together¡¡with¡¡other¡¡methods¡£¡¡Take¡¡some¡¡time¡¡to¡¡learn¡¡about¡¡all¡¡of¡¡the¡¡possibilities¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡As¡¡an¡¡example¡¡of¡¡the¡¡power¡¡of¡¡the¡¡various¡¡methods£»¡¡consider¡¡the¡¡following¡¡code£»¡¡which¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡pacts¡¡the¡¡frequency¡¡code¡¡into¡¡a¡¡couple¡¡of¡¡lines¡¡of¡¡source¡¡code¡£¡¡



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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡_tickets¡£SelectMany£¨¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Function£¨ticket£©¡¡ticket¡£Numbers£©¡£Where£¨¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Function£¨num£©¡¡num¡¡=¡¡numberToSearch£©¡£Count£¨£©¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Here£»¡¡each¡¡ticket¡¡is¡¡iterated¡¡by¡¡calling¡¡the¡¡SelectMany£¨£©¡¡method¡£¡¡This¡¡returns¡¡an¡¡array¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡numbers£»¡¡which¡¡represents¡¡the¡¡drawn¡¡numbers¡£¡¡The¡¡purpose¡¡of¡¡SelectMany£¨£©¡¡is¡¡to¡¡bine¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡individual¡¡arrays¡¡of¡¡numbers¡¡into¡¡a¡¡large¡¡array¡¡of¡¡numbers¡£¡¡The¡¡code¡¡then¡¡calls¡¡Where£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡filter¡¡out¡¡only¡¡those¡¡numbers¡¡that¡¡equal¡¡the¡¡number¡¡to¡¡search¡¡for£»¡¡and¡¡finally¡¡the¡¡Count£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡method¡¡is¡¡called¡¡to¡¡return¡¡the¡¡number¡¡of¡¡found¡¡values¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡sections¡¡present¡¡examples¡¡of¡¡using¡¡the¡¡extension¡¡methods¡¡with¡¡LINQ¡£¡¡They¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡are¡¡in¡¡the¡¡¡¡LINQExamples¡¡project£»¡¡which¡¡is¡¡a¡¡console¡¡application¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡In¡¡all¡¡of¡¡the¡¡examples£»¡¡I¡¡have¡¡taken¡¡shortcuts¡¡for¡¡simplicity¡£¡¡So¡¡you¡¡will¡¡see¡¡some¡¡coding¡¡practices¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡are¡¡not¡¡remended£»¡¡such¡¡as¡¡creating¡¡public¡¡data¡¡members¡¡and¡¡not¡¡using¡¡properties¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Selecting¡¡and¡¡Altering¡¡Data¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡running¡¡a¡¡LINQ¡¡query£»¡¡the¡¡data¡¡that¡¡you¡¡filter¡¡and¡¡manipulate¡¡does¡¡not¡¡need¡¡to¡¡stay¡¡in¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡its¡¡original¡¡form¡£¡¡Let¡¯s¡¡say¡¡that¡¡you¡¡have¡¡a¡¡list¡¡of¡¡customers£»¡¡and¡¡you¡¡have¡¡identified¡¡a¡¡set¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡customers¡¡who¡¡deserve¡¡more¡¡loyalty¡¡points¡£¡¡You¡¡want¡¡to¡¡select¡¡those¡¡customers£»¡¡increment¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡their¡¡points£»¡¡and¡¡then¡¡return¡¡the¡¡list¡¡of¡¡altered¡¡customers¡£¡¡To¡¡do¡¡that£»¡¡you¡¡can¡¡mix¡¡LINQ¡¡with¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡extension¡¡methods¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Consider¡¡the¡¡following¡¡simplified¡¡customer¡¡declaration¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡Customer¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Identifier¡¡As¡¡String¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Points¡¡As¡¡Integer¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Overrides¡¡Function¡¡ToString£¨£©¡¡As¡¡String¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡¡¨Identifier¡¡£¨¡¨¡¡&¡¡Identifier¡¡&¡¡¡¨£©¡¡Points¡¡£¨¡¨¡¡&¡¡Points¡¡&¡¡¡¨£©¡¨¡¡

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

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡A¡¡list¡¡will¡¡be¡¡created¡¡with¡¡two¡¡customers£»¡¡where¡¡one¡¡customer¡¡has¡¡no¡¡points¡¡and¡¡the¡¡other¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡one¡¡does¡£¡¡Here¡¡is¡¡the¡¡source¡¡code¡¡to¡¡create¡¡that¡¡list£º¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡431¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡Private¡¡Function¡¡CreateList£¨£©¡¡As¡¡Customer£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡New¡¡Customer£¨£©¡¡£û¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡New¡¡Customer£¨£©¡¡With¡¡£û¡£Identifier¡¡=¡¡¡¨Person¡¡1¡¨£»¡¡¡£Points¡¡=¡¡0£ý£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡New¡¡Customer£¨£©¡¡With¡¡£û¡£Identifier¡¡=¡¡¡¨Person¡¡2¡¨£»¡¡¡£Points¡¡=¡¡10£ý£ý¡¡

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



¡¡¡¡¡¡¡¡¡¡The¡¡customers¡¡that¡¡have¡¡enough¡¡points¡¡are¡¡selected¡¡and¡¡rewarded¡¡with¡¡extra¡¡points¡£¡¡To¡¡do¡¡¡¡

that£»¡¡use¡¡the¡¡following¡¡LINQ¡¡statement¡£¡¡



¡¡¡¡¡¡¡¡Function¡¡Increment£¨ByVal¡¡pCustomer¡¡As¡¡Customer£»¡¡ByVal¡¡index¡¡As¡¡Integer£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡As¡¡Customer¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡pCustomer¡£Points¡¡£«=¡¡5¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡pCustomer¡¡

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



¡¡¡¡¡¡¡¡Sub¡¡CountCustomers£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡points¡¡=¡¡£¨From¡¡customer¡¡In¡¡CreateList£¨£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Where¡¡customer¡£Points¡¡¡·¡¡5¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Select¡¡customer£©¡£Select£¨AddressOf¡¡Increment£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Count¡¡is¡¡£¨¡¨¡¡&¡¡points¡£Count£¨£©¡¡&¡¡¡¨£©¡¨£©¡¡

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



¡¡¡¡¡¡¡¡¡¡The¡¡LINQ¡¡query¡¡is¡¡bined¡¡with¡¡a¡¡modification¡¡operation¡£¡¡The¡¡LINQ¡¡statement¡¡that¡¡uses¡¡¡¡

From£»¡¡Where£»¡¡and¡¡Select¡¡is¡¡not¡¡new¡£¡¡New¡¡are¡¡the¡¡parentheses¡¡enclosing¡¡the¡¡LINQ¡¡statement¡£¡¡By¡¡¡¡

using¡¡a¡¡set¡¡of¡¡parentheses£»¡¡you¡¡are¡¡identifying¡¡the¡¡LINQ¡¡statement¡¡as¡¡an¡¡object¡¡that¡¡references¡¡¡¡

a¡¡result¡¡set¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡example£»¡¡the¡¡method¡¡called¡¡on¡¡the¡¡LINQ¡¡statement¡¡is¡¡Select£¨£©¡£¡¡Using¡¡the¡¡Select£¨£©¡¡¡¡

method£»¡¡each¡¡item¡¡in¡¡the¡¡result¡¡set¡¡is¡¡iterated¡¡and¡¡passed¡¡as¡¡a¡¡parameter¡¡£¨pCustomer£©¡¡to¡¡the¡¡¡¡

lambda¡¡expression¡¡£¨Increment£¨£©£©¡£¡¡Passed¡¡with¡¡the¡¡item¡¡is¡¡the¡¡index¡¡of¡¡the¡¡item¡¡in¡¡the¡¡list¡£¡¡The¡¡¡¡

role¡¡of¡¡the¡¡lambda¡¡expression¡¡is¡¡to¡¡do¡¡something¡¡with¡¡the¡¡item¡¡and¡¡return¡¡what¡¡should¡¡be¡¡used¡¡as¡¡¡¡

a¡¡basis¡¡for¡¡another¡¡list¡£¡¡In¡¡the¡¡example£»¡¡an¡¡instance¡¡of¡¡the¡¡type¡¡Customer¡¡is¡¡passed¡¡in¡¡to¡¡Increment£¨£©£»¡¡¡¡

and¡¡an¡¡instance¡¡of¡¡type¡¡Customer¡¡is¡¡passed¡¡out¡£¡¡But¡¡before¡¡the¡¡instance¡¡is¡¡returned£»¡¡it¡¡is¡¡manip

ulated¡¡to¡¡get¡¡an¡¡additional¡¡five¡¡bonus¡¡points¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡What¡¡might¡¡concern¡¡you¡¡is¡¡that¡¡there¡¡is¡¡no¡¡test¡¡to¡¡check¡¡if¡¡the¡¡customer¡¡actually¡¡warrants¡¡¡¡

earning¡¡five¡¡bonus¡¡points¡£¡¡That¡¡would¡¡be¡¡a¡¡concern¡¡if¡¡you¡¡were¡¡not¡¡using¡¡the¡¡LINQ¡¡expression¡£¡¡¡¡

The¡¡LINQ¡¡expression¡¡is¡¡responsible¡¡for¡¡filtering¡¡out¡¡only¡¡those¡¡customers¡¡who¡¡should¡¡get¡¡the¡¡¡¡

additional¡¡bonus¡¡points¡£¡¡Thus£»¡¡when¡¡the¡¡method¡¡Select£¨£©¡¡is¡¡called£»¡¡you¡¡are¡¡100£¥¡¡sure¡¡that¡¡¡¡

only¡¡the¡¡customers¡¡who¡¡should¡¡get¡¡bonus¡¡points¡¡actually¡¡get¡¡bonus¡¡points¡£¡¡Think¡¡of¡¡this¡¡as¡¡¡¡

building¡¡a¡¡pipeline¡¡of¡¡manipulations¡£¡¡



Selecting¡¡with¡¡Anonymous¡¡Types¡¡



The¡¡Select£¨£©¡¡method¡¡and¡¡statement¡¡are¡¡used¡¡to¡¡generate¡¡a¡¡result¡¡set¡¡after¡¡finding¡¡a¡¡particular¡¡¡¡

element¡£¡¡As¡¡demonstrated¡¡in¡¡the¡¡previous¡¡section£»¡¡a¡¡Select¡¡statement¡¡is¡¡used¡¡to¡¡generate¡¡a¡¡new¡¡¡¡

result¡¡set¡£¡¡For¡¡example£»¡¡what¡¡if¡¡you¡¡want¡¡to¡¡find¡¡all¡¡of¡¡the¡¡customers¡¡who¡¡fulfill¡¡a¡¡certain¡¡crite

rion£»¡¡but¡¡do¡¡not¡¡want¡¡to¡¡copy¡¡all¡¡of¡¡the¡¡associated¡¡data£¿¡¡You¡¡might¡¡want¡¡only¡¡the¡¡customer¡¡¡¡

identifier¡¡and¡¡accumulated¡¡points¡£¡¡To¡¡do¡¡that£»¡¡you¡¡could¡¡modify¡¡the¡¡Select£¨£©¡¡part¡¡of¡¡the¡¡LINQ¡¡¡¡

statement¡¡to¡¡return¡¡a¡¡new¡¡type¡¡that¡¡you¡¡declare¡¡dynamically¡£¡¡The¡¡following¡¡is¡¡the¡¡previous¡¡¡¡

example¡¡rewritten¡¡to¡¡use¡¡an¡¡anonymous¡¡type¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡432¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Function¡¡Increment2£¨ByVal¡¡pCustomer¡¡As¡¡Customer£»¡¡ByVal¡¡index¡¡As¡¡Integer£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡pCustomer¡£Points¡¡£«=¡¡5¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡New¡¡With¡¡£û¡£identifier¡¡=¡¡pCustomer¡£Identifier£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£points¡¡=¡¡pCustomer¡£Points£ý¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Sub¡¡CountCustomers2£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡points¡¡=¡¡£¨From¡¡customer¡¡In¡¡CreateList£¨£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Where¡¡customer¡£Points¡¡¡·¡¡5¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Select¡¡customer£©¡£Select£¨AddressOf¡¡Increment2£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Count¡¡is¡¡£¨¡¨¡¡&¡¡points¡£Count£¨£©¡¡&¡¡¡¨£©¡¨£©¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡example£»¡¡the¡¡Return¡¡statement¡¡in¡¡the¡¡¡¡Increment2£¨£©¡¡method¡¡uses¡¡the¡¡keyword¡¡New¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡without¡¡a¡¡type¡¡identifier£»¡¡but¡¡with¡¡the¡¡syntax¡¡of¡¡an¡¡object¡¡initializer¡£¡¡This¡¡is¡¡defining¡¡an¡¡anony

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mous¡¡type¡£¡¡An¡¡anonymous¡¡type¡¡is¡¡an¡¡object¡¡instance¡¡that¡¡has¡¡no¡¡explicitly¡¡named¡¡type¡£¡¡The¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡anonymous¡¡type¡¡has¡¡properties£»¡¡but¡¡it¡¡does¡¡not¡¡have¡¡methods¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Anonymous¡¡types¡¡are¡¡useful¡¡only¡¡in¡¡the¡¡context¡¡of¡¡the¡¡method¡¡in¡¡which¡¡they¡¡are¡¡declared¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡variable¡¡points¡¡in¡¡the¡¡CountCustomers2£¨£©¡¡method¡¡is¡¡a¡¡collection¡¡of¡¡anonymous¡­type¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡objects¡¡that¡¡could¡¡be¡¡iterated¡¡as¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡Each¡¡customer¡¡in¡¡points¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Customer¡¡£¨¡¨¡¡&¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡customer¡£identifier¡¡&¡¡¡¨£©£¨¡¨¡¡&¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡customer¡£points¡¡&¡¡¡¨£©¡¨£©¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡piler¡¡that¡¡translates¡¡the¡¡LINQ¡¡expression¡¡knows¡¡that¡¡the¡¡final¡¡result¡¡set¡¡contains¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡anonymous¡­type¡¡objects¡¡with¡¡the¡¡properties¡¡identifier¡¡and¡¡points¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Processing¡¡Multiple¡¡Streams¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡all¡¡of¡¡the¡¡LINQ¡¡examples¡¡so¡¡far£»¡¡a¡¡single¡¡result¡¡set¡¡has¡¡been¡¡manipulated£»¡¡processed£»¡¡and¡¡filtered¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡You¡¡can¡¡process¡¡multiple¡¡inputs¡¡at¡¡the¡¡same¡¡time£»¡¡but¡¡you¡¡will¡¡get¡¡a¡¡binatorial¡¡type¡¡answer¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡example£»¡¡suppose¡¡you¡¡had¡¡this¡¡LINQ£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡set1¡¡As¡¡Integer£¨£©¡¡=¡¡New¡¡Integer£¨£©¡¡£û1£»¡¡2£»¡¡3£»¡¡4£»¡¡5£ý¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡set2¡¡As¡¡Integer£¨£©¡¡=¡¡New¡¡Integer£¨£©¡¡£û1£»¡¡2£»¡¡3£»¡¡4£»¡¡5£ý¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡set3¡¡As¡¡Integer£¨£©¡¡=¡¡New¡¡Integer£¨£©¡¡£û1£»¡¡2£»¡¡3£»¡¡4£»¡¡5£ý¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡triples¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡From¡¡a¡¡In¡¡set1¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡From¡¡b¡¡In¡¡set2¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡From¡¡c¡¡In¡¡set3¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Select¡¡New¡¡With¡¡£ûa£»¡¡b£»¡¡c£ý¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡pseudo¡­code£»¡¡the¡¡following¡¡would¡¡be¡¡identical¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡433¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



Dim¡¡items¡¡As¡¡List¡¡£¨Of¡¡Object£©¡¡=¡¡New¡¡List£¨Of¡¡Object£©£¨£©¡¡

For¡¡Each¡¡a¡¡In¡¡set1¡¡

¡¡¡¡¡¡¡¡For¡¡Each¡¡b¡¡In¡¡set2¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡Each¡¡c¡¡In¡¡set3¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡items¡£Add£¨New¡¡With¡¡£û¡¡a£»¡¡b£»¡¡c¡¡£ý£©¡¡

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

¡¡¡¡¡¡¡¡Next¡¡

Next¡¡



¡¡¡¡¡¡¡¡¡¡When¡¡you¡¡specify¡¡multiple¡¡¡¡From¡¡clauses£»¡¡you¡¡are¡¡creating¡¡a¡¡looping¡¡mechanism¡¡where¡¡¡¡

each¡¡item¡¡is¡¡iterated¡¡against¡¡the¡¡other¡¡elements¡£¡¡This¡¡sounds¡¡useful£»¡¡but¡¡it¡¡can¡¡have¡¡a¡¡disastrous¡¡¡¡

side¡¡effect£º¡¡a¡¡seemingly¡¡innocent¡¡query¡¡can¡¡take¡¡much¡¡longer¡¡than¡¡it¡¡should¡£¡¡After¡¡having¡¡¡¡

written¡¡the¡¡individual¡¡¡¡From¡¡statements£»¡¡you¡¡can¡¡use¡¡Where¡¡and¡¡Select¡¡as¡¡usual¡£¡¡



Sorting¡¡the¡¡Results¡¡



After¡¡having¡¡selected¡¡elements£»¡¡you¡¡will¡¡probably¡¡want¡¡to¡¡sort¡¡the¡¡result¡¡set¡£¡¡Using¡¡LINQ£»¡¡you¡¡¡¡

can¡¡sort¡¡by¡¡anything¡¡you¡¡deem¡¡important¡£¡¡The¡¡obvious¡¡approach¡¡is¡¡to¡¡sort¡¡according¡¡to¡¡a¡¡number¡¡¡¡

or¡¡letter£»¡¡but¡¡you¡¡could¡¡also¡¡sort¡¡according¡¡to¡¡length¡¡of¡¡the¡¡word¡£¡¡

¡¡¡¡¡¡¡¡¡¡Regardless¡¡of¡¡how¡¡you¡¡sort£»¡¡in¡¡LINQ¡¡you¡¡use¡¡the¡¡keywords¡¡Order¡¡By¡¡or¡¡the¡¡method¡¡OrderBy£¨£©¡£¡¡¡¡

The¡¡following¡¡is¡¡a¡¡LINQ¡¡example¡¡that¡¡does¡¡an¡¡alphabetic¡¡sort¡£¡¡



Dim¡¡words¡¡As¡¡String£¨£©¡¡=¡¡£û¡¡¡¨cherry¡¨£»¡¡¡¨apple¡¨£»¡¡¡¨blueberry¡¨¡¡£ý¡¡



Dim¡¡sortedWords¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡From¡¡w¡¡In¡¡words¡¡_¡¡

¡¡¡¡¡¡¡¡Order¡¡By¡¡w¡¡_¡¡

¡¡¡¡¡¡¡¡Select¡¡w¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡phrase¡¡Order¡¡By¡¡is¡¡inserted¡¡before¡¡Select¡£¡¡In¡¡this¡¡case£»¡¡it¡¡will¡¡sort¡¡the¡¡words¡¡in¡¡ascending¡¡¡¡

alphabetical¡¡order¡£¡¡The¡¡way¡¡that¡¡the¡¡Order¡¡By¡¡works¡¡is¡¡that¡¡the¡¡¡¡value¡¡of¡¡the¡¡variable¡¡is¡¡pared£»¡¡¡¡

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