It's easy to get the value of a key from a .Net 2.0 generic Dictionary:
Dictionary<int, string> greek = new Dictionary<int, string>();
greek.Add(1, "Alpha");
greek.Add(2, "Beta");
string secondGreek = greek[2]; // Beta
But is there a simple way to get the key of a value?
int[] betaKeys = greek.WhatDoIPutHere("Beta"); // expecting single 2
Then layman's solution
A function similar to the one below could be written to make such a dictionary:
As everyone else has said, there's no mapping within a dictionary from value to key.
I've just noticed you wanted to map to from value to multiple keys - I'm leaving this solution here for the single value version, but I'll then add another answer for a multi-entry bidirectional map.
The normal approach to take here is to have two dictionaries - one mapping one way and one the other. Encapsulate them in a separate class, and work out what you want to do when you have duplicate key or value (e.g. throw an exception, overwrite the existing entry, or ignore the new entry). Personally I'd probably go for throwing an exception - it makes the success behaviour easier to define. Something like this:
Can't you create a subclass of Dictionary which has that functionality?
EDIT: Sorry, didn't get code right first time.
Okay, here's the multiple bidirectional version:
Maybe the easiest way to do it, without Linq, can be to loop over the pairs:
If you had Linq, it could have done easily this way:
As I wanted a full fledged BiDirectional Dictionary (and not only a Map), I added the missing functions to make it an IDictionary compatible class. This is based on the version with unique Key-Value Pairs. Here's the file if desired (Most work was the XMLDoc through):