Ramasamy Kanna
Ramasamy Kanna

Reputation: 792

how to casting session to list?

First I am assigning a list values to Session like this

HttpContext.Session[cont + "schedule"] = objupload.schedule;

It is saving fine,

After that I want to retrieve the values from the session, then I am using this

objupload.schedule=HttpContext.Session[cont + "schedule"];

When I am using this, I am getting this error

'Error Cannot implicitly convert type 'object' to 'System.Collections.Generic.List'

My question is, ia casting possible for list conversion and is there any other solution for retrieving a value from the session?

Upvotes: 1

Views: 3532

Answers (2)

Qasim Bataineh
Qasim Bataineh

Reputation: 707

You can cast an object from a session by:

        if (HttpContext.Session[cont + "schedule"] != null)
        {
            objupload.schedule = HttpContext.Session["Current"] as (List<SomeClass>);
        }

Upvotes: 0

Yasser Shaikh
Yasser Shaikh

Reputation: 47774

You can typecast it, something like this should work.

objupload.schedule = (List<SomeClass>)HttpContext.Session[cont + "schedule"];

here replace SomeClass with your class.

Hope this helps.

Upvotes: 2

Related Questions