/***************Linq入门**************** * Language Integrated Query (LINQ) * 应用于所有信息源( all sources of information )的具有多种用途( general-purpose )的语法查询特性( query facilities ) * 意思就是:对所有信息源的查询语句,类似数据库的sql语句,xml的xpath **************************************/ 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申请的是无类型变量。n没有定义就使用了,类似javascript语法 //正常的次序:select item from item in items where item>5 orderby item 就是把select item置后 //与sql的区别: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; } } } }