Application["temp"] = 8; should set the value 8 to the key temp.
However, so does Application.Contents["temp"] = 8;
So what are the differences between these two?
Thank you very much.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The Contents property is the default for Application, so when you use:
under the hood, the above code will be changed to call
Application.Contents["temp"] = 8.EDIT: I’ve just used Reflector and as Greg pointed out, the Contents property just returns a reference the current
HttpApplicationStateobject. Not sure if my answer is strictly correct in this case – can someone verify this?EDIT: OK, I found out that when you call
Application["temp"] = 8;orApplication.Contents["temp"] = 8;it actually call HttpApplicationState.Item. Check out this IL: