1

I’m trying to store an array in a session variable then use it latter like this:

        Session["sessionVariable"] = searchString;

Now here I’m trying to store the session variable into a string variable.

        String[] sv = Session["sessionVariable"];

When I do I get his error.

Cannot explicitly convert type ‘Object’ to ‘String[]’, An explicit conversion exists, (are you mission a cast?)

I’ve tried various conversions but can’t find the correct one. Can you please help me to find the correct conversion? Thanks.

1
  • searchString is already a string array being passed into the method like this: Commented Oct 31, 2012 at 15:32

1 Answer 1

8

Try this:

Set:

Session["test"] = new string[] { "1", "2", "3" };

Get:

string[] array = Session["test"] as string[];
Sign up to request clarification or add additional context in comments.

Comments

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.