如何从字典继承? [英] How do I inherit from Dictionary?

查看:372
本文介绍了如何从字典继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望所有的的功能字典< TKEY的,TValue> ,但我想它作为美孚< TKEY的,TValue>


我应该如何去这样做呢?

目前我使用

I want all the functionality of Dictionary<TKey,TValue> but I want it as Foo<TKey,TValue>.
How should I go about doing this?
Currently I am using

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){}

}

什么是过载构造函数和父类方法的正确方法?

注:我想我已经滥用词'超载',请更正或建议修正

NOTE:I think I have misused the word 'overload' please correct it or suggest correction.

推荐答案

您很接近,你只需要在构造函数中删除类型参数。

You were close, you just need to remove the type parameters from the constructors.

class Foo<TKey,TValue> : Dictionary<TKey, TValue>
{   
    Foo():base(){}
    Foo(int capacity):base(capacity){}
}

要覆盖您可以使用override关键字的方法。

To override a method you can use the override keyword.

这篇关于如何从字典继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆