8. Implement Idictionary<tkey, Tvalue> interface
Because the front implementation of the IDictionary interface, now realize Idictionary<tkey, Tvalue> also have no difficulty, divert.
First change the class declaration:
public class ReversibleSortedList<TKey, TValue> :IDictionary<TKey, TValue>
IDictionary, IEnumerable<KeyValuePair<TKey, TValue>>, ICollection,
IEnumerable, ICollection<KeyValuePair<TKey, TValue>>
Then implement Icollection<keyvaluepair<tkey, Tvalue>> interface member:
bool Icollection<keyvaluepair<tkey, TVALUE>> IsReadOnly
{
Get
{
return false;
}
}
void Icollection<keyvaluepair<tkey, Tvalue>> ADD (
Keyvaluepair<tkey, tvalue> KeyValuePair)
{
this. ADD (Keyvaluepair.key, Keyvaluepair.value);
}
BOOL Icollection<keyvaluepair<tkey, TVALUE>> Contains (
Keyvaluepair<tkey, tvalue> KeyValuePair)
{
int num1 = this. Indexofkey (Keyvaluepair.key);
if ((num1 >= 0) && Equalitycomparer<tvalue>. Default.equals (This.values[num1],
keyvaluepair.value))
{
return true;
}
return false;
}
void Icollection<keyvaluepair<tkey, Tvalue>> CopyTo (
Keyvaluepair<tkey, tvalue>[] array, int arrayindex)
{
if (array = = NULL)
{
throw new ArgumentNullException ("array");
}
if (arrayindex < 0) | | (Arrayindex > Array.) Length))
{
throw New ArgumentOutOfRangeException (
"Arrayindex", "Need a non-negative number");
}
if (array. Length-arrayindex) < this. Count)
{
throw new ArgumentException ("Arrayplusofftoosmall");
}
for (int num1 = 0; Num1 < this. Count; num1++)
{
Keyvaluepair<tkey, tvalue> pair1;
Pair1 = new Keyvaluepair<tkey, tvalue> (
THIS.KEYS[NUM1], this.values[num1]);
Array[arrayindex + num1] = Pair1;
}
}
bool Icollection<keyvaluepair<tkey, TVALUE>> Remove (
Keyvaluepair<tkey, tvalue> KeyValuePair)
{
int num1 = this. Indexofkey (Keyvaluepair.key);
if ((num1 >= 0) && Equalitycomparer<tvalue>. Default.equals (
This.values[num1], Keyvaluepair.value)
{
this. RemoveAt (NUM1);
return true;
}
return false;
}