c# - 从数组列表中获取字典

标签 c# asp.net dictionary arraylist

protected Dictionary<string , string> xmlList = new Dictionary<string , string>();
protected System.Collections.ArrayList list = new System.Collections.ArrayList();

我已经将字典存储在这样的数组列表中..

    xmlList.Add( "image" , "images/piece1.png" );
    xmlList.Add( "description" , " Experience why entertainment is more amazing with Xbox."            );
    xmlList.Add( "title" , "Downloads" );
    list.Add( xmlList );
    xmlList.Clear();
    xmlList.Add( "image" , "images/piece2.png" );
    xmlList.Add( "description" , "Limited-time offer: Buy Office now, get the next version free.*" );
    xmlList.Add( "title" , "Security & Updates" );
    list.Add( xmlList );

如何从数组列表中访问字典的每个元素?

<% for (int i = 0; i < list.Count; i++)
    {
    foreach(Dictionary<string , string> itemList in list)
        {
        Response.Write( itemList["image"] );
        }
   } 
%>

这给了我两次相同的结果 'images/piece2.png'..

我做不到

foreach(Dictionary<string , string> itemList in list[i])
    {
    Response.Write( itemList["image"] );
    }

最佳答案

 protected Dictionary<string, string> xmlList;
    protected System.Collections.ArrayList list = new System.Collections.ArrayList();

 xmlList = new Dictionary<string, string>();
        xmlList.Add("image", "images/piece1.png");
        xmlList.Add("description", " Experience why entertainment is more amazing with Xbox.");
        xmlList.Add("title", "Downloads");
        list.Add(xmlList);
        xmlList = new Dictionary<string, string>();
        xmlList.Add("image", "images/piece2.png");
        xmlList.Add("description", "Limited-time offer: Buy Office now, get the next version free.*");
        xmlList.Add("title", "Security & Updates");
        list.Add(xmlList);

        foreach (Dictionary<string, string> itemList in list)
        {
            Response.Write(itemList["image"]);
            Response.Write("<br>");
        }

关于c# - 从数组列表中获取字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13757370/

相关文章:

swift - Dictionary 中的变量与类中其他变量之间的联系

c# - Linq To Entities Group By 键中有多个表

c# - 无效的属性 ID 错误 - 来自 List<> c# ASP.NET 的 JSON 对象

c# - Dispatcher 是一个可以在 C# 中传递的对象吗?

c# - ScriptManager.RegisterClientScriptBlock 和 Response.Write 有什么区别?

asp.net - 如何向我的 POCO(template) 类添加验证

Scala 不可变多重映射

python - 将 csv 仅一列转换为字典

c# - 等效于 Java 中的 C# 关键字 'as'

c# - 单独库中 Controller 的动态路由前缀