昏暗与私人/公共 [英] Dim vs Private/Public
问题描述
在一个模块的头部,我希望声明一些全局变量以用于各种子/函数.
At the head of a module, I wish to declare some global variables for use in various subs/functions.
有什么区别
Dim x as string
和 Private x as string
/Public x as string
,我什么时候会使用一个?
Dim x as string
and Private x as string
/ Public x as string
, and when would I use one over the other?
推荐答案
私有和公共控制您声明的变量或对象的范围.
Private and public control the scope of the variable or object you're declaring.
Private
将只允许相关模块/类/任何成员的成员访问实例
Private
will only allow members of the relative module/class/whatever to access the instance
public
将允许与模块/类/任何内容相同范围内的任何内容访问它.
public
will allow anything in the same scope as the module/class/whatever to access it.
Dim
默认为 public 或 private,这取决于你在做什么.例如,一个类将默认为 private.我建议阅读封装和 OOP 以更好地了解这一点.
Dim
defaults to either public or private, depending on what you're working in. A class for example, will default to private. I suggest reading up on encapsulation and OOP to get a better feel for this.
这篇关于昏暗与私人/公共的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!