双射词典/地图在C#

问题描述:

是否有有效的存储键/值对,其中键和值是不同的,因此,双射映射(即TryGetValue / TryGetKey)是可能的双射字典in.NET?天真的方法是有两个内置的字典:一个键值和值密钥字典,但这不是有效的在内存方面

Is there a bijective dictionary in.NET that efficiently stores Key/Values pairs, where both keys and values are distinct, so a bijective mapping (i.e. TryGetValue/TryGetKey) is possible? The naive approach would be to have two internal dictionaries: A key-value and a value-key dictionary, but this is not efficient in terms of memory.

我不相信有一在.NET。根据不同的键/值类型,我不知道该使用两个字典有可能造成的的多大的效率损失:这是我会做什么,直到我看到了问题的基础上,事实上,它是简单的。

I don't believe there's one in .NET. Depending on the key/value types, I'm not sure that using two dictionaries is likely to cause that much of an efficiency loss: it's what I'd do until I saw a problem, based on the fact that it's simple.

在事实上,它的非常的简单,因为我已经在另一个堆栈溢出的答案付诸实施。我去看看我能找到它...

In fact, it's very simple as I've already implemented it in another Stack Overflow answer. I'll see if I can find it...

编辑:我发现了两个:

  • One of mine
  • Another based on mine, but more fully developed with Remove etc.