我需要创建一个词典,其中键是枚举和整数的一对,值是对象。因此,我想将一对映射到某个对象。
其中一种选项是
public enum SomeEnum
{
value1, value2
}
class Key
{
public SomeEnum;
public int counter;
// Do I have to implement Compare here?
}
Dictionary<SomeEnum, object> _myDictionary;
另一个选择是将枚举和整数转换为某个唯一键。
string key = String.Format("{0}/{1}", enumValue, intValue)
那种方法需要进行字符串解析,需要额外的大量工作。
如何让它更容易呢?