Global variable

I have a windows applicaton written in c#. How can I store a connection globally so that I can open it at the beginning and keep until exit from the application



Answer this question

Global variable

  • lguger

    If it's a database connection, it is recommended to open and close it everytime you are doing a query (connection pooling will handle everything).


    Here is a simple way to do a global variable.

    class Global
    {
      public static string PublicVariable;
    }


    // ...

    Global.PublicVariable = "aaa";




  • Global variable