473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Static vs Application in Global.aspx.cs

Does anyone know the difference between defining a static variable
inside Global vs using an Application variable?

For example

Using a static int variable.

public class Global : System.Web.HttpApplication
{
public static int MaxValue

protected void Application_Start(Object sender, EventArgs e)
{
MaxValue = 100;
}
}

referring to this in your other classes using Global.MaxValue
vs

public class Global : System.Web.HttpApplication
{
public static int MaxValue

protected void Application_Start(Object sender, EventArgs e)
{
Application["MaxValue"] = 100;
}
}

referring to this in your other classes using
(int)Application["MaxValue"]
Thanks in advance

Aug 16 '06 #1
3 1776
I think the end result is going to be the same.

Using an actual variable, you get type safety, where as in Application you
have to cast everything. If you use a static variable, depending on what
class it is defined, you may need to reference that DLL, whereas with
Application, that is a property in Page and UserControl.

If you know your variables ahead of time, and their names aren't going to be
generated by your application, having static variables (or properties) will
make your code easier to read, easier to use those variables, and less
likely that you will have to deal with type issues.

<rw*****@yahoo.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Does anyone know the difference between defining a static variable
inside Global vs using an Application variable?

For example

Using a static int variable.

public class Global : System.Web.HttpApplication
{
public static int MaxValue

protected void Application_Start(Object sender, EventArgs e)
{
MaxValue = 100;
}
}

referring to this in your other classes using Global.MaxValue
vs

public class Global : System.Web.HttpApplication
{
public static int MaxValue

protected void Application_Start(Object sender, EventArgs e)
{
Application["MaxValue"] = 100;
}
}

referring to this in your other classes using
(int)Application["MaxValue"]
Thanks in advance

Aug 16 '06 #2
One is globally attached to the Application object as an object and the
other is typed properly. That is about it.

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

*************************************************
Think outside the box!
*************************************************
<rw*****@yahoo.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Does anyone know the difference between defining a static variable
inside Global vs using an Application variable?

For example

Using a static int variable.

public class Global : System.Web.HttpApplication
{
public static int MaxValue

protected void Application_Start(Object sender, EventArgs e)
{
MaxValue = 100;
}
}

referring to this in your other classes using Global.MaxValue
vs

public class Global : System.Web.HttpApplication
{
public static int MaxValue

protected void Application_Start(Object sender, EventArgs e)
{
Application["MaxValue"] = 100;
}
}

referring to this in your other classes using
(int)Application["MaxValue"]
Thanks in advance

Aug 16 '06 #3
Thanks all. This is basically what I thought. Cowboy glad to see your
active. I don't know if you recall but I enjoyed discussing the
differences between C# and VB.Net on a previous post that I started a
couple of years ago.

This is a side note, but are you seeing .Net Web Services returning
typed datasets out in the real world. I've done some research and it
seems that the tool sets out there on the java world are not fully
supporting typed datasets (using the xsd to convert the dataset to the
equivalent java class). I haven't done Java since 1997 and haven't
setup a Linux/java environment to consume a .Net web service returning
a dataset.

I am assuming that Microsoft wants typed datasets to be a standard.
However the java world is somewhat reluctant to fully support it. If
they do, and a large number websites are done in .Net returning typed
datasets, the will be forced to support Microsoft's tweaking of
datasets in the future. And because I want it easy for .Net and java
developers to consume my web services, I am returning, simple class
(structures) arrays.

Wondering what your thoughts are?

Cowboy (Gregory A. Beamer) wrote:
One is globally attached to the Application object as an object and the
other is typed properly. That is about it.

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

*************************************************
Think outside the box!
*************************************************
<rw*****@yahoo.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Does anyone know the difference between defining a static variable
inside Global vs using an Application variable?

For example

Using a static int variable.

public class Global : System.Web.HttpApplication
{
public static int MaxValue

protected void Application_Start(Object sender, EventArgs e)
{
MaxValue = 100;
}
}

referring to this in your other classes using Global.MaxValue
vs

public class Global : System.Web.HttpApplication
{
public static int MaxValue

protected void Application_Start(Object sender, EventArgs e)
{
Application["MaxValue"] = 100;
}
}

referring to this in your other classes using
(int)Application["MaxValue"]
Thanks in advance
Aug 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Sahil Malik [MVP] | last post by:
So here's a rather simple question. Say in an ASP.NET application, I wish to share common constants as static variables in global.asax (I know there's web.config bla bla .. but lets just say I...
3
by: Faisal | last post by:
Hi. I'm in the process of moving an application from ASP to ASP.NET, & I'm writing in VB, using VS.NET. I'm new to the .NET framework & have a basic question regarding static objects defined in...
8
by: Simone Chiaretta | last post by:
I've a very strange behaveour related to a website we built: from times to times, something should happen on the server, and all static variables inside the web application, both defined inside aspx...
25
by: Sahil Malik [MVP] | last post by:
So here's a rather simple question. Say in an ASP.NET application, I wish to share common constants as static variables in global.asax (I know there's web.config bla bla .. but lets just say I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.