开发者

Does VB.NET support automatic getters and setters on properties?

开发者 https://www.devze.com 2023-02-23 07:21 出处:网络
In C# I can do this: public string myProperty { get; private set; } This is referred to as an \"automatic getter/setter\" (from what I\'ve heard). 开发者_如何学JAVADoes VB.NET support these? So far

In C# I can do this:

public string myProperty { get; private set; }

This is referred to as an "automatic getter/setter" (from what I've heard). 开发者_如何学JAVADoes VB.NET support these? So far, with my properties, all I can do is this:

Public Property myProperty As String
    Get
        Return String.Empty
    End Get
    Private Set(ByVal value As String)
        somethingElse = value
    End Set
End Property

which is extremely clunky.

So... is there a better way?


Yes.

Public Property MyProperty As String

However, you can only make it ReadOnly in VB 14 (vs 2015) or later.


It does but only from framework 4.0 (2010)

http://weblogs.asp.net/gunnarpeipman/archive/2009/11/01/net-framework-4-0-vb-net-supports-automatic-properties.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号