|
-
Nov 4th, 2005, 10:30 AM
#1
Thread Starter
Frenzied Member
for each sorted list
Hey,
I have the following code in a class that inherits from SortedList.
VB Code:
Public Sub Dispose() Implements System.IDisposable.Dispose
Dim entry As DictionaryEntry
For Each entry In MyBase.Values
CType(entry.Value, Invoice).Dispose()
Next
End Sub
The for each entry in mybase.value causes the following error
System.InvalidCastException - Specified cast is not valid.
Does anyone know why this is happening? I thought that Values return a dictionary entry.
Thanks,
Don't anthropomorphize computers -- they hate it
-
Nov 4th, 2005, 11:17 AM
#2
Re: for each sorted list
VB Code:
Public Sub Dispose() Implements System.IDisposable.Dispose
For Each Inv as Invoice In MyBase.Values
Inv.Dispose()
Next
End Sub
-
Nov 4th, 2005, 12:46 PM
#3
Thread Starter
Frenzied Member
Re: for each sorted list
Thanks a lot. That worked fine.
I'm wondering though, how come the dictionary entry didn't work when the help file states that with teh for each loop you should use the dictionary entry.
Don't anthropomorphize computers -- they hate it
-
Nov 4th, 2005, 12:48 PM
#4
Re: for each sorted list
i don't know, but possibly because when you inherit the sorted list and put your own objects in the collection, the collection consists of objects of type invoice, and not of type DictionaryEntry
-
Nov 4th, 2005, 01:25 PM
#5
Thread Starter
Frenzied Member
Re: for each sorted list
The collection contains keys and values. But I was iterating through the Values collection which contained objects of type Invoice, so that's why I was getting that error.
Thanks a lot,
Don't anthropomorphize computers -- they hate it
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
|