Best place for global variables in ASP.Net apps?

G

Guest

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;
 
I

Ignacio Machin \( .NET/ C# MVP \)

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,
 
K

Kevin Yu [MSFT]

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."
 
G

Guest

I was sure I'd clicked
Yes for Did this post answer the question?

The reponses were very helpful - thanks.
 

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