user1919052
user1919052

Reputation: 247

What are the square brackets in ASP.NET means (C#) ex. Session[""];?

I am a beginner in ASP.NET and as an experienced C# Programmer I can't understand the role of the square brackets in ASP.NET.

For example, I ran into those things: Session["masterpage"], ViewState["masterpage"], Application["users"] etc. Are those like array or indxers? I am sorry, I just can't understand it.

Thanks for the helpers :)

Upvotes: 0

Views: 1110

Answers (4)

Henk Holterman
Henk Holterman

Reputation: 273464

Session and Application both are storage objects with an indexer property. What you are seeing is the use of that property.

string myName = (string) Session["Name"];

can be thought of as the use of a hypothetical function:

string myName = (string) Session.GetValueForKey("Name");

The property just offers a more compact and familiar (array-like) notation.

Upvotes: 3

J.Starkl
J.Starkl

Reputation: 2343

This are different ways to persist data in your application

Session-Data is specific to a user

Application-Data is accessable from each user

Viewstate-Data is also user specific and is stored in the current aspx-page

Find more infos here: http://msdn.microsoft.com/en-us/magazine/cc300437.aspx

Upvotes: 1

Soner Gönül
Soner Gönül

Reputation: 98810

From ASP.NET Session State

ASP.NET session state is enabled by default for all ASP.NET applications. ASP.NET session-state variables are easily set and retrieved using the Session property, which stores session variable values as a collection indexed by name*.

Upvotes: 2

Michel Keijzers
Michel Keijzers

Reputation: 15367

In C# you can use indexers ... you can then define a function to 'convert' these strings (or any objects) into an integer index to get that item of the array.

The main functionality of indexers is to be able to use more meaningfull names instead of (integer) indices to retrieve a single array item.

Upvotes: 1

Related Questions