【发布时间】:2013-09-11 17:09:07
【问题描述】:
我有这个简单的通用代码示例:
public class Box<E> where E : BoxProperties{
}
public class BoxProperties{
}
public class BlueBox : Box<BlueBox.BlueProperties >{
public class BlueProperties : Properties{
}
}
public class RedBox : Box<RedBox.RedProperties >{
public class RedProperties : Properties{
}
}
我需要创建一个可以将 RedBox 和 BlueBox 存储为值的字典。 有什么帮助吗?
【问题讨论】:
-
BlueProperties和RedProperties继承自 Properties,因此只需创建一个Dictionary<TKey, Properties>。 -
@AlessandroD'Andria 这不会帮助他存储
RedBox或BlueBox对象。RedBox和BlueBox都不是继承自Properties。 -
@cdhowie 你说得对,我不明白这个问题。
标签: c# templates generics inheritance