In C#, the Dictionary class takes a single key and maps it to a single value. I’m looking for something similar, where I can pass in an ordered tuple and get a single value — without wrapping it in a class.
Here’s a pretty hypothetical example of what I want (with buttons, instead of some 2D map tile). Currently, I can do this:
Dictionary<int, Button> buttons = new Dictionary<int, Button>();
If I want to use each button’s coordinates as the key, I can do this:
Dictionary<Point, Button> buttons = new Dictionary<Point, Button>();
buttons[new Point(b.X, b.Y)] = b;
What I would like to do is this
Dictionary<int, int, Button> buttons = new Dictionary<int, int, Button>();
buttons[b.X, b.Y] = b;
Again, it’s a trivial case with a known work-around. But I just find it annoying that I have to create a new placeholder class (struct?) with each set of parameters that I want to use as a key.
Is this somehow possible?
1 Answer