473,698 Members | 2,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Overriding Hashtable.Add method

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
Nov 21 '05 #1
6 5408
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.

"John Cobb" <jo*******@acxi om.com> wrote in message
news:OX******** ******@TK2MSFTN GP15.phx.gbl...
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

Nov 21 '05 #2
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.

"John Cobb" <jo*******@acxi om.com> wrote in message
news:OX******** ******@TK2MSFTN GP15.phx.gbl...
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

Nov 21 '05 #3
> 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.
Nov 21 '05 #4
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

"John Cobb" <jo*******@acxi om.com> wrote in message
news:OX******** ******@TK2MSFTN GP15.phx.gbl...
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

Nov 21 '05 #5
Hi,

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

http://msdn.microsoft.com/library/de...classtopic.asp

Ken
---------------
"John Cobb" <jo*******@acxi om.com> wrote in message
news:OX******** ******@TK2MSFTN GP15.phx.gbl...
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

Nov 21 '05 #6
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!

"John Cobb" <jo*******@acxi om.com> wrote in message
news:OX******** ******@TK2MSFTN GP15.phx.gbl...
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

Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2217
by: Rafael Veronezi | last post by:
I have some questions about override in inheritance, and virtual members. I know that you can you override a method by two ways in C#, one, is overriding with the new keyword, like: public new bool Equals(object obj) {} Another is using the override keyword, like: public override bool Equals(object obj) {}
4
6273
by: David Hoffer | last post by:
Why is it that when I override Equals I get the following warning? What am I suppose to do? warning CS0659: 'XXX.MyObject' overrides Object.Equals(object o) but does not override Object.GetHashCode()
33
3312
by: Ken | last post by:
I have a C# Program where multiple threads will operate on a same Hashtable. This Hashtable is synchronized by using Hashtable.Synchronized(myHashtable) method, so no further Lock statements are used before adding, removing or iterating the Hashtable. The program runs in a high workload environment. After running a few days, now it suddenly catchs this Exception when inserting a pair of key and object, stacktrace =...
17
2913
by: Bob Weiner | last post by:
What is the purpose of hiding intead of overriding a method? I have googled the question but haven't found anything that makes any sense of it. In the code below, the only difference is that when the Poodle is upcast to the Dog (in its wildest dreams) it then says "bow wow" where the bernard always says "woof" (see code). Basically, it appears that I'm hiding the poodle's speak method from everything except the poodle. Why would I...
3
3328
by: pagates | last post by:
Hello Gurus, I have a listview, and I only want to add unique items. The problem is, my code is blowing by my "Contains" statement, adding the item, and then hitting my Compare code in the class that I have set up for my ListViewItemSorter. Here is my (simplified) code: // Note: there are accessor properties, constructors, etc // that I have omitted here for clarity
7
36807
by: ad | last post by:
I have a hash table like: Hashtable myHT = new Hashtable(); myHT.Add("First", "Hello"); myHT.Add("Second", "World"); myHT.Add("Third", "!"); We can use key to find value like: myHT -> "Hello" But how can use use value to find key?
12
6738
by: Rubbrecht Philippe | last post by:
Hi there, According to documentation I read the ArrayList.IndexOf method uses the Object.Equals method to loop through the items in its list and locate the first index of an item that returns True. Therefore, overriding the Equals method in the class definition of the items I put in the ArrayList should make the IndexOf method use my version of the Equals method?!
18
4736
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the class where only the "searched" property has a value. I expected to get the index into the arraylist where I could then get the entire class instance. However, the 'indexof' is never calling my overloaded, overrides Equals method. Here is the...
10
105187
by: r035198x | last post by:
The Object class has five non final methods namely equals, hashCode, toString, clone, and finalize. These were designed to be overridden according to specific general contracts. Other classes that make use of these methods assume that the methods obey these contracts so it is necessary to ensure that if your classes override these methods, they do so correctly. In this article I'll take a look at the equals and hashCode methods. ...
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8611
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8904
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8876
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7741
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.