I have a interface that can implement various collections and data types, it works fine with some collection but the dictionary is giving me issues, I’m guessing because the Dictionary is a little different and has key value pairs?
public interface IStructure
{
void InsertRun<T> (T item);
ICollection RetrieveSortedListRun<T>();
T RetrieveItemRun<T>(T item);
}
class DictionaryRun : IStructure
{
IDictionary<int, object> dictionary;
public DictionaryRun()
{
dictionary = new Dictionary<int, object>();
}
public void InsertRun<T>(T item)
{
dictionary.Add(dictionary.Count + 1, item);
}
public ICollection RetrieveSortedListRun<T>()
{
return dictionary;
}
public T RetrieveItemRun<T>(T item)
{
return item;
}
}
IDictionary<TKey, TValue>does not implementICollection, it implementsICollection<KeyValuePair<TKey, TValue>>.As is, if you changed your dictionary to be a
IDictionaryyour code would compile.However, it seems to me that your overall design of the interface and the object could be reworked.