Reputation: 247
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
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
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
Reputation: 98810
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
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