how to setup static variable at program load

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • siilexx
    New Member
    • Aug 2010
    • 19

    how to setup static variable at program load

    Hello,

    I'd like to setup a static variable at program load, depending on data saved in a text file.

    It's currently hardcoded :
    internal static int ApplicationVers ion=3;
    And I use it to declare my arrays of objects,... :
    internal Button[,] ButtonDays = new Button[ApplicationVers ion, 7];

    How can I update the "ApplicationVer sion" once at the startup of the program, so that the whole declarations are also setup accordingly ?

    Thank you
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    All you need to do is set your ApplicationVers ion before you do your declarations. If you did it in your constructor for your main form, you could always do...

    Code:
    internal static int ApplicationVersion = -1;
    
    public MyObject()
    {
      if (ApplicationVerson == -1)
        ApplicationVersion = GetApplicationVersion();
    
      SetUpObjects(ApplicationVersion);
    }
    Is that what you meant? If you really wanted, you could always throw ApplicationVers ion on a global static class and set it in Program.cs before your application is even run.

    Comment

    • siilexx
      New Member
      • Aug 2010
      • 19

      #3
      Hi
      thanks for your help

      Comment

      Working...