[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

Generic Dictionary Linking?

I need a generic Dictionary like this: Dictionary<int, string, string, string>.

Q. Is there a way to link/gang Dictionary's together to build larger ones?

Note: I've already discovered this one, but I'm looking for another alternative. http://www.aronweiler.com/2009/02/multi-key-generic-dictionary-class-for.html
0
pointeman
Asked:
pointeman
  • 3
  • 2
1 Solution
 
ViceroyFizzlebottomCommented:
I don't know if I'm interpreting your question correctly, but could you simply use a IList<string> lookup? Using the int as a key, you could then have access to the three strings, but you wouldn't be constrained by the content going into the IList.

Dictionary<int, IList<string>>
0
 
pointemanAuthor Commented:
Over my head on that one. Do you have a code example?
0
 
ViceroyFizzlebottomCommented:
I don't know what you're trying to store in the Dictionary, but here is kindof an example:


string custName = "Fred";
            string custAddress = "12345 Street 1";
            string custZip = "90210";
            int custId = 1;
 
            IList<string> custData = new List<string>();
            custData.Add(custName);
            custData.Add(custAddress);
            custData.Add(custZip);
 
            //Now we want to store all this information for easy retrieval later
            Dictionary<int, IList<string>> dictionary = new Dictionary<int, IList<string>>();
            dictionary.Add(custId, custData);
 
            // Now to access data for a customer
            if (dictionary.ContainsKey(1))
            {
                IList<string> newCustData = dictionary[1];
                foreach (string item in newCustData)
                {
                    Console.WriteLine(item);
                }
            }

Open in new window

0
 
pointemanAuthor Commented:
Great example. I'm working with it as we speak...
0
 
pointemanAuthor Commented:
Excellent... Thank You
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now