C# 基于多级字典的类
我计划创建一个表示 html 表的类,问题是它必须能够包含 3 个以上的维度,其中一个维度当然是宽度,其余的将沿着长度,如下所示:
foo1:bar1
foo1:bar2
foo2:bar1
foo2:bar2
etc.
现在我正在考虑如何在我的类中表示这一点,我的想法是使用多级字典,即可以像这样索引的字典:myDict[fooKey][barKey][...]
,是这样的好主意吗?是否可以?如何?
我可以让该类的用户给它任何字典以及 int 深度,然后在内部使用该类时转换为字典吗?
编辑:似乎我有点不清楚,显然有一个实际的深度限制,但我更喜欢对任何深度进行编码,深度应该由类的用户给出。
I'm planning to create a class representing a html table, problem is that it must be able to contain 3+ dimensions, one dimension will be the width of course, the rest will be along the length like this:
foo1:bar1
foo1:bar2
foo2:bar1
foo2:bar2
etc.
Now I'm contemplating how to represent this in my class, my idea is to use a multi-level dictionary, i.e. one that can be indexed like this: myDict[fooKey][barKey][...]
, is that a good idea? Is it possible? How?
Can I let the user of the class give it any Dictionary along with an int depth and then cast to dictionary when using the class internally?
edit: Seems like I was a bit unclear, there is a practical depth limit obviously, but I'd prefer to code it for any depth, the depth should be given by the user of the class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用密钥字典类型的字典...
所以您可以说:
并按照您提到的方式使用它..
you can use a Dictionary with type of Key Dictionary...
so you can say:
and use it as mentioned of you..