问题描述
我需要在我的项目中有一个Public变量。在VB中,它可以在
中声明为标准模块。我在哪里可以用C#做什么?
我试着在默认的Program.cs中做这个,我尝试在
me class中添加它。
没有成功
那么,我如何以及在哪里声明项目中任何模块可见的变量?
Esha
I need to have a Public variable in my project. In VB it can be declared in
a standard module. Where can I do it in C# ?
I tried to do it in default class Program.cs and I tried it in an added by
me class.
No success
So, how and where I declare a variable visible by any module in the project?
Esha
推荐答案
快速解决方案:
公共类Globals
{
public SomeClass Varname;
}
可用作Globals.Varname
更好的解决方案:
看单身模式或其他重组方式,
因为第一个不好OOP
Arne
Quick solution:
public class Globals
{
public SomeClass Varname;
}
can be used as Globals.Varname
Better solution:
look at singleton pattern or another way of restructuring,
because the first one is not good OOP
Arne
Michael
Michael
这篇关于在哪里声明公共变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!