Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么我能';t亚类_C#_.net - Fatal编程技术网

C# 为什么我能';t亚类

C# 为什么我能';t亚类,c#,.net,C#,.net,我试图对PersistentDictionary进行子类化,但编译器标记了base(storage\u key)并说: Error 1 'object' does not contain a constructor that takes 1 arguments 这是我的代码: public class MyPersistentDictionary<TKey, TValue> : PersistentDictionary<TKey, TValue> where

我试图对PersistentDictionary进行子类化,但编译器标记了base(storage\u key)并说:

Error   1   'object' does not contain a constructor that takes 1 arguments  
这是我的代码:

public class MyPersistentDictionary<TKey, TValue> : PersistentDictionary<TKey, TValue> where TKey : IComparable<TKey>
    {
        private string storage_key;

        public MyPersistentDictionary(string storage_key):base(storage_key)
        {
            // TODO: Complete member initialization

            this.storage_key = storage_key;
        }
    }
公共类MyPersistentDictionary:PersistentDictionary其中TKey:IComparable
{
私有字符串存储密钥;
公共MyPersistentDictionary(字符串存储密钥):基本(存储密钥)
{
//TODO:完成成员初始化
this.storage\u key=storage\u key;
}
}
我确信PersistentDictionary有一个带一个字符串的构造函数:

您尝试的子类是,因此没有类型可以继承

public sealed partial class PersistentDictionary<TKey, TValue> : 
    IDictionary<TKey, TValue>, IDisposable
    where TKey : IComparable<TKey>
公共密封部分类PersistentDictionary:
IDictionary,IDisposable
其中TKey:i可比较
当然,您可以通过将实例作为参数来解决这个问题

public sealed class PersistentCache<TKey, TValue> : IDictionary<TKey, TValue>
{
    private readonly PersistentDictionary<TKey, TValue> _backingInstance;

    public PersistentCache(PersistentDictionary<TKey, TValue> backingInstance)
    {
        _backingInstance = backingInstance;    
    }

    // implement IDictionary<TKey, TValue>
}
公共密封类PersistentCache:IDictionary
{
私有只读持久字典_backingstance;
公共PersistentCache(PersistentDictionary backingInstance)
{
_后退姿态=后退姿态;
}
//实现IDictionary
}

Error明确指出“object”不包含接受1个参数的构造函数。By object compiler意味着
PersistentDictionary
。那是什么
PersistentDictionary
?你检查过它的文档了吗?你不明白错误信息的哪一部分
PersistentDictionary
没有接受字符串的构造函数。我猜你不需要将
storage\u key
传递给基构造函数,而且
base:(storage\u key)
可以被完全删除。@SriramSakthivel它有这样一个构造函数:你不能继承一个
sealed
类,这正是你想要做的。所以我实现了所有方法?@AVEbrahimi-你不必这么做,但我推荐它。