I have a class that inherits a generic dictionary and an inteface
public class MyDictionary: Dictionary<string, IFoo>, IMyDictionary { }
the issue is that consumers of this class are looking for the ‘.Keys’ and ‘.Values’ properties of the interface so i added:
/// <summary> /// /// </summary> ICollection<string> Keys { get; } /// <summary> /// /// </summary> IEnumerable<IFoo> Values { get; }
to the interface.
Now, the implementation needs to have this as well but when i implement these, i get this error:
‘The keyword new is required because it hides property Keys . .. ‘
so what do i need to do. Should i be adding a ‘new’ in front of these get properties?
Another option would be to change the types on the interface to be:
That way the interface is already implemented by the dictionary saving you the trouble of implementing the properties again, and it doesn’t hide or cover the original implementation.