如何在一个解决方案中访问项目中的公共变量 [英] How to access public variable accross projects in one solution
本文介绍了如何在一个解决方案中访问项目中的公共变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个在类中定义的publice变量(vrPassword)。
如何在解决方案中跨不同项目访问其数据?
我不知道是否需要给这个班级任何重围?
谢谢
Hi,
I have a publice variable (vrPassword) that is defined in a class.
How to access its data across different projects in a solution?
I do not know if any re fences to this class needs to be given?
Thanks
推荐答案
首先转到其他项目的参考部分 - 右键单击并选择添加参考。
参考对话框应打开,项目
标签已打开(如果没有,则选择该标签)
你的其他项目将在那里列出 - 点击确定。
在你想要使用 vrPassword的同一个项目中,输入
First go to the References section of the "other" project - right-click and choose "Add Reference".
The References dialog should open with theProjects
tab already open (if not, then select that tab)
Your other project will be listed there - click OK.
In the same project where you want to use vrPassword, type
using ASample;
(其中ASample是项目名称包含 vrPassword
您现在可以使用该变量
(where "ASample" is the name of your project that contains vrPassword
You can now use that variable
YourClass yc = new YourClass();
MessageBox.Show(yc.AVariable.ToString());
或者您可以使用省略并使用
or you can omit the using
and use
ASample.YourClass yc = new ASample.YourClass();
MessageBox.Show(yc.AVariable.ToString());
这篇关于如何在一个解决方案中访问项目中的公共变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文