在Visual C#中的全局变量 [英] Global variables in Visual C#

查看:106
本文介绍了在Visual C#中的全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何申报在Visual C#中的全局变量?

How do I declare global variables in Visual C#?

推荐答案

这个怎么样

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



要知道这是不是线程安全的。像 Globals.GlobalInt

这可能是另外一个讨论,但一般全局是不是真的需要传统OO发展。我会退后一步,看看为什么你认为你需要一个全局变量。有可能是一个更好的设计。

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.

这篇关于在Visual C#中的全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆