下面實現了ICollection接口的兩個私有屬性:
bool ICollection.IsSynchronized
{
get
{
return false;
}
}
object ICollection.SyncRoot
{
get
{
return this;
}
}
好,現在開始正式實現IDictionary接口。首先是屬性:
bool IDictionary.IsFixedSize
{
get
{
return false;
}
}
bool IDictionary.IsReadOnly
{
get
{
return false;
}
}
//item屬性,本質上就是索引器
object IDictionary.this[object key]
{
get
{
if (ReversibleSortedList<TKey, TValue>.IsCompatibleKey(key))
{
int num1 = this.IndexOfKey((TKey)key);
if (num1 >= 0)
{
return this.values[num1];
}
}
return null;
}
set
{
ReversibleSortedList<TKey, TValue>.VerifyKey (key);
ReversibleSortedList<TKey, TValue>.VerifyValueType(value);
//這裡調用了 IDictionary<TKey, TValue>接口的Item屬性,由於
//還沒有實現它,所以先把這句屏敝掉
//this[(TKey) key] = (TValue)value;
}
}
ICollection IDictionary.Keys
{
get
{
return this.GetKeyListHelper();
}
}
ICollection IDictionary.Values
{
get
{
return this.GetValueListHelper();
}
}