2

I have a session variable that is composed by an object that is composed by a list of strings how can I retrieve it´s value? i know that this is possible

 List<string>Session["data"]

but how do I cast session variable if it is an object of lists?

1
  • Session["data"] as List<string> Commented Mar 10, 2017 at 17:41

3 Answers 3

4
var list = Session["data"] as List<string>;
Sign up to request clarification or add additional context in comments.

Comments

3

If what you want to retrieve is a list of strings:

List<String> data = (List<String>) Session["data"];

If what you mean is that you have an Object that contains a list of strings:

ObjectWithListOfStrings data = (ObjectWithListOfStrings)Session["data"];
List<String> retrievedData = data.listOfStringsArray;

Comments

0
var myList =  Session["data"] as List<string>;

or

var myList = (List<string>)Session["data"];

11 Comments

Then don't submit an incomplete answer.
indeed it was a complete one, only thing was formating
Not at all, what you posted wasn't just wrong, it wouldn't even compile.
bad day for me, everywhere i post am getting downvotes :)
Well, if you post bad answers, eventually you get called out on meta
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.