Linq中如何使用City集合-古蔺大橙子建站
RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
Linq中如何使用City集合

Linq 中如何使用City集合,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

苍南网站制作公司哪家好,找成都创新互联公司!从网页设计、网站建设、微信开发、APP开发、响应式网站等网站项目制作,到程序开发,运营维护。成都创新互联公司成立于2013年到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联公司

因为我们将在好几个示例中重用这个Linq City集合,我决定把它封装到一个"TravelOrganizer"类中,如下所示:

using System;  using System.Collections.Generic;   public class TravelOrganizer  {  public List PlacesVisited  {  get  {  List cities = new List{  & 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;  }  }  }

这使我只需要编写如下的代码就能得到跟上面同样的结果:

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很酷之处就是它是强类型的。这意味着:

1) 你的所有的查询都会进行编译时检查。不像现在的SQL语句,你只有到运行时才会发现你的错误所 在。这意味着你在开发时就可以检查你的代码的正确性,例如,如果我把上面的"distance"误写成 了"distanse",编译器将为我捕获到这个错误。

2) 当你写LINQ查询的时候你将在VS或免费的Visual Web Developer中获得智能感知的提示。这不仅加 快了编码的输入速度,而且使我们在处理无论简单还是复杂的集合和数据源对象模型时都变得非常容易。

看完上述内容,你们掌握Linq 中如何使用City集合的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


文章题目:Linq中如何使用City集合
本文路径:http://scgulin.cn/article/jpiddo.html