【发布时间】:2010-10-20 09:06:11
【问题描述】:
我需要安排一种字典,其中键是一对 enum 和 int 价值是对象。所以我想将一对映射到某个对象。
一个选项是
public enum SomeEnum
{
value1, value2
}
class Key
{
public SomeEnum;
public int counter;
// Do I have to implement Compare here?
}
Dictionary<SomeEnum, object> _myDictionary;
另一种选择是将 enum 和 int 转换为某个唯一键。
string key = String.Format("{0}/{1}", enumValue, intValue)
这种方法需要进行字符串解析,需要做很多额外的工作。
如何轻松搞定?
【问题讨论】:
-
你使用的是什么版本的 C#?
-
Visual Studio 2008 所以我认为它是 3.5
标签: c# .net generics dictionary