如何实现词典有两把钥匙? [英] How to implement a Dictionary with two keys?

查看:123
本文介绍了如何实现词典有两把钥匙?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用C#,我想找到一种方法如何实现像一本字典,它取决于两个关键对象。

Using C#, I'd like to find a way how to implement something like a dictionary that depends on two key objects.

我有一个对象和一个字符串。为了这两个值我要分配一个双精度值。所以,我应该用什么样的结构?或者,我怎么能实现这样的结构?

I have an object and a string. To this two values I want to assign one double value. So what structure should I use? Or how can I implement such a structure?

推荐答案

您可以有它汇集了两个属性的自定义类,覆盖的 GetHash code 的方法就可以了,然后有一个的IDictionary< CustomClass,双>

You could have a custom class which aggregates the two properties, override the GetHashCode method on it and then have a IDictionary<CustomClass, double>.

这篇关于如何实现词典有两把钥匙?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆