I have a string array like this
string[] BranchIds = {"1","2","3"};
and then stored it into a session
Session["BranchIds"] = BranchIds;
Now how can I retrieve this values as integers from session?
I have a string array like this
string[] BranchIds = {"1","2","3"};
and then stored it into a session
Session["BranchIds"] = BranchIds;
Now how can I retrieve this values as integers from session?
You can do this:
string[] branchIds = (string[])Session["BranchIds"]
Then you can iterate array for it's values.
You first get the values as an array of strings:
var strArr = (string[])Session["BranchIds"];
Then you can convert it to an array of int:
var intArr = Array.ConvertAll(strArr, int.Parse);
The 2 Question are not related, so retrieve from session is same as you add to session so if say:
string [] BranchIds = (string[])Session["BranchIds"]
then you you retrieved the array from session.
to parse a string value to integer you can use:
Int32.Parse()
so for example to parse first id:
int id = Int32.Parse(BranchIds[0]);
or you can do a for loop and convert all of them to integers, or you can store to session in integer from beginning if needed.