I doubt this is possible, but I was curious if you could have more than 2 items (key,value) in a dictionary. Maybe a key and 2 values. Is there a collection object that does allow this? What I am actually trying to do is to store a key and a value for the key and another value to hold the count of how many times the key has been found. For example, I may have a for loop that goes through a list of colors and each color has a unique value. As I go through the list, I not only want to store the color, the unique value of the color in a dictionary, but also store how many times red occurred in the list.
I put in the following declaration and now I am tyring to figure out how I can test to see if it contains the value already and if it does not, add it to the list with a count of 1 and if it does, increment the count. After I post the declaration, I will post how I was doing it with just one dictionary.
Dictionary<string, Dictionary<int,int>> colors = new Dictionary<string, Dictionary<int,int>>();
Here is code of how I was handling it before:
Dictionary<string, int> colors = new Dictionary<string, int>(); foreach (Color color in ColorList) { if (colors.ContainsKey(color.ToString())) colors[color]++; else colors.Add(color, 1); }
Could you perhaps have a dictionary of a struct that would keep track of the color and the number of times it occurred?
Edit: As suggested elsewhere, this could also be accomplished by building your own small custom class. Would essentially work in the same fashion.