zoukankan      html  css  js  c++  java
  • 两种转换城市的方式

    首先已经将国内和国际的城市列表分别存到了表dtcity和dtIcity,

    第一种是使用datatable.select找出数据出来存入datarow[]中,然后读取

    1 DataRow[] rowscity = dtcity.Select("AirportCode='" +takeoffstn + "'");
    2 if (rowscity.Length < 1)
    3     rowscity = dtIcity.Select("AirportCode='" + takeoffstn + "'");
    4 if (rowscity.Length < 1)
    5     takeoffstn = "未知城市";
    6 else
    7 {
    8     takeoffstn = rowscity[0]["AirportCN"].ToString();
    9 }

    第二种方法是使用linq,将datatable转换成list<T>形式,然后使用where和lambda表达式来读取

     1 List<CityList> cityhost = ExtendMethod.ToList<CityList>(dtcity);
     2 List<CityList> cityInt = ExtendMethod.ToList<CityList>(dtIcity);
     3 var chost = cityhost.Where(c => c.AirportCode == takeoffstn).ToList();
     4 if (chost == null || chost.Count < 1)
     5     chost = cityInt.Where(c => c.AirportCode == takeoffstn).ToList();
     6 if (chost == null || chost.Count < 1)
     7     takeoffstn = "未知城市";
     8 else
     9 {
    10     takeoffstn = chost[0].AirportCN;
    11 }

    两种方式都可以,不过使用linq的会快一点

  • 相关阅读:
    input.file上传图片| FileReader h5新特性
    lua的luasocket程序
    nginx的proxy_set_header
    lua的table.sort
    lua的深拷贝和浅拷贝
    nginx的location匹配
    kong后台接口
    一些程序和工具
    lua的模式匹配
    php的一些语法
  • 原文地址:https://www.cnblogs.com/Lvkang/p/10068989.html
Copyright © 2011-2022 走看看