制作一个包含字典列表的字典?

如何使用此模式制作带有字典列表的字典?


这有效:


public static Dictionary<string, List<string>> someDict = new Dictionary<string, List<string>>

{

    { "someKey" , new List<string> { "listValue1", "listValue2" } },

};

这不起作用:


    public static Dictionary<string, List<Dictionary<string, string>>> whateverName = new Dictionary<string, List<Dictionary<string, string>>>

    {

        { "someKey", new List<Dictionary<string, string>> { { "key1", "value1"}, { "key2", "value2"} } },

    };

“方法没有重载需要两个值”


子衿沉夜
浏览 166回答 2
2回答

缥缈止盈

您需要Dictionary<string, string>在List<Dictionary<string, string>>列表中添加集合 而不是key和valueDictionary<string, List<Dictionary<string, string>>> whateverName = new Dictionary<string, List<Dictionary<string, string>>>{&nbsp; &nbsp; { "someKey",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;new List<Dictionary<string, string>>()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;new Dictionary<string, string>() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ "key1", "value1"},&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ "key2", "value2"}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; }};

BIG阳

public static Dictionary<string, List<Dictionary<string, string>>> whateverName = new Dictionary<string, List<Dictionary<string, string>>>{&nbsp; &nbsp; { "someKey", new List<Dictionary<string, string>> { new Dictionary<string, string>{{ "key1", "value1"}, { "key2", "value2"} } } },};你错过了你有一个List的点Dictionary
打开App,查看更多内容
随时随地看视频慕课网APP