我在global.asax.cs类写 protected void Session_Start(Object sender, EventArgs e)
        {
            try
            {
                int a[]={1,2};
                
                Session["c"] = a;
            }
            catch
            {
                throw;
            }
        }
在页面调用时 int[] a = (int[])Session["c"];
            TextBox1.Text = a[0].ToString();
结果报错,说未将对象引用设置到对象的实例。
为什么?

解决方案 »

  1.   

        protected void Button1_Click(object sender, EventArgs e)
        {
            int[] a ={ 1,2,5};
            Session["a"] = a;        if (Session["a"] != null)
            {
                int[] b = (int[])Session["a"];
                for (int i = 0; i < b.Length; i++)
                    Response.Write(b[i].ToString() +"<br />");
            }
        }