Linq中如何使用City集合

Linq 中如何使用City集合,相信很多沒(méi)有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。

蒼南網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)公司!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營(yíng)維護(hù)。成都創(chuàng)新互聯(lián)公司成立于2013年到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來(lái)保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)公司

因?yàn)槲覀儗⒃诤脦讉€(gè)示例中重用這個(gè)Linq City集合,我決定把它封裝到一個(gè)"TravelOrganizer"類中,如下所示:

using System;  using System.Collections.Generic;   public class TravelOrganizer  {  public List<Location> PlacesVisited  {  get  {  List<Location> cities = new List<Location>{  & nbsp; & nbsp;new Location { City="London", Distance=4789, Country="UK" },  & nbsp; & nbsp;new Location { City="Amsterdam", Distance=4869, Country="Netherlands" },  & nbsp; & nbsp;new Location { City="San Francisco", Distance=684, Country="USA" },  & nbsp; & nbsp;new Location { City="Las Vegas", Distance=872, Country="USA" },  & nbsp; & nbsp;new Location { City="Boston", Distance=2488, Country="USA" },  & nbsp; & nbsp;new Location { City="Raleigh", Distance=2363, Country="USA" },  & nbsp; & nbsp;new Location { City="Chicago", Distance=1733, Country="USA" },  & nbsp; & nbsp;new Location { City="Charleston", Distance=2421, Country="USA" },  & nbsp; & nbsp;new Location { City="Helsinki", Distance=4771, Country="Finland" },  & nbsp;new Location { City="Nice", Distance=5428, Country="France" },  & nbsp; & nbsp;new Location { City="Dublin", Distance=4527, Country="Ireland" }  & nbsp; & nbsp;};     return cities;  }  }  }

這使我只需要編寫如下的代碼就能得到跟上面同樣的結(jié)果:

using System;  using System.Collections.Generic;  using System.Web;  using System.Web.UI;  using System.Query;     public partial class Step3 : System.Web.UI.Page  {  protected void Page_Load(object sender, EventArgs e)  {  TravelOrganizer travel = new TravelOrganizer();     GridView1.DataSource = from location in travel.PlacesVisited  & nbsp; where location.Distance > 1000  & nbsp; orderby location.Country, location.City  & nbsp; select location;     GridView1.DataBind();  }  }

LINQ很酷之處就是它是強(qiáng)類型的。這意味著:

1) 你的所有的查詢都會(huì)進(jìn)行編譯時(shí)檢查。不像現(xiàn)在的SQL語(yǔ)句,你只有到運(yùn)行時(shí)才會(huì)發(fā)現(xiàn)你的錯(cuò)誤所 在。這意味著你在開發(fā)時(shí)就可以檢查你的代碼的正確性,例如,如果我把上面的"distance"誤寫成 了"distanse",編譯器將為我捕獲到這個(gè)錯(cuò)誤。

2) 當(dāng)你寫LINQ查詢的時(shí)候你將在VS或免費(fèi)的Visual Web Developer中獲得智能感知的提示。這不僅加 快了編碼的輸入速度,而且使我們?cè)谔幚頍o(wú)論簡(jiǎn)單還是復(fù)雜的集合和數(shù)據(jù)源對(duì)象模型時(shí)都變得非常容易。

看完上述內(nèi)容,你們掌握Linq 中如何使用City集合的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

網(wǎng)站欄目:Linq中如何使用City集合
瀏覽地址:http://muchs.cn/article10/jpiddo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊(cè)建站公司虛擬主機(jī)、品牌網(wǎng)站設(shè)計(jì)、電子商務(wù)、手機(jī)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營(yíng)