自己写了个ASP.NET Web服务应用程序,里面有个参数是自己写的一个Dictionary,在运行的时候就报必须在 System.Collections.Generic.Dictionary`2+KeyCollection[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] 上实现默认访问器,因为它继承自 ICollection。
这个问题怎么解决,在线等答案public class MyDictionary<TKey, TValue>
{
public MyDictionary()
{
this.InternalDicktionary = new Dictionary<TKey, TValue>();
}
protected Dictionary<TKey, TValue> InternalDicktionary { get; private set; } public int Count { get { return this.InternalDicktionary.Count; } } public Dictionary<TKey, TValue>.KeyCollection Keys { get { return this.InternalDicktionary.Keys; } } public Dictionary<TKey, TValue>.ValueCollection Values { get { return this.InternalDicktionary.Values; } } public TValue this[TKey key]
{
get { return this.InternalDicktionary[key]; }
set { this.InternalDicktionary[key] = value; }
} public void Add(TKey key, TValue value)
{
this.InternalDicktionary.Add(key, value);
} public void Clear()
{
this.InternalDicktionary.Clear();
} public bool ContainsKey(TKey key)
{
return this.InternalDicktionary.ContainsKey(key);
} public bool ContainsValue(TValue value)
{
return this.InternalDicktionary.ContainsValue(value);
} public Dictionary<TKey, TValue>.Enumerator GetEnumerator()
{
return this.InternalDicktionary.GetEnumerator();
}
public bool Remove(TKey key)
{
return this.InternalDicktionary.Remove(key);
} public bool TryGetValue(TKey key, out TValue value)
{
return this.InternalDicktionary.TryGetValue(key, out value);
}
}
上面是我Dictionary的代码
这个问题怎么解决,在线等答案public class MyDictionary<TKey, TValue>
{
public MyDictionary()
{
this.InternalDicktionary = new Dictionary<TKey, TValue>();
}
protected Dictionary<TKey, TValue> InternalDicktionary { get; private set; } public int Count { get { return this.InternalDicktionary.Count; } } public Dictionary<TKey, TValue>.KeyCollection Keys { get { return this.InternalDicktionary.Keys; } } public Dictionary<TKey, TValue>.ValueCollection Values { get { return this.InternalDicktionary.Values; } } public TValue this[TKey key]
{
get { return this.InternalDicktionary[key]; }
set { this.InternalDicktionary[key] = value; }
} public void Add(TKey key, TValue value)
{
this.InternalDicktionary.Add(key, value);
} public void Clear()
{
this.InternalDicktionary.Clear();
} public bool ContainsKey(TKey key)
{
return this.InternalDicktionary.ContainsKey(key);
} public bool ContainsValue(TValue value)
{
return this.InternalDicktionary.ContainsValue(value);
} public Dictionary<TKey, TValue>.Enumerator GetEnumerator()
{
return this.InternalDicktionary.GetEnumerator();
}
public bool Remove(TKey key)
{
return this.InternalDicktionary.Remove(key);
} public bool TryGetValue(TKey key, out TValue value)
{
return this.InternalDicktionary.TryGetValue(key, out value);
}
}
上面是我Dictionary的代码
直接继承Dictionary
再添加一些自定义方法 不就可以了么~