C# 制作包含词典列表的词典?
如何使用此模式创建包含词典列表的词典 这项工作:C# 制作包含词典列表的词典?,c#,C#,如何使用此模式创建包含词典列表的词典 这项工作: public static Dictionary<string, List<string>> someDict = new Dictionary<string, List<string>> { { "someKey" , new List<string> { "listValue1", "listValue2" } }, }; publicstaticdictionary so
public static Dictionary<string, List<string>> someDict = new Dictionary<string, List<string>>
{
{ "someKey" , new List<string> { "listValue1", "listValue2" } },
};
publicstaticdictionary someDict=新字典
{
{“someKey”,新列表{“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"} } },
};
publicstaticdictionary whateverName=新字典
{
{“someKey”,新列表{{“key1”,“value1”},{“key2”,“value2”},
};
“方法无重载取两个值”您需要在
列表中添加字典集合,而不是键和值
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"}
}
}
}
};
Dictionary whateverName=新字典
{
{“someKey”,
新名单()
{
新字典(){
{“key1”,“value1”},
{“key2”,“value2”}
}
}
}
};
公共静态字典whateverName=新字典
{
{“someKey”,新列表{新字典{{“key1”,“value1”},{“key2”,“value2”}},
};
你忽略了一点,那就是你有一个字典的列表
,为什么会被否决?他问了一个问题并发布了他的代码。他有一个语法错误,这是两个人在回答时指出的。对我来说似乎完全合理。
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"} } } },
};