VB.net自动属性具有不同的访问级别设置

发布于 2024-09-12 05:34:11 字数 404 浏览 1 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

贱人配狗天长地久 2024-09-19 05:34:11

它看起来也不像是在 VB.NET 2010 中。您可以这样做:(

Public Property myProp As String = "Foo"

这将为您提供公共 getter 和 setter。)

但是您无法设置不同级别的访问权限。您仍然需要手动实现它们。

It doesn't look like it's in VB.NET 2010 either. You can do this:

Public Property myProp As String = "Foo"

(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.

謸气贵蔟 2024-09-19 05:34:11

According to this answer, you can't.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文