Overriding Hashtable.Add method

  • Thread starter Thread starter John Cobb
  • Start date Start date
J

John Cobb

MSDN and intellisense shows the Add method of Hashtable being overridable
however when I use this code:

Public Class RAL
Inherits Hashtable

Public Overrides Sub Add(ByVal Key As String, ByVal Value As Object)

End Sub


I get the following 2 errors indicating that Add is Overloadable instead of
Overridable:

sub 'Add' cannot be declared 'Overrides' because it does not override a sub
in a base class.

sub 'Add' shadows an overloadable member declared in the base class
'Hashtable'. If you want to overload the base method, this method must be
declared 'Overloads'.


If possible I need to override this. Any suggestions appreciated.
Thanks,
John
 
Overriding it, means overriding it with the exact same signature method.
You have changed the type of the first parameter - therefore it would be
overloading the method.
 
Hi John,

Parameter "Key" must be of type "Object". Select "(Overrides)" from the
Class dropdown box above the text editor and then "Add" from the other
dropdown, this assures that the method has the same signature.

Nick.
 
Public Overrides Sub Add(ByVal Key As String, ByVal Value As Object)

The Add method of the hashtable has both its arguments as 'Object'. You
cannot change the signature of a method when overriding it - you can only
change its implementation.


Imran.
 
John,
In addition to the other comments:

Rather then attempt to inherit from Hashtable, consider inheriting from
DictionaryBase.

As DictionaryBase wraps a Hashtable allowing you to put type safe methods on
your derived class.

Hope this helps
Jay
 
Hi,

To create a custom collection you inherit from collectionbase.
To create a custom hastable inherit from DictionaryBase.

http://msdn.microsoft.com/library/d...systemcollectionsdictionarybaseclasstopic.asp

Ken
---------------
MSDN and intellisense shows the Add method of Hashtable being overridable
however when I use this code:

Public Class RAL
Inherits Hashtable

Public Overrides Sub Add(ByVal Key As String, ByVal Value As Object)

End Sub


I get the following 2 errors indicating that Add is Overloadable instead of
Overridable:

sub 'Add' cannot be declared 'Overrides' because it does not override a sub
in a base class.

sub 'Add' shadows an overloadable member declared in the base class
'Hashtable'. If you want to overload the base method, this method must be
declared 'Overloads'.


If possible I need to override this. Any suggestions appreciated.
Thanks,
John
 
Thanks for all the quick informative replies. I inherited from
DictionaryBase rather than Hashtable as suggested and I've got a better,
more robust object. Thanks!
 
Back
Top