Re: How are static variables handled in asp.net

From: Scott Allen (bitmask_at_[nospam)
Date: 09/09/04


Date: Thu, 09 Sep 2004 14:57:30 -0400

Hi Frank:

If I have this class in an ASP.NET project:

public class Foo
{
   public static string Bar
   {
       get
       {
          // pull a string from the config file,
          // the database, a resource file, etc..
       }
   }
}

Then I can write:

Foo.Bar

from anywhere else in code to pull back the string I need. Public
static members are global and always available (which can make them a
double edged sword in some scenarios).

VB.NET works the same way, except the keyword is "Shared" instead of
static.

--
Scott
http://www.OdeToCode.com
On Thu, 9 Sep 2004 14:14:10 -0400, "Frank Mamone"
<frankmnospam@canada.com> wrote:
>How do you use static variables?
>
>Is that like global variables that are always available?
>
>-Frank
>
>


Relevant Pages

  • Re: How are static variables handled in asp.net
    ... > public static string Bar ... >>How do you use static variables? ... >>Is that like global variables that are always available? ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: SessionStatic
    ... Static variables live in the application ... Writing an ASP.NET page that makes use of a static class in a Class ... ..wondering, is it possible to make a static field, static per session. ... public static string Variable; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Static variables - saving state!
    ... I think that static variables in ASP.NET will have application scope and ... > public static string firstName; ... > public string LastName; ... > my data classes use static method to access/modify data) .. ...
    (microsoft.public.dotnet.general)