LINQ

string [] cities={"London","Amsterdam","San Fran","a"};

GridView1.DataSource=from city in cites where city.length>4 orderby city select city.ToUpper();

返回类型:IEnumerable<string> result =from city in cities where city.Length>4 orderby city select ctiy.ToUpper();

select 子句选择的对象类型决定了这里的<T>类型。、

ASP.net 控件可以绑定到任何的IEnumerable 集合。如:<asp:Repeater>,<asp:datalist>

<asp:dropdownlist>

List<Location> cities =new List<Location>{new Location{City,"Londoen",Country="England",Distance=12},{City,"Londddoen",Country="England",Distance=122}};

GridView1.DataSource=from location in cities where location.Diatance>12 orderby

location.country,location.City select location;

GridView1.DataBind();

原文地址:https://www.cnblogs.com/zhubenxi/p/5277669.html