VB.net自动属性具有不同的访问级别设置
在 C# 中,您可以为 get 和 set 自动赋予具有不同访问级别的值。 。 。例如,
public String myString
{
get;
private set;
}
是否可以通过 vb.net 中的自动属性来做到这一点,或者您是否被迫进行冗长的属性实现?
例如我不想一直这样做
Dim _myString As String
Public Property MyString() As String
Get
Return _myString
End Get
Private Set(ByVal value As String)
_myString = value
End Set
End Property
In c# you can auto property a value with different level of access for the get and set . . . e.g.
public String myString
{
get;
private set;
}
Is there away to do that with automatic properties in vb.net or are you forced to go for the long winded implementation of properties?
e.g. I don't want to do this all the time
Dim _myString As String
Public Property MyString() As String
Get
Return _myString
End Get
Private Set(ByVal value As String)
_myString = value
End Set
End Property
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它看起来也不像是在 VB.NET 2010 中。您可以这样做:(
这将为您提供公共 getter 和 setter。)
但是您无法设置不同级别的访问权限。您仍然需要手动实现它们。
It doesn't look like it's in VB.NET 2010 either. You can do this:
(This will give you a public getter and setter.)
But you can't set different levels of access. You would still have to manually implement them.
根据这个答案,你不能。
According to this answer, you can't.