本文介绍了使用哈希表集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

RegionName.getRegionName("CA", null);
GEOIP_REGION_NAME = Count = 193


RegionName.GEOIP_REGION_NAME["CA"]  Count = 13  object {System.Collections.Hashtable}
-       ["ON"]  "Ontario"
        Key "ON"    object {string}
        Value   "Ontario"   object {string}
+       ["NT"]  "Northwest Territories"
+       ["BC"]  "British Columbia"
+       ["YT"]  "Yukon Territory"
+       ["NL"]  "Newfoundland"
+       ["SK"]  "Saskatchewan"
+       ["NS"]  "Nova Scotia"
+       ["NU"]  "Nunavut"
+       ["MB"]  "Manitoba"
+       ["NB"]  "New Brunswick"
+       ["AB"]  "Alberta"
+       ["QC"]  "Quebec"
+       ["PE"]  "Prince Edward Island"


RegionName.GEOIP_REGION_NAME["CA"]  Count = 13  object {System.Collections.Hashtable}



如何遍历以上内容并填充以下内容



How can I loop through the above and populate the following

public CascadingDropDownNameValue[] GetStates(string knownCategoryValues, string category)
       {
           string CountryCode = "";

           StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

           if (kv["CountryID"].ToString() == null)
           {
               throw new ArgumentException("Country not found.");
           }

           CountryCode = Convert.ToString(kv["CountryID"].ToString());

           RegionName.getRegionName(CountryCode, null); // Return a collections hashtable

           List<CascadingDropDownNameValue> l = new List<CascadingDropDownNameValue>();

           // Need to loop through the collections and build cas
           while (())
           {
               l.Add(new CascadingDropDownNameValue(RegionName.GEOIP_REGION_NAME["CA"]????,RegionName.GEOIP_REGION_NAME["CA"]????);
           }

           return l.ToArray();
       }


任何帮助将不胜感激.


Any help would be appreciated.

推荐答案

public CascadingDropDownNameValue[] GetStates(string knownCategoryValues, string category)
{
    string CountryCode = "";

    StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

    if (kv["CountryID"].ToString() == null)
    {
        throw new ArgumentException("Country not found.");
    }

    CountryCode = Convert.ToString(kv["CountryID"].ToString());
    // I take it from your code that RegionName.getRegionName is returning a Hashtable
    // Going by that name I'm not really sure
    Hashtable ht = RegionName.getRegionName(CountryCode, null); // Return a collections hashtable

    List<CascadingDropDownNameValue> list = new List<CascadingDropDownNameValue>();

    // Need to loop through the collections and build cas
    // Iterating over a hastable is easy when you use DictionaryEntry
    // Each DictionaryEntry has a Key and a Value property of type object
    foreach (DictionaryEntry de in ht)
    {
        list.Add(new CascadingDropDownNameValue(de.Key.ToString(), de.Value.ToString());
    }

    return list.ToArray();
}


这篇关于使用哈希表集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 17:45