我估计我可以这样做:
Dictionary<string, <Dictionary<int, int>> targetChapterAdjustments = new Dictionary<string, <Dictionary<int, int>>();
(创建一个将Dictionary作为其“定义”成员的词典。)
但是到底能走多远 - 有限制或实际限制吗?
我可以使用这样的词典:
Dictionary<string, <Dictionary<int, Dictionary<string, <Dictionary<int, Dictionary<bool, <Dictionary<float, Dictionary<string, <Dictionary<int>>>>>>>>>>>>
...例如?
我很想/不喜欢看这样一个班级的创作。
好的,LineBacker跟我说话了;我试过了,但是这个:
Dictionary<string, <Dictionary<int, Dictionary<string, <Dictionary<int, Dictionary<bool, <Dictionary<float, Dictionary<string, <Dictionary<int>>>>>>>>>>>> funWithDictionaries =
new Dictionary<string, <Dictionary<int, Dictionary<string, <Dictionary<int, Dictionary<bool, <Dictionary<float, Dictionary<string, <Dictionary<int>>>>>>>>>>>>();
...因多个语法错误而失败。
由L.B编辑(对不起评论意见太大)
此代码编译。足够你的情况?
var dict = new Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,string>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>();
答案 0 :(得分:5)
C#或CLR没有强制执行任意限制。您最终会遇到的限制是系统内存,但这适用于创建任何对象,而不仅仅是嵌套结构。
泛型的设计是合理的,无论您提供什么类型参数(假设它们是有效类型),它都将起作用。这意味着任何具体类型都可以替换TKey
的{{1}}和TValue
部分。我相信预编译器实际上在幕后创建了一个类,具体类型替换了它们相应的Type参数,所以你所做的只是增加它必须做的工作。如果你要构建一个证明,你会发现这种做法对于任何数量的嵌套来说都是合理的(理论上它可能是无限的,当然你在实践中也做不到这一点。)
答案 1 :(得分:1)
如果您只是询问资源限制,我认为@ evanmcdonall的答案是正确的,但是如果您关心代码设计,您应该避免使用许多嵌套字典,因为它们违反了许多OOP的良好实践,如抽象和OCP。