Private Thingy As Integer
Property Thing() As Integer
Get
Return Thingy
End Get
Private Set(ByVal value As Integer)
Thingy = value
End Set
End Property
VB10 中的 Auto 属性
Property PartNo As Integer = 44302
但在 VB 中仍然无法使用私有设置,甚至在 VB10 中也无法完成,请参阅此处:
来自 MSDN(如约翰所说):
需要的属性定义 标准语法:
指定不同的辅助功能 获取和设置过程。 为了 例如,您可能想要使 设置过程 Private 和 Get 程序公开。
Like this:
Private Thingy As Integer
Property Thing() As Integer
Get
Return Thingy
End Get
Private Set(ByVal value As Integer)
Thingy = value
End Set
End Property
Auto property in VB10
Property PartNo As Integer = 44302
But with a private set still can't be done in vb not even in VB10 see here:
From MSDN (as john said):
Property Definitions That Require Standard Syntax :
Specify different accessibility for the Get and Set procedure. For example, you might want to make the Set procedure Private and the Get procedure Public.
Auto-implemented properties are convenient and support many programming scenarios. However, there are situations in which you cannot use an auto-implemented property and must instead use standard, or expanded, property syntax.
You have to use expanded property-definition syntax if you want to do any one of the following:
[...]
Specify different accessibility for the Get and Set procedure. For example, you might want to make the Set procedure Private and the Get procedure Public.
发布评论
评论(3)
像这样:
VB10 中的 Auto 属性
但在 VB 中仍然无法使用私有设置,甚至在 VB10 中也无法完成,请参阅此处:
来自 MSDN(如约翰所说):
Like this:
Auto property in VB10
But with a private set still can't be done in vb not even in VB10 see here:
From MSDN (as john said):
根据 这篇 MSDN 文章,您不能:
According to this MSDN article, you can't:
我认为这是不可能的(目前)。
请参阅 MSDN 上的此链接。
上面的文章甚至链接到另一篇混合访问级别。
我在 Microsoft Connect 上发现了此,因此他们正在考虑(如果是针对 VS2010 那是另一个问题)。
I don't think that is possible (yet).
See this link on MSDN.
The above article even links to another one about mixed access levels.
I found this on Microsoft Connect, so they are thinking about it (If it will be for VS2010 that's another question).