set up a static global variable


In, what code do I use to set up and use a static global variable.
I want to apply a string value to it that can be used all over the project
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
Obadiah ChristopherConnect With a Mentor Commented:
Declare a static property in your application.

public class Class1
        public static int MyProperty { get; set; }

// Inside the global.asax file Application_Start event initialize it's value
protected void Application_Start(object sender, EventArgs e)
Class1.MyProperty = 1;    

Now you can access this property anywhere from the application.
Kyle AbrahamsConnect With a Mentor Senior .Net DeveloperCommented:
I usually put something like that in the web.config so it can be configured later.


   <key ="MyKey" value = "MyValue" />

in code:

dim mystring as string = ConfigurationManager.AppSettings("MyKey")

More info:
Try doing a little more digging before asking here. Found this example that seems to be the solution to your problem rather quickly.
CodeCruiserConnect With a Mentor Commented:
You can also use session. Add something to session

Session("MyVar") = MyVal

and you can access it anywhere else.
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much for the information
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.