LINQѧϰ±Ê¼Ç:½á¹¹»¯ÇÒÀàÐÍ°²È«µÄ²éѯ
ͨ¹ýеĹؼü×Övar, ÎÒÃÇ»¹¿ÉÒÔʹ²éѯÓï¾ä¸ü¼ò¶ÌһЩ: var filteredNames = names.Where(n => n.Length > = 4); ´ó¶àÊýµÄ²éѯ²Ù×÷·½·¨¶¼½ÓÊÜÒ»¸öLambda±í´ïʽ×÷ΪÊäÈë²ÎÊý, Lamdba±í´ïʽÓÃÓÚÖ¸µ¼ºÍËÜÔì²éѯ, n => n.Length >= 4¾ÍÊÇÎÒÃÇÉÏÊö·½·¨ÖÐÓõ½µÄLamdba±í´ïʽ. ÊäÈë²ÎÊý½«»áÏìÓ¦µ½Ã¿Ò»¸öÔªËØ, ÔÚÕâ¸öÀý×ÓÖÐ, ÊäÈë²ÎÊýn´ú±íÔÚÊý×éÖеÄÿһ¸öÔªËØ, ²¢ÇÒËüµÄÀàÐÍÊÇstring. Where²Ù×÷·½·¨ÒªÇóLambda±í´ïʽ·µ»ØÒ»¸öboolÖµ, Èç¹û·µ»Øtrue, ±íʾ¸ÃÔªËؽ«±»°üº¬½øÊä³öÐòÁÐÖÐ. ÁíÍâÔÚC#µ±Öл¹¶¨ÒåÁËÒ»ÖÖÌØÊâµÄÓï·¨ÓÃÓÚ±àд²éѯ, ³ÉΪ¸´ºÏ²éѯÓï·¨, Ò»¸öÀý×ÓÈçÏÂ: IEnumerable<string> theName = from n in names where n.Contains(“T”) select n; LambdaÓï·¨ºÍ¸´ºÏ²éѯÓï·¨ÊÇ»¥²¹µÄ. ´ýÐø! |
ÁèÖڿƼ¼×¨ÒµÌṩ·þÎñÆ÷×âÓᢷþÎñÆ÷Íйܡ¢ÆóÒµÓʾ֡¢ÐéÄâÖ÷»úµÈ·þÎñ£¬¹«Ë¾ÍøÕ¾£ºhttp://www.lingzhong.cn ΪÁ˸ø¹ã´ó¿Í»§Á˽â¸ü¶àµÄ¼¼ÊõÐÅÏ¢£¬±¾¼¼ÊõÎÄÕÂÊÕ¼¯À´Ô´ÓÚÍøÂç,ÁèÖڿƼ¼×ðÖØÎÄÕÂ×÷ÕߵİæȨ£¬Èç¹ûÓÐÉæ¼°ÄãµÄ°æȨÓбØҪɾ³ýÄãµÄÎÄÕ£¬ÇëºÍÎÒÃÇÁªÏµ¡£ÒÔÉÏÐÅÏ¢ÓëÎÄÕÂÕýÎÄÊDz»¿É·Ö¸îµÄÒ»²¿·Ö,Èç¹ûÄúҪתÔر¾ÎÄÕÂ,Çë±£ÁôÒÔÉÏÐÅÏ¢£¬Ð»Ð»! |