global variable for windows application


hello,

how can i write and read a global variable for the entire application in C#


Many Thanks,
Jassim Rahma




Answer this question

global variable for windows application

  • stoneyowl

    Hello Jassim

    There is no concept of Global Variables in C#, you can use global variables inside the entire class but not in the entire namespace.

    Solution for this problem is to create STATIC VARIABLES and use these variables anywhere in the namespace. Hope this might help


  • e-an

    You can use a class with some public static members or properties. Here is a little example, or you can take a look to the Singleton pattern.


    public static class Globals
    {
    public static string MyString;
    public static int MyInt;
    public static double MyDouble;
    }




  • global variable for windows application