I have a class that extends SortedList. I can use the many of the SortedList methods in my class like Add() and Remove() but for some reason it doesn’t like it when I try to use GetKey(). Can anyone tell me why this might be happening?
public class SymbolTableImplementation : SortedList<string, SymbolTableEntry>, SymbolTable
{
public SymbolTableEntry Enter(string name)
{
SymbolTableEntry entry = SymbolTableFactory.CreateSymbolTableEntry(name, this);
Add(name, entry); // This is OK
return entry;
}
// Look up an existing symbol table entry. Null if it does not exist.
public SymbolTableEntry Lookup(string name)
{
return GetKey(name); // Doesn't exist in current context
}
}
GetKeyis defined inSortedList, which is actually a completely separate class fromSortedList<TKey, TValue>. You also have a mistake in your original code; if you were actually usingGetKey/SortedList, this would not have compiled:Instead, just use the
IDictionaryindexer: