【发布时间】:2013-04-07 15:07:12
【问题描述】:
我有一个(字符串,对象)字典,对象(类)有一些值,包括由枚举定义的数据类型。我需要一个应该返回字典项值的 GetItemValue 方法。所以返回类型必须是项目对象中定义的类型。
Class Item
{
String Name;
DataValueType DataType;
Object DataValue;
}
private Dictionary<string, Item> ItemList = new Dictionary<string, Item>();
void Main()
{
int value;
ItemList.Add("IntItem", new Item("IntItem", DataValueType.TInt, 123));
value = GetItemValue("IntItem"); // value = 123
}
什么样的解决方案可以克服这个问题?
最好的问候,
【问题讨论】:
标签: c# overloading return-type