Global variables in VC#.net windows application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rhyme2ri2
    New Member
    • Dec 2006
    • 21

    Global variables in VC#.net windows application

    Hi!
    I want to use some variables throughout my VC#.net windows based application.... .......
    How can i declare global variables that will work throughout my project...
    -Regards
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    I recommend declaring them in the application_sta rt event of the global.asax file. This article may help if you are unfamiliar with the ASP.NET application file:
    Global.asax Syntax

    Comment

    • almaz
      Recognized Expert New Member
      • Dec 2006
      • 168

      #3
      Originally posted by rhyme2ri2
      Hi!
      I want to use some variables throughout my VC#.net windows based application.... .......
      How can i declare global variables that will work throughout my project...
      -Regards
      Global variables, especially those being updated from various parts of application, make your code unreadable. General thoughts that should be considered when you want to declare something to be globally available:
      • Each variable is bound to some functionality. Thus, it is better to put it to corresponding class as static/instance member, so it will be maintained through methods/properties of that class.
      • Static members containing common values that are changed from different places of application can brake encapsulation rule.

      Nevertheless it may be useful to separate common constants/settings to a separate internal static class, something like this:
      Code:
      internal static class Constants
      {
          public static int UndefinedID = int.MinValue;
      
          public bool IsDefined(int id) { return id != UndefinedID; }
      }

      Comment

      • nmsreddi
        Contributor
        • Jul 2006
        • 366

        #4
        hello kenobewan

        i want to how you can have a global.asax file in windows based application

        as you have said in the above reply.


        please tell me if its possible it is very use full for me too.


        regards
        NMsreddi

        Comment

        Working...