views:

56

answers:

2

Hi there,

I have a class called CookieMonster, its objective is to simply create a cookie based on 3 parameters passed to it. The cookie name, the cookie name-value pairs and the cookie expiry date.

I have experimented with List(of T) and Array and StringCollection, but I'm unsure which is the best for passing the name-value pairs and providing that information to the class.

Ideally, I'd like to be able to do something like this:

Dim l As New List(Of String)
l.Add("name", "value")
l.Add("name", "value")

Dim c as New CookieMonster()
c.Name = "My New Cookie"
c.Values = l
c.Expires = Date.Now()

Has anyone got any suggestion or code snippets to send me on my way?

Help appreciated and welcomed.

Thanks

+6  A: 

Use a Dictionary, its made for Key Value Pairs.

Dim values As New Dictionary(Of String, String)
values.Add("name1", "value1")
values.Add("name2", "value2")
Lukasz
+1. Good answer, beat me to it.
David Stratton
This is my first time to answer a question and be the first one to answer. lolThanks!
Lukasz
Thanks to both for answers, this worked perfectly. Many thanks to both. +1.
Chris Laythorpe
+1  A: 

Personally, I would use the Dictionary class for this type of scenario.

Example is within the documentation here:

http://msdn.microsoft.com/en-us/library/xfhwa508.aspx

David Stratton