从.Net集合中获取密钥

Ras*_*dit 2 collections dictionary .net-2.0

我使用StringDictionary来存储键值对.我需要交替使用键和值,即我应该能够从值中获取键,因为在我的情况下,值将是不同的.

有没有直接的方法可以做到(没有循环)?或者,如果有任何其他收藏我可以用来实现这一目标?

目前我正在循环:

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");
        }
Run Code Online (Sandbox Code Playgroud)

任何帮助深表感谢.谢谢.

Jon*_*eet 5

你基本上需要使用两个字典封装成一个.

目前已经实现格式在这里这里的其他堆栈溢出的问题.