如何使用此模式制作包含字典列表的字典?
这有效:
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"} } },
};
“方法的无重载采用两个值”
答案 0 :(得分:3)
您需要在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"}
}
}
}
};
答案 1 :(得分:0)
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
的问题