views:

209

answers:

3

What are the differences between

Request.Cookies["MyCookie"].Value
Request.Cookies["MyCookie"].Values

??

A: 

A cookie can have more than one value, the second form returns a NameValueCollection with multiple values.

A good introduction is at http://msdn.microsoft.com/en-us/library/ms178194.aspx

Peter Hahndorf
A: 

Values is a NameValueCollection enabling you to do:

HttpCookie MyCookie = new HttpCookie("MyCookie");
MyCookie.Values["Value1"] = "1";
MyCookie.Values["Value2"] = "2";
MyCookie.Values["Value3"] = "3";
MyCookie.Values["Value4"] = "4";
Response.Cookies.Add(MyCookie);

Where as value allows you to assign the value of the individual cookie like this:

MyCookie.Value = "123";
Tchami
A: 

Cookies["name"].Value is to check if cookie is null or not. Null is the value if the cookie was never set. Otherwise it gives you the cookie value (no subkeys) Cookies["name].Values is a subkey=>value pair of the values stored in the cookie.

Perpetualcoder