Overriding Hashtable.Add method

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
 
M

Marina

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.
 
N

Nak

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.
 
I

Imran Koradia

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.
 
J

Jay B. Harlow [MVP - Outlook]

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
 
K

Ken Tucker [MVP]

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
 
J

John Cobb

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Why Overloads needed 12
Error 1
How would you translate this? 3
Overloads vs Shadows 2
strange inheritance proble 8
Overriding 5
Overriding my method 4
Problem with typed dataset 8

Top