ASP.NET - Session arry with c# - Asked By hiren dhameliya on 12-Apr-10 04:43 AM

Hi , give me some idea ofArrry of Seesion asp.net with c#
Santhosh N replied to hiren dhameliya on 12-Apr-10 04:50 AM
YOu can add anyting to session in asp.net..

Session.Items.Add("arr", ArrayVar);
Anand Malli replied to hiren dhameliya on 12-Apr-10 04:51 AM
hi hiren

As such there are no arrays of Session but As soon as you add different Session it will be all stored in Session class
you can use array list or hashtable or datatable also,what you can do is following

ArrayList arrList  = New ArrayList();
arrList.Insert(0, "values"); 
  
If(arrList.Count != 0)
   Session["myArray"] = arrList;
  
  
// now to use it further or get the from it you would do
ArrayList arList1;
arrList1  = Session["MyArrayList"] as ArrayList() 
  
// to get the values
String strString = myNewArrList[0].ToString();


thxs
vikram malhotra replied to Anand Malli on 12-Apr-10 06:35 AM
arraylist sessionnew = new arraylist();
sessionnew[0]= session["name1"].tostring();
sessionnew[1]= session["address"].tostring();


like this also u can use it
Sasha Kotlo replied to vikram malhotra on 12-Apr-10 09:40 AM
that's incorrect and your code would fail for two reason. First it's ArrayList instead of arraylist and second you're assigning a value to an index that doesn't exist:

sessionnew[0]= session["name1"].tostring();
sessionnew[1]= session["address"].tostring();

particularly these 2 lines of code would fail.