How to retrieve a session value

  • Thread starter Thread starter Robert Dufour
  • Start date Start date
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
 
Session["VarName"]

its called an indexer. where vb.net adds .Item() to get to the indexer.
 
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();
 
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.
 
Back
Top