为什么我不能继承

AVE*_*imi -2 .net c#

我试图继承PersistentDictionary,但编译器标记base(storage_key)并说:

Error   1   'object' does not contain a constructor that takes 1 arguments  
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

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;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我相信PersistentDictionary 有一个带有一个字符串的构造函数:https: //managedesent.codeplex.com/SourceControl/latest#EsentCollections/PersistentDictionary.cs

Cha*_*ion 5

类型您要继承的密封所以没有类型可以继承.

public sealed partial class PersistentDictionary<TKey, TValue> : 
    IDictionary<TKey, TValue>, IDisposable
    where TKey : IComparable<TKey>
Run Code Online (Sandbox Code Playgroud)

您当然可以通过将实例作为参数来解决此问题.

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>
}
Run Code Online (Sandbox Code Playgroud)