LINQ入門(mén)簡(jiǎn)單描述
語(yǔ)言集成查詢(xún) (LINQ)有很多值得學(xué)習(xí)的地方,這里我們主要介紹一下LINQ入門(mén),包括介紹LINQ查詢(xún)語(yǔ)言等方面。
語(yǔ)言集成查詢(xún) (LINQ) 是 Visual Studio 2008 和 .NET Framework 3.5 版中一項(xiàng)突破性的創(chuàng)新,它在對(duì)象領(lǐng)域和數(shù)據(jù)領(lǐng)域之間架起了一座橋梁。
傳統(tǒng)上,針對(duì)數(shù)據(jù)的查詢(xún)都是以簡(jiǎn)單的字符串表示,而沒(méi)有編譯時(shí)類(lèi)型檢查或 IntelliSense 支持。此外,您還必須針對(duì)以下各種數(shù)據(jù)源學(xué)習(xí)不同的查詢(xún)語(yǔ)言:SQL 數(shù)據(jù)庫(kù)、XML 文檔、各種 Web 服務(wù)等。LINQ 使查詢(xún)成為 C# 和 Visual Basic 中的一等語(yǔ)言構(gòu)造。應(yīng)用于所有信息源( all sources of information )的具有多種用途( general-purpose )的語(yǔ)法查詢(xún)特性( query facilities )。對(duì)所有信息源的查詢(xún)語(yǔ)句,類(lèi)似數(shù)據(jù)庫(kù)的sql語(yǔ)句,xml的xpath 。
LINQ入門(mén)代碼:
- using System;
 - using System.Collections.Generic;
 - using System.ComponentModel;
 - using System.Data;
 - using System.Drawing;
 - using System.Linq;
 - using System.Text;
 - using System.Windows.Forms;
 - namespace HelloVS2008
 - {
 - public partial class LinqFrm : Form
 - {
 - public LinqFrm()
 - {
 - InitializeComponent();
 - }
 - private void btnLinq_Click(object sender, EventArgs e)
 - {
 - int[] arr = new int[] { 8, 5, 89, 3, 56, 4, 1, 58 };//信息源
 - //var申請(qǐng)的是無(wú)類(lèi)型變量。n沒(méi)有定義就使用了,類(lèi)似javascript語(yǔ)法
 - //正常的次序:select item from item in items where item>5 orderby item 就是把select item置后
 - //與sql的區(qū)別:select col1 from table 這里似乎是select col1 from col1 in table 不知何故
 - var m = from n in arr where n < 5 orderby n select n;
 - foreach (var n in m)
 - {
 - txtLinq.Text += n;
 - }
 - }
 - }
 - }
 
以上是LINQ入門(mén)介紹
【編輯推薦】















 
 
 
 
 
 
 