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
?
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
?
Yes the session will be changed as a List<T>
is a reference type. All that this fooList
variable represents is a pointer to the real object and all that Session["foo"]
represents is also a pointer to the same object. So changing fooList
will affect the real object that the session is also pointing to. The behavior will be different if you store value types in session.