当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.NET list<object> OBJECT.clean()会清空session['OBJECT']的值的问题

ASP.NET list<object> OBJECT.clean()会清空session['OBJECT']的值的问题

2019年05月08日  | 移动技术网IT编程  | 我要评论

sky网络电话下载,盖洛普咨询公司,易锐车品

public partial class 测试 : system.web.ui.page
{
    static list<item> allanswer= new list<item>();

     protected void page_load(object sender, eventargs e)
    {
           //首次加载
        if (ispostback == false)
        {
            //不能使用将allanswer中的元素全部删除,这样也会将session中的值清空
            //allanswer.clean();

           //使用重新定义新的空的对象来实现对allanswer的清空
            allanswer = new list<item>();


            list<item> reallanswer = null;

            try
            {
              //其中session["reallanswer"]来自于另一页面
                reallanswer = (list<item>)session["reallanswer"];
                //printallanwser(reallanswer);
            }
            catch { }
     }
}

如果使用allanswer.clean()函数,则接收的数据session["reallanswer"]将会设置为空;

而使用new list<item>(),则不会。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网