Kevin ...
Technically, you are correct ... if these static members are merely
accessors for private variables. For example:
Public Class MySessionVars
Private Shared _myInt As Integer
Public Shared Property MyInt() As Integer
Get
Return _myInt
End Get
Set(ByVal Value As Integer)
_myInt = Value
End Set
End Property
End ClassThis would store the variables in the heap *and* have the same
values for every user! Not desirable in this situation.
Doing this, however, would be different:
Public Class MySessionVars
Public Shared Property MyInt() As Integer
Get
Return CInt(HttpContext.Current.Session("MyInt"))
End Get
Set(ByVal Value As Integer)
HttpContext.Current.Session("MyInt") = Value
End Set
End Property
End Class
In this case, the static property is merely a wrapper around the current
HttpContext's Session object. Note that this will *crash and burn* if not in
an ASP.NET environment! It is the second method that I think Patrice was
referring to ... and I would agree with Patrice on this practice. It's a
nice layer to abstract the details of the Session, providing flexibility on
storage location of the information, providing intellisense and strong
typing. Many Good Things(tm).
Jason ... you'd add the above class (or something like it) to your project
as a class file in the web solution. From there, you would refer to it like
so:
Dim myInt as Integer = MySessionVars.MyInt
You do not have to create an instance of the class to access static/Shared
members of the type.
"Kevin Spencer" wrote:
Under the hood it uses the user session to store the value.
Static objects are stored in the application heap, not Session.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
"Patrice" <no****@nowhere.com> wrote in message
news:ej**************@TK2MSFTNGP10.phx.gbl... What language are you using ? The keyword is Shared in VB.NET and static
in
C#.
It allows to have a member that is the same for all objects of a class.
Under the hood it uses the user session to store the value.
Having a list is done using an Enumeration (Enum in both languages if I
remember)...
Actually I didn't thought about that either. Saw this suggestion once in
this group...
Patrice
--
"Jason" <ja*************@hotmail.com> a écrit dans le message de
news:11*********************@l41g2000cwc.googlegro ups.com... Never thought about that! But I am unfamiliar with "shared numbers" or
how to get a list of "choices" to be displayed when you are trying to
set a property of a class.