2012-10-17 30 views

回答

4

您还需要在字典中循环,为了做到这一点,您可以使用Foreach来迭代tempDic

foreach(Dictionary<string, string> tempDic in rootNode) 
{ 
    foreach(KeyValuePair<string, string> _x in tempDic) 
    { 
     Response.Write(_x.key + "," + _x.value + "<br>"); 
    } 
} 
+0

但数组列表只有12行,有哪行只有一个字典,而使用2个foreach会打印出大约62行数据。 – hkguile

0

你可以使用LINQ第一个获得所有KeyValuePair s的列表(实际上IEnumerable<KeyValuePair<string, string>>):

var pairs = rootNode.OfType<Dictionary<string, string>>() 
        .SelectMany(d => d.AsEnumerable()); 
foreach (KeyValuePair<string, string> tempPair in pairs) 
{ 
    Response.Write(tempPair.Key + "," + tempPair.Value + "<br>"); 
} 

所以,这将是足够的做只有一个foreach循环。另一个将由LINQ为您完成。

相关问题