|
-
Mar 24th, 2002, 07:04 AM
#1
Thread Starter
New Member
Overriding Function in VB.NET - plz help!
i tried overriding the clear() subroutine for system.collection.collectionbase class
it gives me an error message :-
An unhandled exception of type 'System.TypeLoadException' occurred in Structure Demo.exe
Additional information: Declaration referenced in a method implementation can not be a final method. Type: Structure_Demo.CustomerCollection. Assembly: Clear.
i tried overriding other functions for other classes and it work. but i dont understand why it doesnt work for the CollectionBase class
does that mean there are problems with this specific class?
can anyone plz help??
Jeffrey
-
Mar 24th, 2002, 10:51 AM
#2
Addicted Member
try calling the MyBase.Clear at the end of your override there may be some nessesary code that ms uses in that method the documentation says you should always pass it back to the correct event/method after override
Magiaus
Visual Basic 6.0 SP5
Visual C++ 6.0 SP5
The only sovereign you can allow to rule you is reason.
-
Mar 24th, 2002, 11:27 AM
#3
Thread Starter
New Member
it says the sub clear() is not overridable in the definition for the collectionbase class
but if i dont declare the Clear() as overrides on my inherited class, it underlines the Clear() in blue. it says that :-
sub 'Clear' shadows an overridable method from the base class. in this case it should be the collectionBase class.
im confused here...
anyone help?
Jeffrey
-
Mar 28th, 2002, 09:42 AM
#4
New Member
If you do not put the Overrides keywork in the derived class, the function is assumed to shadow the origional function.
A shadow function is a function in the derived class that has the same name as a function in the base class but is NOT intended to override the base class function.
-
Mar 28th, 2002, 10:25 AM
#5
Frenzied Member
If a method is not overidable, then you cant override it. You can either use a different name for your clear method, or change the method signiture in you class.
Hope that helps
Dont gain the world and lose your soul
-
Mar 28th, 2002, 12:50 PM
#6
Thread Starter
New Member
thx for the replies...
i'ved solved the problem by using the Shadows keyword in the derived class.
Visual Basic 6.0
Visual Basic .NET
C/C++
JAVA
-
Mar 28th, 2002, 01:02 PM
#7
Frenzied Member
please elaberate
post the override with the shadows i am curius to see it
Magiaus
If I helped give me some points.
-
Mar 28th, 2002, 01:34 PM
#8
Thread Starter
New Member
Public Class CustomerCollection
Inherits System.Collections.CollectionBase
'members...
Private _emailHashtable As New Hashtable()
'EmailHashtable - return the e-mail hashtable...
Public ReadOnly Property EmailHashtable() As Hashtable
Get
Return _emailHashtable
End Get
End Property
'Item - return a customer given an index...
Default Public Property Item(ByVal index As Integer) As Customer
Get
Return Me.List.Item(index)
End Get
Set(ByVal Value As Customer)
Me.List.Item(index) = Value
End Set
End Property
'Overloaded default property
'Item - return email hashtable
Default ReadOnly Property Item(ByVal email As String) As Customer
Get
email = email.ToLower
Return EmailHashtable.Item(email)
End Get
End Property
'add customer...
Public Sub Add(ByVal newCustomer As Customer)
Me.List.Add(newCustomer)
'add to the hashtable...
Dim useEmail As String
useEmail = newCustomer.Email.ToLower
EmailHashtable.Add(useEmail, newCustomer)
End Sub
'Remove - delete a customer...
Public Sub Remove(ByVal removeCustomer As Customer)
'remove from list...
Me.List.Remove(removeCustomer)
'remove from hashtable...
Dim useEmail As String
useEmail = removeCustomer.Email.ToLower
EmailHashtable.Remove(useEmail)
End Sub
'Clear - provide a new implementation of clear...
Public Shadows Sub Clear()
'get collectionbase to clear...
MyBase.Clear()
'clear hashtable...
EmailHashtable.Clear()
End Sub
'RemoveAt - remove an item by index...
Public Shadows Sub RemoveAt(ByVal index As Integer)
Remove(Item(index))
End Sub
End Class
Visual Basic 6.0
Visual Basic .NET
C/C++
JAVA
-
Mar 28th, 2002, 01:44 PM
#9
Frenzied Member
Magiaus
If I helped give me some points.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|