You can do it, but where you went wrong is that an array of objects expects the index to be an int. You have to search the array _items yourself and return the right object.
Maybe something like this is a good start.
Code:
public class MyDictionary<TKey, TValue> : MyIDictionary<TKey, TValue>
{
private KeyValuePair<TKey, TValue>[] _items;
private int index = 0;
public MyDictionary()
{
_items = new KeyValuePair<TKey, TValue>[10];
}
public TValue this[TKey key]
{
get
{
foreach (KeyValuePair<TKey, TValue> kvp in _items)
{
if (key.Equals(kvp.Key))
return kvp.Value;
}
throw new System.ArgumentOutOfRangeException(key.ToString(), "not in dictionary");
}
set
{
_items[index] = new KeyValuePair<TKey, TValue>(key, value);
++index;
}
}
}
Nothing was tested.