473,473 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Best place for global variables in ASP.Net apps?

You gather I'm new to C#...

I'm used to declaring global variables and application constants in a common
script file in ASP apps but now in I'm sure things are done differently.

The sort of thing I'm talking about is easy to remember names for numerics
values that have a particular significance in the application
e.g.
When I was using JScript.

var PROD_BISCUIT = 1;
VAR PROD_CAKE = 2;
var PROD_SANDWICH = 3;
etc.

or

var DIR_INBOUND = 1;
var DIR_OUTBOUND = 2;
So now in C# if I was writing an SQL query string anywhere in the app I
could use:

string sql = "SELECT * FROM Luncbox AS L WHERE L.Direction=" + DIR_INBOUND +
" AND L.SnackTypeID = " + PROD_BISCUIT

I can think of a few places where I could do something similar in C# but
what is the best way?
I'd like to be able to use something visually brief and simple (not
Application["PROD_BISCUIT "] for instance).
What do you experience guys do, and why?

Also, is there a commonly used formatting convention for these things?
I've seen things like all caps or starting with an underscore, like I've
generally seen public and private variables differentiated with inital letter
case like:

public string MyString; (or a get())
private string myString;
--
Thanks

Grant Ord
Nov 16 '05 #1
4 9251
Define constants in a C# class:

class WSEventing
{
public const string Namespace = http://blahblah;
}
--
Mickey Williams
Author, "Visual C# .NET Core Ref", MS Press
www.neudesic.com
www.servergeek.com

"Grant Ord" <gr*******@nospam.nospam> wrote in message
news:11**********************************@microsof t.com...
You gather I'm new to C#...

I'm used to declaring global variables and application constants in a common script file in ASP apps but now in I'm sure things are done differently.

The sort of thing I'm talking about is easy to remember names for numerics
values that have a particular significance in the application
e.g.
When I was using JScript.

var PROD_BISCUIT = 1;
VAR PROD_CAKE = 2;
var PROD_SANDWICH = 3;
etc.

or

var DIR_INBOUND = 1;
var DIR_OUTBOUND = 2;
So now in C# if I was writing an SQL query string anywhere in the app I
could use:

string sql = "SELECT * FROM Luncbox AS L WHERE L.Direction=" + DIR_INBOUND + " AND L.SnackTypeID = " + PROD_BISCUIT

I can think of a few places where I could do something similar in C# but
what is the best way?
I'd like to be able to use something visually brief and simple (not
Application["PROD_BISCUIT "] for instance).
What do you experience guys do, and why?

Also, is there a commonly used formatting convention for these things?
I've seen things like all caps or starting with an underscore, like I've
generally seen public and private variables differentiated with inital letter case like:

public string MyString; (or a get())
private string myString;
--
Thanks

Grant Ord

Nov 16 '05 #2
Hi,

What you were declaring was constants , not variable , if this is your ony
requirement then you can create a class with the constans inside:

class SystemConstants
{
public const int PROD_BISCUIT = 1;
}

If they are variable you could do a similar thing too.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Grant Ord" <gr*******@nospam.nospam> wrote in message
news:11**********************************@microsof t.com...
You gather I'm new to C#...

I'm used to declaring global variables and application constants in a common script file in ASP apps but now in I'm sure things are done differently.

The sort of thing I'm talking about is easy to remember names for numerics
values that have a particular significance in the application
e.g.
When I was using JScript.

var PROD_BISCUIT = 1;
VAR PROD_CAKE = 2;
var PROD_SANDWICH = 3;
etc.

or

var DIR_INBOUND = 1;
var DIR_OUTBOUND = 2;
So now in C# if I was writing an SQL query string anywhere in the app I
could use:

string sql = "SELECT * FROM Luncbox AS L WHERE L.Direction=" + DIR_INBOUND + " AND L.SnackTypeID = " + PROD_BISCUIT

I can think of a few places where I could do something similar in C# but
what is the best way?
I'd like to be able to use something visually brief and simple (not
Application["PROD_BISCUIT "] for instance).
What do you experience guys do, and why?

Also, is there a commonly used formatting convention for these things?
I've seen things like all caps or starting with an underscore, like I've
generally seen public and private variables differentiated with inital letter case like:

public string MyString; (or a get())
private string myString;
--
Thanks

Grant Ord

Nov 16 '05 #3
Hi Grant

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #4
I was sure I'd clicked
Yes for Did this post answer the question?

The reponses were very helpful - thanks.

"Kevin Yu [MSFT]" wrote:
Hi Grant

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #5

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

Similar topics

1
by: mark4asp | last post by:
What are the best methods for using global constants and variables? I've noticed that many people put all global constants in a file and include that file on every page. This is the best way of...
15
by: Relaxin | last post by:
How can I have a variable that has been initialized and set to a value within one source file (*.cs), and have access to that same variable in other files of the same project? NOTE: That...
7
by: Michael | last post by:
Hi newsgroup, as the subject indicates I am looking for an advice using global variables. I am not if this problem is more about style then C. If its wrong in thi group, sorry. So I have a...
25
by: Daniel Bass | last post by:
how do i declare a global variable in c#.net? it's like it want's everything in classes... there are times when globals are good, like having constants in a program which apply to several...
6
by: Andrea Williams | last post by:
Where is the best place to put global variables. In traditional ASP I used to put all of them into an include file and include it in every page. Will the Global.aspx.cs do that same thing? ...
5
by: Fred Nelson | last post by:
Hi: I'm a relative newby so hopefully this is a simple question! I have found that I can create global variables easily on a web page by placing the dim statement before the first "private...
4
by: Marc E | last post by:
All, I'm coming from java and coldfusion, where one can set a "global" variable in one place (the servletcontext in java, Application.cfm in coldfusion) and all files in that site can then take...
5
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.