0

I'm trying to convert the following line from VB to C#:

HttpContext.Current.Request.Cookies("MyCookieName")("MyProperty")

I can get the cookie:

HttpCookie httpCookie = HttpContext.Current.Request.Cookies.Get("MyCookieName");

but don't know how to get the property. Is "property" the correct word for what I am trying to get? How do I get this?

Answer:
string property = HttpContext.Current.Request.Cookies["MyCookieName"]["MyProperty"];

Al Lelopath
  • 6,448
  • 13
  • 82
  • 139

1 Answers1

2

HttpContext.Current.Request.Cookies["MyCookieName"]["MyProperty"]

That is the equivalent line in C#. Those are indexers.

Trevor Elliott
  • 11,292
  • 11
  • 63
  • 102
  • This line, with a ; at the end, does not compile. The error is: Only assignment, call, increment, decrement, and new object expressions can be used as a statement. – Al Lelopath Oct 08 '13 at 19:58
  • It's a partial statement. You have to do something with the return value. It doesn't make sense to fetch a value and let it sit in the abyss... Just prepend `string cookieValue = ...;` where `...` is the code above, to the beginning of the line of code to store the result in a variable you can use. – Trevor Elliott Oct 08 '13 at 20:02