Dim 和 Private 之间的区别 [英] Difference between Dim and Private

查看:58
本文介绍了Dim 和 Private 之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VB.NET中DimPrivate有什么区别?

What is the difference between Dim and Private in VB.NET?

推荐答案

Dim 声明并为变量分配空间.Private 用于指定访问级别这意味着只有声明类才能看到或使用声明的成员.

Dim declares and allocates space for a variable. Private is used to specify an access level that means only the declaring class can see or use the declared member.

我相信您的问题源于您有时会看到以下内容:

I believe your question comes from the fact that you sometimes see things like:

Class MyDemoClass
   Dim mVar1 As Integer
   Private mVar2 As Integer
End Class

在上面的例子中,mVar1mVar2 声明在逻辑上是等价的——它们都归结为 Private Dim mVar as Integer.

In the above example mVar1 and mVar2 declarations are logically equivalent - they both boil down to Private Dim mVar as Integer.

MSDN 在此处对此进行了解释:

MSDN explains this here:

如果您指定以下任何修饰符,Dim 关键字是可选的,通常会被省略:Public、Protected、Friend、Protected Friend、Private、Shared、Shadows、Static、ReadOnly 或 WithEvents.

The Dim keyword is optional and usually omitted if you specify any of the following modifiers: Public, Protected, Friend, Protected Friend, Private, Shared, Shadows, Static, ReadOnly, or WithEvents.

这篇关于Dim 和 Private 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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