qJake qJake - 1 year ago 127
Vb.net Question

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

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). Does VB.NET support these? So far, with my properties, all I can do is this:

Public Property myProperty As String
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?

Answer Source


Public Property MyProperty As String

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download