Re: Q: global variable
From: Scott Allen (scott_at_nospam.odetocode.com)
Date: 02/14/05
- Next message: Juan T. Llibre: "Re: Calendar-control"
- Previous message: Michael Groeger: "Re: Newbie question"
- In reply to: JIM.H.: "Q: global variable"
- Next in thread: Kevin Spencer: "Re: global variable"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 14 Feb 2005 11:28:51 -0500
The life span of a variable is as long as the class instance it is
associated with, and the object will live for as long as you hold a
reference to the object. We typically don't hold a reference to a Page
object since they are only used to process a single request. You could
put an object reference inside the Session, Cache, or Application
objects to keep the object around a bit longer.
You can also mark a field as static (shared in VB.NET) and the field
will be around for the duration of the application. A static field
also means there is only one instance of the field in the entire
application - no matter how many objects get created - so you have to
be sure this is what your design really calls for. Globals like this
are a double edged sword.
-- Scott http://www.OdeToCode.com/blogs/scott/ On Mon, 14 Feb 2005 07:57:05 -0800, JIM.H. <JIMH@discussions.microsoft.com> wrote: >Hello, >What is the life span of public variable defined in the class. >Is there any way to define a global variable in aps.net, and use it in all >the following pages. >Thanks, >Jim.
- Next message: Juan T. Llibre: "Re: Calendar-control"
- Previous message: Michael Groeger: "Re: Newbie question"
- In reply to: JIM.H.: "Q: global variable"
- Next in thread: Kevin Spencer: "Re: global variable"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|