如何使用复合键的字典? [英] How to use compound key for dictionary?
本文介绍了如何使用复合键的字典?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要安排排序词典,其中的关键是一对枚举和INT的 和值对象。所以,我要地图一对一些对象。
I need to arrange sort of dictionary where the key would be a pair of enum and int and value is object. So I want to map a pair to some object.
一种选择是
public enum SomeEnum
{
value1, value2
}
class Key
{
public SomeEnum;
public int counter;
// Do I have to implement Compare here?
}
Dictionary<SomeEnum, object> _myDictionary;
另一种办法是转换枚举和int到一些独特的密钥。
Another option would convert enum and int to some unique key.
string key = String.Format("{0}/{1}", enumValue, intValue)
这方法要求字符串解析,很多额外的工作。
That approach requires string parsing, a lot of extra work.
如何使它容易吗?
推荐答案
我会用类似的东西去
public enum SomeEnum
{
value1, value2
}
public struct Key
{
public SomeEnum;
public int counter;
}
Dictionary<Key, object>
我认为这将使它?
I think that would make it?
这篇关于如何使用复合键的字典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文