When static class member initialized in asp.net?

A

Adam Smith

If I have a utility class, let's say BankAccount and I have a static
class member "double balance" which is initialized in a static
constructor to 0, does this class member exist for the lifetime of my
asp.net application?

Or, is it initialized every time my application is hit on from a web
page?

Thanks in advance.

Adam Smith
 
K

Kevin Spencer

It exists for the lifetime of your application.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
C

Cowboy \(Gregory A. Beamer\)

It depends on how you are setting the member. If you set it each time, even
if it has a value, you are zeroing it each time. If, instead, you are
setting it and allowing it only to be updated when a user changes it, then
it will always have the most current value. By default, it will always hold
the last set value and live for the lifetime of the application.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
J

John Saunders

Cowboy (Gregory A. Beamer) said:
It depends on how you are setting the member. If you set it each time, even
if it has a value, you are zeroing it each time. If, instead, you are
setting it and allowing it only to be updated when a user changes it, then
it will always have the most current value. By default, it will always hold
the last set value and live for the lifetime of the application.

Note that "lifetime of the application" means the lifetime of the AppDomain.
I believe that the value will be reset if you change the web.config, for
instance.

If you need something which will last even over application restarts, you
have to start looking at method which use less-volatile storage, like
Session state with the State Server or SQL Server modes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top