ASP.NET / C# : Multidimensional Dictionary or Equivalent

skij used Ask the Experts™
Using ASP.NET/C#, how can I form a multidimensional dictionary or something that is equivalent?

Here is an example of the structure I need:
Basket1 =>
  "USDCAD" = "Buy",
  "EURUSD" = "Sell",
  "USDCHF" = "Buy"
Basket2 =>
  "USDCAD" = "Sell",
  "AUDCAD" = "Sell",
  "CADJPY" = "Buy",
  "CADCHF" = "Buy"
Basket3 =>
  "EURUSD" = "Buy"

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
You can, in effect, nest any collection in .NET. Each collection is a type, so you can use those collections as the types of other collections. You could do:

List<List<string>> doubleList;
Dictionary<string, List<string>> dictionaryOfLists;
Dictionary<string, Dictionary<string, string>> dictionaryOfDictionaries;
Dictonary<string, Dictionary<string, List<string>>> dictionaryOfDictionariesOfLists;

Open in new window

You simply need to write the types accordingly when you declare.

My guess is that you're looking for something like:

Dictionary<string, Dictionary<string, string>> baskets = new Dictionary<string, Dictionary<string, string>>();

baskets.Add("Basket1", new Dictionary<string, string>());
baskets.Add("Basket2", new Dictionary<string, string>());
baskets.Add("Basket3", new Dictionary<string, string>());

baskets["Basket1"].Add("USDCAD", "Buy");

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial