zoukankan      html  css  js  c++  java
  • .Net中字典的使用

            /// <summary>
            /// 获取用户市信息
            /// </summary>
            /// <param name="CustomerId"></param>
            /// <returns></returns>
            [HttpPost]
            public ActionResult GetCustomerProvinceAndCity(int CustomerId)
            {
                // 检测是否已有记录
                IList<GenericAttribute> customerAttributes = _genericAttributeService.GetAttributesForEntity(CustomerId, "Customer");
                Dictionary<string, string> myDictionary = new Dictionary<string, string>();
                foreach (GenericAttribute item in customerAttributes)
                {
                    //if (item.Key == "ProvinceName")
                    //{
                    //    myDictionary["ProvinceName"] = item.Value;
                    //    continue;
                    //}
    
                    //if (item.Key == "CityName")
                    //{
                    //    myDictionary["CityName"] = item.Value;
                    //    continue;
                    //}
    
                    if (item.Key == "ProvinceName")
                    {
                        myDictionary.Add("ProvinceName", item.Value);
                        continue;
                    }
    
                    if (item.Key == "CityName")
                    {
                        myDictionary.Add("CityName", item.Value);
                        continue;
                    }
                }
    
                if (myDictionary.Count > 0)
                { // 存在
                    return Json(new { result = true, info = myDictionary.ToArray(), msg = "获取成功" });
                }
                else
                { // 不存在
                    return Json(new { result = true, info = myDictionary.ToArray(), msg = "不存在" });
                }
            }
    
    

    Dictionary 方便存储 key/value这种类型的数据,这个比Array要灵活一些。
    上面的两种方式都可以保存数据。

    判断数据数量,是通过Count属性。

    最后返回数据的时候,可以统一转化为Array数组形式。

  • 相关阅读:
    ArcGIS Server 10.2 安装教程
    leaflet 使用kriging.js实现前端自定义插值
    气象科普 -降水
    前端开发者如何用JS开发后台
    Spring的简单介绍
    Hibernate与jsp技术结合的小例子
    Servlet_001 我的第一个servlet程序
    Hibernate一级缓存和三种状态
    github提交代码
    MySql索引原理以及查询优化
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/6958282.html
Copyright © 2011-2022 走看看