List<Foo> fooList = Session["foo"] as List<Foo>;
fooList.Add(bar);
Does the call to Add() change the data that’s in the session? Put another way: when I next pull “foo” from the Session, will the list contain bar?
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.
Yes the session will be changed as a
List<T>is a reference type. All that thisfooListvariable represents is a pointer to the real object and all thatSession["foo"]represents is also a pointer to the same object. So changingfooListwill affect the real object that the session is also pointing to. The behavior will be different if you store value types in session.