我有一种特殊的字典。我不确定如何确切地做到这一点,但是我正在寻找使get方法成为虚拟方法,而不是set方法:
public TValue this[TKey key]
{
get { ... }
set { ... }
}
有可能,如果可以的话,正确的组合是什么?
最佳答案
您不能直接这样做-您需要添加一个单独的方法:
protected virtual TValue GetValue(TKey key) { ...}
public TValue this[TKey key]
{
get { return GetValue(key); }
set { ... }
}