开发者

Is the ASP.NET session data changed?

开发者 https://www.devze.com 2022-12-24 05:41 出处:网络
List<Foo> fooList = Session[\"foo\"] as List<Foo>; fooList.Add(bar); Does the call to Add() change t开发者_运维知识库he data that\'s in the session?Put another way: when I next pull \"fo
List<Foo> fooList = Session["foo"] as List<Foo>;
fooList.Add(bar);

Does the call to Add() change t开发者_运维知识库he 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消