|
-
Jul 22nd, 2004, 10:49 AM
#1
Enumerating Dictionary Objects
I am just tring to enumerate my collection class that inherits from DictionaryBase, and i just cant seem to get it working right
I have a products class containing objects of type product
when I do
for each Prod in Prods
next
where the default property in Prods is Item which returns an object of type Prod
it says there is an invalid cast...
any ideas how I can get this to work?
-
Jul 22nd, 2004, 10:54 AM
#2
The enumerator for DictionaryBase actually returns DictionaryEntry objects, which contain the key/value pair. What I normally do is put this in my collection class...
VB Code:
Public Shadows Function GetEnumerator() As IEnumerator
Return Dictionary.Values.GetEnumerator
End Function
And then your code should work.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jul 22nd, 2004, 11:21 AM
#3
using that do I not use for each in the form code then?
-
Jul 22nd, 2004, 11:54 AM
#4
never mind, got it to work. Thanks.
-
Dec 7th, 2006, 04:46 AM
#5
Hyperactive Member
Re: Enumerating Dictionary Objects
Hi Kleinma,
I'm having a similar problem. Can you tell me how you fixed it?
Thx.
Last edited by BShadow; Dec 7th, 2006 at 05:05 AM.
"Experience is something you don't get until just after you need it."
-
Dec 7th, 2006, 10:13 AM
#6
Re: Enumerating Dictionary Objects
Hmmm it was 2 years ago, and honestly I can't remember exactly what I did. If you post your code I will try to fix it though.
-
Dec 7th, 2006, 10:27 AM
#7
Hyperactive Member
Re: Enumerating Dictionary Objects
"Experience is something you don't get until just after you need 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
|