C# - 的WinForms - 全局变量 [英] C# - Winforms - Global Variables
本文介绍了C# - 的WinForms - 全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想有些变量是整个项目的全球性和可访问的每一个形式。我怎样才能做到这一点?
I want some variables to be global across the project and accessible in every form. How can I do this?
推荐答案
是你可以使用静态类。
像这样的:
yes you can by using static class. like this:
static class Global
{
private static string _globalVar = "";
public static string GlobalVar
{
get { return _globalVar; }
set { _globalVar = value; }
}
}
和使用任何地方,你可以这样写:
and for using any where you can write:
GlobalClass.GlobalVar = "any string value"
这篇关于C# - 的WinForms - 全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文