c# - 为嵌套字典添加价值
问题描述
如果我有:
var dict = new Dictionary<Dictionary<string, string>, Dictionary<int, int>>();
如何向嵌套字典添加值。这样做的正确语法是什么?
dict.Add(...)
我知道 > 的语法。但不是两个嵌套字典合二为一。
解决方案
并不是说使用字典作为另一个字典的键很有意义..
var dict1 = new Dictionary<string, string>();
var dict2 = new Dictionary<int, int>();
dict.Add(dict1, dict2);
or
dict.Add(new Dictionary<string, string>(), new Dictionary<int, int>());
或使用初始化程序的一些数据
dict.Add(new Dictionary<string, string>() { { "test", "test"} }, new Dictionary<int, int>() { {1, 1}});
推荐阅读
- sapui5 - 如何根据 UI5 中的值格式化表内的文本字段?
- variables - 如何成功启动 vsim 命令?即使它在 CentOS 8 的 PATH 环境变量中也找不到
- javascript - 带有 HTML 符号的 SVG 到 Canvas
- python - 如何从csv文件中删除子路径
- r - 如何解决cut()中的错误:'x'必须是数字?
- python - Python - 打印十六进制数据显示错误值
- java - Netty:有多少线程在服务器端口(80)上接受连接
- amazon-web-services - 您如何确定上传是否在 S3 预签名 URL 中成功完成?
- java - 如何将枚举与超类型分组
- java - 使用 mockito 的 Spring MVC 模拟未在服务层发生