Hi, I am using a StringDictionary to store key value pairs. I need to use the keys and values interchangeably i.e. I should be able to get the key from the value as in my case the values will be distinct.
Is there a direct way I could do it (without looping)? Or if there is any other collection I could use to achieve this?
Currently I am looping:
public String GetKeyFromValue(string value)
{
foreach (KeyValuePair<string, string> kvp in instance)
{
if (String.Equals(kvp.Value, value))
return kvp.Key;
}
throw new Exception ("Key not found in FilterControlMapping");
}
Any help is much appreciated. Thanks.