C# 双向字典?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1227683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 13:56:29  来源:igfitidea点击:

Bi-directional dictionary?

c#data-structures

提问by Svish

I have two sets of objects where in some cases the first set will be used as keys for the other set, and in other cases the second set will be used as keys for the first. In addition there must be no duplicates in either list.

我有两组对象,在某些情况下,第一组将用作另一组的键,而在其他情况下,第二组将用作第一组的键。此外,任何一个列表中都不能有重复项。

What would be a good data-structure to use for this? Should I use two Dictionaries for this or are there smarter ways?

什么是用于此目的的良好数据结构?我应该为此使用两个词典还是有更聪明的方法?

采纳答案by Dinah

Someone with better knowledge of data structures could probably give better advice, but personally, I'd use 2 dictionaries for ease of use. You could do the same with 1 dictionary but access time would increase.

对数据结构有更深入了解的人可能会提供更好的建议,但就个人而言,我会使用 2 部词典以方便使用。您可以对 1 个字典执行相同操作,但访问时间会增加。

Edit: crap, I was just in the process of writing up some code how I would do it and I saw that Falaina posted this which is the same idea that I was doing only much better: Getting key of value of a generic Dictionary?

编辑:废话,我只是在写一些代码的过程中我会怎么做,我看到 Falaina 发布了这个,这与我做得更好的想法相同:获取通用字典的价值键?