Global variables in Visual C#

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

How do I declare global variables in Visual C#?

4条回答
  •  暖寄归人
    2021-01-21 03:40

    How about this

    public static class Globals {
        public static int GlobalInt { get; set; }
    }
    

    Just be aware this isn't thread safe. Access like Globals.GlobalInt

    This is probably another discussion, but in general globals aren't really needed in traditional OO development. I would take a step back and look at why you think you need a global variable. There might be a better design.

提交回复
热议问题