【发布时间】:2010-12-08 09:01:33
【问题描述】:
我想要Dictionary<TKey,TValue> 的所有功能,但我想要Foo<TKey,TValue>。
我应该怎么做?
目前我正在使用
class Foo<TKey,TValue> : Dictionary<TKey, TValue>
{
/*
I'm getting all sorts of errors because I don't know how to
overload the constructors of the parent class.
*/
// overloaded methods and constructors goes here.
Foo<TKey,TValue>():base(){}
Foo<TKey,TValue>(int capacity):base(capacity){}
}
重载父类的构造函数和方法的正确方法是什么?
注意:我认为我误用了“过载”这个词,请更正或建议更正。
【问题讨论】:
-
您说(在对我的回答的评论中)它是装饰器模式的实现。无论它到底用于什么,我怀疑你应该从 Dictionary 继承,甚至不实现 IDictionary。我认为您应该只编写一个常规类,该类包含一个(私有)字典来管理其状态,并具有一些 Add、Remove 和 Get 类型的方法。
标签: c# inheritance collections