俺用以下代码得到一个IDictionary  rootMap, 然后用foreach (DictionaryEntry myDE in rootMap) 读value和key,但无论怎么样都只得到rootMap里的内容,得不到itemMap里的,怎么样才能把IDictionary rootMap里的全部内容,包括itemMap的也读出来呢?谢谢IDictionary rootMap = new Hashtable();
IList items = new ArrayList();
IDictionary itemMap = null;
rootMap.Add("items", items);
rootMap = new Hashtable();
items.Add(rootMap);itemMap.Add("title", "itemTitle");
itemMap.Add("link", "itemLink");
itemMap.Add("description", "itemDescription");rootMap.Add("title", "rootTitle");
rootMap.Add("description", "rootDescription");
rootMap.Add("link", "rootLink");

解决方案 »

  1.   

    to 但无论怎么样都只得到rootMap里的内容,得不到itemMap里的,怎么样才能把IDictionary rootMap里的全部内容,包括itemMap的也读出来呢?谢谢看你的代码,你并没有初始化itemMap
      

  2.   

    但如果我IDictionary itemMap = new Hashtable(); 会报远程计算机强行关闭一个连接的错误,怎么初始化?请指教.
      

  3.   

    这只是新建一个hashtable,然后得到Idirctory接口对象,并不会造成关机,我如下试过没问题:
    IDictionary rootMap = new Hashtable();
    IDictionary itemMap = new Hashtable();
      

  4.   

    IDictionary object is a key/value pair, the element type is not the type of the key or the type of the value. Instead, the element type is DictionaryEntry. For example:
    C#
    foreach (DictionaryEntry de in myHashtable) {...}quote: http://msdn2.microsoft.com/en-us/library/system.collections.idictionary.aspx