How to retrieve a session value

R

Robert Dufour

In vb I can retrieve a session variable in a web site as follows.
Dim myvar as string
MyVar = Session.Item("VarName").ToString

But In C# there is no item property to use.
How do you retrieve the value of a session item in C#?

Thanks for any help
Bob
 
S

sloan

Session["VarName"]

its called an indexer. where vb.net adds .Item() to get to the indexer.
 
A

Alberto Poblacion

Robert Dufour said:
In vb I can retrieve a session variable in a web site as follows.
Dim myvar as string
MyVar = Session.Item("VarName").ToString

But In C# there is no item property to use.
How do you retrieve the value of a session item in C#?

The equivalent of 'Item' in C# is the class indexer, which you access
using square brackets:

MyVar = Session["VarName"].ToString();
 
A

Andrew Van Slaars

In vb I can retrieve a session variable in a web site as follows.
Dim myvar as string
MyVar = Session.Item("VarName").ToString

But In C# there is no item property to use.
How do you retrieve the value of a session item in C#?

Thanks for any help
Bob

This is an Indexer which is handled by adding the Item property in VB,
these constructs are natively handled in C# and you can access your
session value as follows:
string myVar = Session["VarName"];

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top