为什么公共变量无法看到? [英] Why public variable can not be seen?

查看:84
本文介绍了为什么公共变量无法看到?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在vb.net工作过。该项目有三个模块。我在form1.vb中定义了两个变量,如:



public lbest as integer

公共距离(255,3)为double

模块2中的
,我使用了上面两个变量,但使用距离变量时出现错误。错误信息是:



错误104'距离'未声明。由于其保护级别,它可能无法访问。



有什么问题以及为什么lbest变量有错误?



regrads。

Hi,
I worked with vb.net. the project has three modules. I defined two variables in form1.vb like:

public lbest as integer
public distances(255,3) as double

in module2, I used the two above variables but there is an error appears when using distance variable. the error message is:

Error 104 'distances' is not declared. It may be inaccessible due to its protection level.

what is the problem and why there is error with lbest variable??

regrads.

推荐答案

可能是因为你将它们声明为form1的一部分 - 这使得它们成为form1类中的类级变量。为了访问它们,你需要使用包含你想要的变量的form1的实际实例。



它就像一辆汽车 - 如果你将你的手机放入你的车的手套箱,你希望在我的车的手套箱里找到它吗?

每辆车都有自己的手套箱,而且每个form1的实例都有它自己的一组类变量。因此,您只需在yourCar.GloveBox中找到您的手机而不是myCar.GloveBox,您需要引用myInstanceOfForm1.lbest和myInstanceOfForm1.distances来访问变量。
Probably, because you declared them as part of form1 - which makes them class level variables within the form1 class. In order to access them, you need to use the actual instance of form1 that contains the variables you want.

It's like a car - if you put your mobile in the glove box of your car, would you expect to find it in the glove box of my car?
Each car has it's own glove box, and each instance of form1 has it's own set of class variables. So just as you will only find your mobile in yourCar.GloveBox and not in myCar.GloveBox, you would need to reference myInstanceOfForm1.lbest and myInstanceOfForm1.distances to access the variables.


这篇关于为什么公共变量无法看到?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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