-3

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mårten
  • 231
  • 2
  • 14
  • 2
    When you say *multi-level dictionary* do you mean something like `Dictionary>`? This question is unclear. – Yuck Jan 03 '12 at 14:04
  • Is there any limit on the depth? – BlueMonkMN Jan 03 '12 at 14:11
  • It looks like you're trying to find a C# equivalent to the STL `multimap` class in C++. [Here](http://www.dotnetperls.com/multimap)'s a decent implementation from dotnetperils. – M.Babcock Jan 03 '12 at 14:25

1 Answers1

0

you can use a Dictionary with type of Key Dictionary...

so you can say:

Dictionary<string, Dictionary < string, string>> x;

and use it as mentioned of you..

x["asdf"]["asdf"] = "asdf";