Global variables in Visual C#

前端 未结 4 575
花落未央
花落未央 2021-01-21 03:15

How do I declare global variables in Visual C#?

4条回答
  •  轮回少年
    2021-01-21 03:52

    A public static field is probably the closest you will get to a global variable

    public static class Globals
    {
      public static int MyGlobalVar = 42;
    }
    

    However, you should try to avoid using global variables as much as possible as it will complicate your program and make things like automated testing harder to achieve.

提交回复
热议问题