为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

C#
子衿沉夜 2021-11-14 15:56:37
如何使用此模式制作带有字典列表的字典?这有效: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"} } },    };“方法没有重载需要两个值”
查看完整描述

2 回答

?
缥缈止盈

TA贡献2041条经验 获得超4个赞

您需要Dictionary<string, string>在List<Dictionary<string, string>>列表中添加集合 而不是key和value


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

{

    { "someKey",

         new List<Dictionary<string, string>>()

         {

             new Dictionary<string, string>() {

                 { "key1", "value1"},

                 { "key2", "value2"}

             }

         }

    }

};


查看完整回答
反对 回复 2021-11-14
?
BIG阳

TA贡献1859条经验 获得超6个赞

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

{


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

};

你错过了你有一个List的点Dictionary


查看完整回答
反对 回复 2021-11-14
  • 2 回答
  • 0 关注
  • 165 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信