﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>博客园-咖喱克斯</title><link>http://www.cnblogs.com/galex/</link><description>关注，利用，分享</description><language>zh-cn</language><lastBuildDate>Sat, 30 Aug 2008 11:13:42 GMT</lastBuildDate><pubDate>Sat, 30 Aug 2008 11:13:42 GMT</pubDate><ttl>60</ttl><item><title>好久没有更新了</title><link>http://www.cnblogs.com/galex/archive/2008/05/08/1188149.html</link><dc:creator>关小羽</dc:creator><author>关小羽</author><pubDate>Thu, 08 May 2008 03:37:00 GMT</pubDate><guid>http://www.cnblogs.com/galex/archive/2008/05/08/1188149.html</guid><wfw:comment>http://www.cnblogs.com/galex/comments/1188149.html</wfw:comment><comments>http://www.cnblogs.com/galex/archive/2008/05/08/1188149.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/galex/comments/commentRss/1188149.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/galex/services/trackbacks/1188149.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;真是太对不起自己了。<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;由于工作和生活都忙，还好不是一团乱。<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;等周会开完，公司的考核结束，我继续写LINQ。<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
<img src ="http://www.cnblogs.com/galex/aggbug/1188149.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41966/" target="_blank">[新闻]Google推出Android Market挑战App Store</a>]]></description></item><item><title>LINQ(3): HelloWorld的最后一个例子</title><link>http://www.cnblogs.com/galex/archive/2008/04/14/1153164.html</link><dc:creator>关小羽</dc:creator><author>关小羽</author><pubDate>Mon, 14 Apr 2008 10:18:00 GMT</pubDate><guid>http://www.cnblogs.com/galex/archive/2008/04/14/1153164.html</guid><wfw:comment>http://www.cnblogs.com/galex/comments/1153164.html</wfw:comment><comments>http://www.cnblogs.com/galex/archive/2008/04/14/1153164.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/galex/comments/commentRss/1153164.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/galex/services/trackbacks/1153164.html</trackback:ping><description><![CDATA[<p><font face="Verdana">　　今天我们会把经典的LINQ to SQL入门的例子过掉，然后结束第一章，要不老在HelloWorld徘徊，爸爸会骂我的。</font></p>
<p><font face="Verdana">　　要想在程序里使用LINQ to SQL，书上说要先建立对应的实体类(Entity Classes)，所幸的是数据库中的表和字段都能通过Attribute的方式和相关的实体类对应，甚至主键都能标明，只是要引用System.Data.Linq.Mapping命名空间。还需要准备的是提供集成于编程语言查询的数据上下文对象System.Data.Linq.DataContext，它能把对内存对象的数据请求翻译成对数据库的SQL查询，并把执行得到的结果存成集合。如果本机上安装了SQL SERVER 2005 EXPRESS以上的数据库引擎服务，直接把MDF文件的绝对路径传入构造函数就可以方便地初始化这个DataContext对象，通过GetTable就能建立数据表和实体类某实例的映射，操作真的是越来越简便了，一如以下代码：<br />
</font></p>
<p><font face="Verdana"></p>
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080">&nbsp;1</span><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System;<br />
</span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System.Linq;<br />
</span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System.Data.Linq;<br />
</span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System.Data.Linq.Mapping;<br />
</span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;HelloLinqToSql<br />
</span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img id="Codehighlighter1_117_653_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_117_653_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_117_653_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_117_653_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_117_653_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_117_653_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_117_653_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_117_653_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" align="top"  alt="" /></span><span id="Codehighlighter1_117_653_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_117_653_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />[Table(Name</span><span style="color: #000000">=</span><span style="color: #800000">"</span><span style="color: #800000">Contacts</span><span style="color: #800000">"</span><span style="color: #000000">)]<br />
</span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;Contact<br />
</span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img id="Codehighlighter1_158_328_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_158_328_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_158_328_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_158_328_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_158_328_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_158_328_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_158_328_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_158_328_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" /></span><span id="Codehighlighter1_158_328_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_158_328_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">10</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />[Column(IsPrimaryKey</span><span style="color: #000000">=</span><span style="color: #0000ff">true</span><span style="color: #000000">)]<br />
</span><span style="color: #008080">11</span><span style="color: #000000"><img id="Codehighlighter1_209_222_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_209_222_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_209_222_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_209_222_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_209_222_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_209_222_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_209_222_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_209_222_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;ContactID&nbsp;</span><span id="Codehighlighter1_209_222_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_209_222_Open_Text"><span style="color: #000000">{&nbsp;</span><span style="color: #0000ff">get</span><span style="color: #000000">;&nbsp;</span><span style="color: #0000ff">set</span><span style="color: #000000">;&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />[Column(Name</span><span style="color: #000000">=</span><span style="color: #800000">"</span><span style="color: #800000">ContactName</span><span style="color: #800000">"</span><span style="color: #000000">)]<br />
</span><span style="color: #008080">13</span><span style="color: #000000"><img id="Codehighlighter1_271_284_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_271_284_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_271_284_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_271_284_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_271_284_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_271_284_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_271_284_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_271_284_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;Name&nbsp;</span><span id="Codehighlighter1_271_284_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_271_284_Open_Text"><span style="color: #000000">{&nbsp;</span><span style="color: #0000ff">get</span><span style="color: #000000">;&nbsp;</span><span style="color: #0000ff">set</span><span style="color: #000000">;&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">14</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />[Column]<br />
</span><span style="color: #008080">15</span><span style="color: #000000"><img id="Codehighlighter1_313_326_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_313_326_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_313_326_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_313_326_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_313_326_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_313_326_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_313_326_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_313_326_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;City&nbsp;</span><span id="Codehighlighter1_313_326_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_313_326_Open_Text"><span style="color: #000000">{&nbsp;</span><span style="color: #0000ff">get</span><span style="color: #000000">;&nbsp;</span><span style="color: #0000ff">set</span><span style="color: #000000">;&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">16</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">17</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;Main()<br />
</span><span style="color: #008080">18</span><span style="color: #000000"><img id="Codehighlighter1_348_651_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_348_651_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_348_651_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_348_651_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_348_651_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_348_651_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_348_651_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_348_651_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" /></span><span id="Codehighlighter1_348_651_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_348_651_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">19</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;path&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000"><br />
</span><span style="color: #008080">20</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />System.IO.Path.GetFullPath(</span><span style="color: #800000">@"</span><span style="color: #800000">..\..\..\..\Data\northwnd.mdf</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
</span><span style="color: #008080">21</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />DataContext&nbsp;db&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;DataContext(path);<br />
</span><span style="color: #008080">22</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br />
</span><span style="color: #008080">23</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />var&nbsp;contacts&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000"><br />
</span><span style="color: #008080">24</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />from&nbsp;contact&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;db.GetTable</span><span style="color: #000000">&lt;</span><span style="color: #000000">Contact</span><span style="color: #000000">&gt;</span><span style="color: #000000">()<br />
</span><span style="color: #008080">25</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">where</span><span style="color: #000000">&nbsp;contact.City&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">Paris</span><span style="color: #800000">"</span><span style="color: #000000"><br />
</span><span style="color: #008080">26</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />select&nbsp;contact;<br />
</span><span style="color: #008080">27</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">foreach</span><span style="color: #000000">&nbsp;(var&nbsp;contact&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;contacts)<br />
</span><span style="color: #008080">28</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />Console.WriteLine(</span><span style="color: #800000">"</span><span style="color: #800000">Bonjour&nbsp;</span><span style="color: #800000">"</span><span style="color: #000000">+</span><span style="color: #000000">contact.Name);<br />
</span><span style="color: #008080">29</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">30</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div>
<p><br />
　　由上面的例子我们看到，使用LINQ对数据库进行强类型的访问简直是易如反掌。在整个过程中，LINQ to SQL自动为我们做了什么呢？打开数据库链接，告别conn.Open()；生成SQL查询语句，比我们自个去拼凑queryString片段来得更安全；执行对数据库的命令，甚至你都不用想究竟是ExecuteReader还是别的；把执行返回的结果填充至内存对象，这下连while都省去了。先别比较运行的效率，至少开发的效率和准确度都大大提高了。</font></p>
<p><font face="Verdana">　　写书的老外马上意识到读者会问大型复杂的SQL查询和存储过程怎么办，答案必然是没有问题的的，另外好像还有图形化设计器支持呢。世界怎么都变成这样了，不过简单点也好&#8230;&#8230;</font></p>
<img src ="http://www.cnblogs.com/galex/aggbug/1153164.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41965/" target="_blank">[新闻]美国年轻人最喜欢的15大网站</a>]]></description></item><item><title>LINQ(3): HelloWorld的第二个例子</title><link>http://www.cnblogs.com/galex/archive/2008/04/12/1150674.html</link><dc:creator>关小羽</dc:creator><author>关小羽</author><pubDate>Sat, 12 Apr 2008 13:22:00 GMT</pubDate><guid>http://www.cnblogs.com/galex/archive/2008/04/12/1150674.html</guid><wfw:comment>http://www.cnblogs.com/galex/comments/1150674.html</wfw:comment><comments>http://www.cnblogs.com/galex/archive/2008/04/12/1150674.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/galex/comments/commentRss/1150674.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/galex/services/trackbacks/1150674.html</trackback:ping><description><![CDATA[<p><font face="Verdana"><br />
　　继续我们LINQ的学习，昨天体验了LINQ to Object，今天轮到LINQ to XML的入门程序了。我之前基本上很少用到XML，但经常能从同事的口中听到 XML DOM 和 XQuery 之类的词，可见其普及型之高，不学不行。原来XML常用于各种应用间交换数据，存储配置信息，持久化临时数据，生成网页和报表，无所不能！</font></p>
<p><font face="Verdana">　　虽然应用如此广泛，但是至今为止多数的编程语言都没有生来就支持XML，而是通过API的形式对实现XML的操作，包括 XmlDocument， XmlReader， XPathNavigator， XslTransform for XSLT， SAX和XQuery实现等。最大的问题就是这些乱七八糟的API并没有很好地和编程语言进行集成，往往为了得到某个简单的结果需要编写很多又长又臭的代码。然后LINQ to XML出现了，它主要改善了以往DOM的使用体验，也避免了DOM的某些限制。还是要看看LINQ to XML和DOM的对比。前者以元素为中心，声明式模型，代码有着和XML相类的层次结构，集成编程语言的查询，支持流，代码短小精悍；相比之下后者以文档为中心，命令式模型，代码和文档结构毫不相干，无集成编程语言，全部载入内存，代码冗长。尽管LINQ to XML的灵感源于XSLT， XPath和XQuery，但是LINQ的使用范围还是它们不太一样，功能自然就无法对比，不过LINQ支持和它们的组合使用。</font></p>
<p><font face="Verdana">　　下面是书本上那个简单的例子。　　</p>
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080">&nbsp;1</span><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System;<br />
</span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System.Collections.Generic;<br />
</span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System.Linq;<br />
</span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System.Text;<br />
</span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System.Xml;<br />
</span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System.Xml.Linq;<br />
</span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br />
</span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;HelloLinqToXml<br />
</span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img id="Codehighlighter1_153_1777_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_153_1777_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_153_1777_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_153_1777_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_153_1777_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_153_1777_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_153_1777_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_153_1777_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" align="top"  alt="" /></span><span id="Codehighlighter1_153_1777_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_153_1777_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">10</span><span style="color: #000000"><img id="Codehighlighter1_159_242_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_159_242_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_159_242_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_159_242_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_159_242_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_159_242_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_159_242_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_159_242_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_159_242_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/**/</span><span id="Codehighlighter1_159_242_Open_Text"><span style="color: #808080">///</span><span style="color: #008000">&nbsp;</span><span style="color: #808080">&lt;summary&gt;</span><span style="color: #008000"><br />
</span><span style="color: #008080">11</span><span style="color: #008000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;Book&nbsp;Class&nbsp;used&nbsp;for&nbsp;Linq&nbsp;query&nbsp;on&nbsp;Objects<br />
</span><span style="color: #008080">12</span><span style="color: #008000"><img src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;</span><span style="color: #808080">&lt;/summary&gt;</span></span><br />
<span style="color: #008080">13</span><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;Book<br />
</span><span style="color: #008080">14</span><span style="color: #000000"><img id="Codehighlighter1_261_880_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_261_880_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_261_880_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_261_880_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_261_880_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_261_880_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_261_880_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_261_880_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_261_880_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_261_880_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">15</span><span style="color: #000000"><img id="Codehighlighter1_295_308_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_295_308_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_295_308_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_295_308_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_295_308_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_295_308_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_295_308_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_295_308_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;Publisher&nbsp;</span><span id="Codehighlighter1_295_308_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_295_308_Open_Text"><span style="color: #000000">{&nbsp;</span><span style="color: #0000ff">get</span><span style="color: #000000">;&nbsp;</span><span style="color: #0000ff">set</span><span style="color: #000000">;&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">16</span><span style="color: #000000"><img id="Codehighlighter1_337_350_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_337_350_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_337_350_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_337_350_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_337_350_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_337_350_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_337_350_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_337_350_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;Title&nbsp;</span><span id="Codehighlighter1_337_350_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_337_350_Open_Text"><span style="color: #000000">{&nbsp;</span><span style="color: #0000ff">get</span><span style="color: #000000">;&nbsp;</span><span style="color: #0000ff">set</span><span style="color: #000000">;&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">17</span><span style="color: #000000"><img id="Codehighlighter1_375_388_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_375_388_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_375_388_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_375_388_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_375_388_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_375_388_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_375_388_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_375_388_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;Year&nbsp;</span><span id="Codehighlighter1_375_388_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_375_388_Open_Text"><span style="color: #000000">{&nbsp;</span><span style="color: #0000ff">get</span><span style="color: #000000">;&nbsp;</span><span style="color: #0000ff">set</span><span style="color: #000000">;&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br />
</span><span style="color: #008080">19</span><span style="color: #000000"><img id="Codehighlighter1_398_706_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_398_706_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_398_706_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_398_706_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_398_706_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_398_706_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_398_706_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_398_706_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_398_706_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/**/</span><span id="Codehighlighter1_398_706_Open_Text"><span style="color: #808080">///</span><span style="color: #008000">&nbsp;</span><span style="color: #808080">&lt;summary&gt;</span><span style="color: #008000"><br />
</span><span style="color: #008080">20</span><span style="color: #008000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;Contructor&nbsp;for&nbsp;Book&nbsp;Class<br />
</span><span style="color: #008080">21</span><span style="color: #008000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;</span><span style="color: #808080">&lt;/summary&gt;</span><span style="color: #008000"><br />
</span><span style="color: #008080">22</span><span style="color: #008000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;</span><span style="color: #808080">&lt;param&nbsp;name="publisher"&gt;</span><span style="color: #008000">Publisher&nbsp;of&nbsp;the&nbsp;book,&nbsp;Type&nbsp;of&nbsp;string</span><span style="color: #808080">&lt;/param&gt;</span><span style="color: #008000"><br />
</span><span style="color: #008080">23</span><span style="color: #008000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;</span><span style="color: #808080">&lt;param&nbsp;name="title"&gt;</span><span style="color: #008000">Title&nbsp;of&nbsp;the&nbsp;book,&nbsp;Type&nbsp;of&nbsp;string</span><span style="color: #808080">&lt;/param&gt;</span><span style="color: #008000"><br />
</span><span style="color: #008080">24</span><span style="color: #008000"><img src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;</span><span style="color: #808080">&lt;param&nbsp;name="year"&gt;</span><span style="color: #008000">Publish&nbsp;year&nbsp;of&nbsp;the&nbsp;book,&nbsp;Type&nbsp;of&nbsp;int</span><span style="color: #808080">&lt;/param&gt;</span></span><br />
<span style="color: #008080">25</span><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;Book(</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;publisher,&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;title,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;year)<br />
</span><span style="color: #008080">26</span><span style="color: #000000"><img id="Codehighlighter1_776_874_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_776_874_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_776_874_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_776_874_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_776_874_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_776_874_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_776_874_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_776_874_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_776_874_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_776_874_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">27</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Publisher&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;publisher;<br />
</span><span style="color: #008080">28</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Title&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;title;<br />
</span><span style="color: #008080">29</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Year&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;year;<br />
</span><span style="color: #008080">30</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">31</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">32</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;Program<br />
</span><span style="color: #008080">33</span><span style="color: #000000"><img id="Codehighlighter1_903_1775_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_903_1775_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_903_1775_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_903_1775_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_903_1775_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_903_1775_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_903_1775_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_903_1775_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_903_1775_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_903_1775_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">34</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;Main(</span><span style="color: #0000ff">string</span><span style="color: #000000">[]&nbsp;args)<br />
</span><span style="color: #008080">35</span><span style="color: #000000"><img id="Codehighlighter1_953_1769_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_953_1769_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_953_1769_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_953_1769_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_953_1769_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_953_1769_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_953_1769_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_953_1769_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_953_1769_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_953_1769_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">36</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">Initialize&nbsp;the&nbsp;object&nbsp;data&nbsp;for&nbsp;Linq&nbsp;query</span><span style="color: #008000"><br />
</span><span style="color: #008080">37</span><span style="color: #008000"><img id="Codehighlighter1_1048_1256_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1048_1256_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_1048_1256_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_1048_1256_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_1048_1256_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1048_1256_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_1048_1256_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_1048_1256_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Book[]&nbsp;books&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Book[]</span><span id="Codehighlighter1_1048_1256_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1048_1256_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">38</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Book(</span><span style="color: #800000">"</span><span style="color: #800000">Ajax&nbsp;in&nbsp;Action</span><span style="color: #800000">"</span><span style="color: #000000">,</span><span style="color: #800000">"</span><span style="color: #800000">Manning</span><span style="color: #800000">"</span><span style="color: #000000">,</span><span style="color: #800080">2005</span><span style="color: #000000">),<br />
</span><span style="color: #008080">39</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Book(</span><span style="color: #800000">"</span><span style="color: #800000">Windows&nbsp;Forms&nbsp;in&nbsp;Action</span><span style="color: #800000">"</span><span style="color: #000000">,</span><span style="color: #800000">"</span><span style="color: #800000">Manning</span><span style="color: #800000">"</span><span style="color: #000000">,</span><span style="color: #800080">2006</span><span style="color: #000000">),<br />
</span><span style="color: #008080">40</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Book(</span><span style="color: #800000">"</span><span style="color: #800000">RSS&nbsp;and&nbsp;Atom&nbsp;in&nbsp;Action</span><span style="color: #800000">"</span><span style="color: #000000">,</span><span style="color: #800000">"</span><span style="color: #800000">Manning</span><span style="color: #800000">"</span><span style="color: #000000">,</span><span style="color: #800080">2006</span><span style="color: #000000">)<br />
</span><span style="color: #008080">41</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">;<br />
</span><span style="color: #008080">42</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br />
</span><span style="color: #008080">43</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">Contruct&nbsp;a&nbsp;peice&nbsp;of&nbsp;XML&nbsp;fragment</span><span style="color: #008000"><br />
</span><span style="color: #008080">44</span><span style="color: #008000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XElement&nbsp;xml&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;XElement(</span><span style="color: #800000">"</span><span style="color: #800000">books</span><span style="color: #800000">"</span><span style="color: #000000">,<br />
</span><span style="color: #008080">45</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;book&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;books<br />
</span><span style="color: #008080">46</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">where</span><span style="color: #000000">&nbsp;book.Year&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">2006</span><span style="color: #000000">&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">query&nbsp;from&nbsp;object&nbsp;data</span><span style="color: #008000"><br />
</span><span style="color: #008080">47</span><span style="color: #008000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;XElement(</span><span style="color: #800000">"</span><span style="color: #800000">book</span><span style="color: #800000">"</span><span style="color: #000000">,<br />
</span><span style="color: #008080">48</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;XAttribute(</span><span style="color: #800000">"</span><span style="color: #800000">title</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;book.Title),<br />
</span><span style="color: #008080">49</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;XElement(</span><span style="color: #800000">"</span><span style="color: #800000">publisher</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;book.Publisher)<br />
</span><span style="color: #008080">50</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)</span><span style="color: #008000">//</span><span style="color: #008000">add&nbsp;XML&nbsp;Elements&nbsp;and&nbsp;Attibutes</span><span style="color: #008000"><br />
</span><span style="color: #008080">51</span><span style="color: #008000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />
</span><span style="color: #008080">52</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br />
</span><span style="color: #008080">53</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(xml);<br />
</span><span style="color: #008080">54</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.ReadLine();<br />
</span><span style="color: #008080">55</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">56</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">57</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">58</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span></div>
</font><br />
　　看得出来<font face="Verdana">LINQ to XML在对XML的处理上以元素为中心，因而不必完整地构建一个XML文档，更多的时候XML的片段就够了，就像上面这个HelloWorld的程序，就把内存中某部分数据通过查询后写出XML片段，我们会惊喜地发现用LINQ操作内存对象和操作XML基本相似。我习惯上用的是C#，但书本中给出了VB 9的代码，其声明的方式和ASP相仿，表现得更接近XML本身的文档层次结构。</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<img src ="http://www.cnblogs.com/galex/aggbug/1150674.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41964/" target="_blank">[新闻]2008年8月30日IT博客精选</a>]]></description></item><item><title>LINQ(2): 内存对象查询的HelloWorld程序</title><link>http://www.cnblogs.com/galex/archive/2008/04/11/1148863.html</link><dc:creator>关小羽</dc:creator><author>关小羽</author><pubDate>Fri, 11 Apr 2008 10:38:00 GMT</pubDate><guid>http://www.cnblogs.com/galex/archive/2008/04/11/1148863.html</guid><wfw:comment>http://www.cnblogs.com/galex/comments/1148863.html</wfw:comment><comments>http://www.cnblogs.com/galex/archive/2008/04/11/1148863.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/galex/comments/commentRss/1148863.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/galex/services/trackbacks/1148863.html</trackback:ping><description><![CDATA[　　<br />
　　在展示这段简单的代码之前，书上特意提到了LINQ所需的编译和运行环境要求。大家都知道，LINQ是.NET 3.5中自带的一组升级功能，其实指的是编译器和类库（.NET FX），而不是运行环境（.NET CLR），这就意味着我们用LINQ编写的项目经过编译后，能正常地在.NET 2.0上运行。后来在脚注下标出来说，LINQ to SQL至少要运行在.NET 2.0 SP1之上。<br />
　　<br />
　　废话说完，开始经典HelloWorld的代码。<br />
　　
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080">&nbsp;1</span><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;HelloWorld<br />
</span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img id="Codehighlighter1_21_762_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_21_762_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_21_762_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_21_762_Closed_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_21_762_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_21_762_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_21_762_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_21_762_Open_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_21_762_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cnblogs.com/Images/dot.gif" /></span><span id="Codehighlighter1_21_762_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;Program<br />
</span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img id="Codehighlighter1_45_760_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_45_760_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_45_760_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_45_760_Closed_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_45_760_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_45_760_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_45_760_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_45_760_Open_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_45_760_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cnblogs.com/Images/dot.gif" /></span><span id="Codehighlighter1_45_760_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;Main(</span><span style="color: #0000ff">string</span><span style="color: #000000">[]&nbsp;args)<br />
</span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img id="Codehighlighter1_95_754_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_95_754_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_95_754_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_95_754_Closed_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_95_754_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_95_754_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_95_754_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_95_754_Open_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_95_754_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cnblogs.com/Images/dot.gif" /></span><span id="Codehighlighter1_95_754_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img id="Codehighlighter1_126_180_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_126_180_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_126_180_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_126_180_Closed_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_126_180_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_126_180_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_126_180_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_126_180_Open_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">[]&nbsp;words&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span id="Codehighlighter1_126_180_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cnblogs.com/Images/dot.gif" /></span><span id="Codehighlighter1_126_180_Open_Text"><span style="color: #000000">{&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">Hello</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">Wonderful</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">Linq</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">Beautiful</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">World</span><span style="color: #800000">"</span><span style="color: #000000">&nbsp;}</span></span><span style="color: #000000">;<br />
</span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" /><br />
</span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;groups&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000"><br />
</span><span style="color: #008080">10</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;word&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;words<br />
</span><span style="color: #008080">11</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;orderby&nbsp;word&nbsp;ascending<br />
</span><span style="color: #008080">12</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;group&nbsp;word&nbsp;by&nbsp;word.Length&nbsp;into&nbsp;lengthGroups<br />
</span><span style="color: #008080">13</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;orderby&nbsp;lengthGroups.Key&nbsp;descending<br />
</span><span style="color: #008080">14</span><span style="color: #000000"><img id="Codehighlighter1_421_467_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_421_467_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_421_467_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_421_467_Closed_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_421_467_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_421_467_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_421_467_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_421_467_Open_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;</span><span id="Codehighlighter1_421_467_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cnblogs.com/Images/dot.gif" /></span><span id="Codehighlighter1_421_467_Open_Text"><span style="color: #000000">{&nbsp;Length</span><span style="color: #000000">=</span><span style="color: #000000">lengthGroups.Key,&nbsp;Words</span><span style="color: #000000">=</span><span style="color: #000000">lengthGroups}</span></span><span style="color: #000000">;<br />
</span><span style="color: #008080">15</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" /><br />
</span><span style="color: #008080">16</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">foreach</span><span style="color: #000000">&nbsp;(var&nbsp;group&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;groups)<br />
</span><span style="color: #008080">17</span><span style="color: #000000"><img id="Codehighlighter1_524_711_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_524_711_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_524_711_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_524_711_Closed_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_524_711_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_524_711_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_524_711_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_524_711_Open_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_524_711_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cnblogs.com/Images/dot.gif" /></span><span id="Codehighlighter1_524_711_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">18</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(</span><span style="color: #800000">"</span><span style="color: #800000">Words&nbsp;of&nbsp;Length&nbsp;</span><span style="color: #800000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;group.Length);<br />
</span><span style="color: #008080">19</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">foreach</span><span style="color: #000000">&nbsp;(var&nbsp;word&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;group.Words)<br />
</span><span style="color: #008080">20</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(</span><span style="color: #800000">"</span><span style="color: #800000">&nbsp;&nbsp;</span><span style="color: #800000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;word);<br />
</span><span style="color: #008080">21</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">22</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" /><br />
</span><span style="color: #008080">23</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.ReadLine();<br />
</span><span style="color: #008080">24</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">25</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">26</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div>
　　<br />
　　入门的代码都不难，那我还需要说什么呢？是我从这段代码中看到了使用LINQ强大的灵活性和可扩展性。<br />
　　<br />
　　其实在这之前还有一个更简单的例子，只是选择了数组中长度小于等于5的单词并输出。但是做过项目的同事就很清楚，客户往往有一些诡异和变幻莫测的需求，他现在不满足于只看到&#8220;hello linq world&#8221;，而是要想看到所有长度下对应的每一个单词，有可能某个长度的单词集合的个数大于1，他又希望这些单词按字母表顺序罗列，甚至他在考GRE，发自内心地想先看到比较长的单词，所以对于长度的分组要从大到小排列。<br />
<br />
　　要是用以往传统的C#实现，这个需求变更并不太难，大不了先把所有长度找到，再按字母表顺序输出相应的单词。等我们好不容易改好，交给客户，他又不满意了。他说，老罗教我们必须按字母表顺序背单词，但是同一字母开头的单词还是需要先背长的，你给我重新输出个词表吧。这个时候，用传统C#实现的你，肯定会觉得要疯了，因为这次需求变更造成的代码增量应该不小，甚至原来的业务逻辑相当于重新来过，这客户咋这样？没办法，他是上帝，那就再改咯。<br />
<br />
　　不过如果是用LINQ实现，问题的解决方案就变得简单得多得多，只需稍稍改写那句SQL（结构不变，仅调换几个变量的位置和逻辑即可），显示的逻辑基本上都可以不变，代码复用度和效率都大大提高。贴上需求变更后的代码，仅供大家参考，可能还有更好的方案。　　<br />
　　
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080">&nbsp;1</span><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System;<br />
</span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System.Collections.Generic;<br />
</span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System.Text;<br />
</span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System.Linq;<br />
</span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br />
</span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;HelloWorld<br />
</span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img id="Codehighlighter1_108_813_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_108_813_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_108_813_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_108_813_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_108_813_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_108_813_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_108_813_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_108_813_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" align="top"  alt="" /></span><span id="Codehighlighter1_108_813_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_108_813_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;Program<br />
</span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img id="Codehighlighter1_132_811_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_132_811_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_132_811_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_132_811_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_132_811_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_132_811_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_132_811_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_132_811_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_132_811_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_132_811_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">10</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;Main(</span><span style="color: #0000ff">string</span><span style="color: #000000">[]&nbsp;args)<br />
</span><span style="color: #008080">11</span><span style="color: #000000"><img id="Codehighlighter1_182_805_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_182_805_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_182_805_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_182_805_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_182_805_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_182_805_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_182_805_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_182_805_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_182_805_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_182_805_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">12</span><span style="color: #000000"><img id="Codehighlighter1_213_267_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_213_267_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_213_267_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_213_267_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_213_267_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_213_267_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_213_267_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_213_267_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">[]&nbsp;words&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span id="Codehighlighter1_213_267_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_213_267_Open_Text"><span style="color: #000000">{&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">Hello</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">Wonderful</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">Linq</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">Beautiful</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">World</span><span style="color: #800000">"</span><span style="color: #000000">&nbsp;}</span></span><span style="color: #000000">;<br />
</span><span style="color: #008080">13</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br />
</span><span style="color: #008080">14</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;groups&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000"><br />
</span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;word&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;words<br />
</span><span style="color: #008080">16</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;orderby&nbsp;word.Length&nbsp;descending<br />
</span><span style="color: #008080">17</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;group&nbsp;word&nbsp;by&nbsp;word.Substring(</span><span style="color: #800080">0</span><span style="color: #000000">,</span><span style="color: #800080">1</span><span style="color: #000000">)&nbsp;into&nbsp;lengthGroups<br />
</span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;orderby&nbsp;lengthGroups.Key&nbsp;ascending<br />
</span><span style="color: #008080">19</span><span style="color: #000000"><img id="Codehighlighter1_523_571_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_523_571_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_523_571_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_523_571_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_523_571_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_523_571_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_523_571_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_523_571_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;</span><span id="Codehighlighter1_523_571_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_523_571_Open_Text"><span style="color: #000000">{&nbsp;Cap&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;lengthGroups.Key,&nbsp;Words&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;lengthGroups&nbsp;}</span></span><span style="color: #000000">;<br />
</span><span style="color: #008080">20</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br />
</span><span style="color: #008080">21</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">foreach</span><span style="color: #000000">&nbsp;(var&nbsp;group&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;groups)<br />
</span><span style="color: #008080">22</span><span style="color: #000000"><img id="Codehighlighter1_628_762_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_628_762_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_628_762_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_628_762_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_628_762_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_628_762_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_628_762_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_628_762_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_628_762_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_628_762_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">23</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #008080">24</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">foreach</span><span style="color: #000000">&nbsp;(var&nbsp;word&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;group.Words)<br />
</span><span style="color: #008080">25</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(</span><span style="color: #800000">"</span><span style="color: #800000">&nbsp;&nbsp;</span><span style="color: #800000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;word);<br />
</span><span style="color: #008080">26</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">27</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br />
</span><span style="color: #008080">28</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.ReadLine();<br />
</span><span style="color: #008080">29</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">30</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">31</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">32</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span></div>
<br />
　　虽然这只是一个简单的入门例子，我们已经能感觉到LINQ的强大了，因为LINQ有着类似SQL语句强大的查询功能，再结合简单易控的.NET代码，就像一股积蓄已久的力量喷薄而出，看来MS还是蛮啥的。我相信，用好LINQ，基于.NET的敏捷开发会越来越更快的。<br />
<br />
　　聪聪过生日，赶去聚会了，明天继续。<br />
　　<br />
<img src ="http://www.cnblogs.com/galex/aggbug/1148863.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41963/" target="_blank">[新闻]《极品飞车12》最新真人照片、游戏截图</a>]]></description></item><item><title>LINQ(1): LINQ的设计目标和使用动机</title><link>http://www.cnblogs.com/galex/archive/2008/04/11/1147759.html</link><dc:creator>关小羽</dc:creator><author>关小羽</author><pubDate>Fri, 11 Apr 2008 00:53:00 GMT</pubDate><guid>http://www.cnblogs.com/galex/archive/2008/04/11/1147759.html</guid><wfw:comment>http://www.cnblogs.com/galex/comments/1147759.html</wfw:comment><comments>http://www.cnblogs.com/galex/archive/2008/04/11/1147759.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cnblogs.com/galex/comments/commentRss/1147759.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/galex/services/trackbacks/1147759.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;其实书上讲了一大堆的对比，说传统的数据和对象的访问方法怎么怎么不好，事实上目前大多数的程序员仍然采用以前的套路，只是在个人不同的风格习惯上，会用类似NHibernate之类的工具提高效率，关于这些估计大家都深有体会。但是，LINQ究竟有什么好，我们为什么要使用它？知道这个还是蛮重要的。<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;书上粗略提了两点：整合使用多重数据类型和数据源，还有就是强类型支持。前者为跨数据源提供了统一的查询语法和数据处理模型，后者则为SQL语句的编译时检查和智能感知的增强提供基础。<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LINQ这个东东并不是一天建成的，它是从MS Research好几年的若干项目演化合并而成。最开始就是C-Omega项目，它主要作为数据类型扩展增强C#对XML和数据库之间的操作；接着是ObjectSpaces，它最初就是一套数据访问的API，使数据对象化，实现对象内数据查询功能，不过这个项目由于WinFS的延迟而夭折；最后是Xquery的实现，这部分功能在.NET FX 2.0的第一个预览版出现，但最终却放弃了，因为它完全又是一种附加语言。然后MS就停止了这三个项目，并在PDC 2005上公布了LINQ项目的开始。<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;既然LINQ主要整合的是内存对象、关系数据库和XML的数据访问，自然可以分成LINQ to Objects，LINQ to SQL 和 LINQ to XML了。下一步就是入门的代码，期待中。一上午的会，累呀。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<img src ="http://www.cnblogs.com/galex/aggbug/1147759.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41963/" target="_blank">[新闻]《极品飞车12》最新真人照片、游戏截图</a>]]></description></item><item><title>开博第一篇，报告一哈状态</title><link>http://www.cnblogs.com/galex/archive/2008/04/10/1147060.html</link><dc:creator>关小羽</dc:creator><author>关小羽</author><pubDate>Thu, 10 Apr 2008 08:56:00 GMT</pubDate><guid>http://www.cnblogs.com/galex/archive/2008/04/10/1147060.html</guid><wfw:comment>http://www.cnblogs.com/galex/comments/1147060.html</wfw:comment><comments>http://www.cnblogs.com/galex/archive/2008/04/10/1147060.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cnblogs.com/galex/comments/commentRss/1147060.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/galex/services/trackbacks/1147060.html</trackback:ping><description><![CDATA[<p>　　<br />
　　最近再看这本书，翻译就算了，实在忙，而且懂这个的太多，我就不班门弄斧了。偶尔我还是会把值得注意的东西摘出来，大家一起研究哈。<br />
<br />
　　<img alt="" src="http://www.cnblogs.com/images/cnblogs_com/galex/LINQ_IN_ACTION.PNG" border="0" /></p>
<img src ="http://www.cnblogs.com/galex/aggbug/1147060.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41962/" target="_blank">[新闻]IBM正在开发超强性能4TB固态硬盘阵列</a>]]></description></item></channel></rss>