4

I was simply wondering if in VB.Net there is a shorthand equivalent to this kind of C# including the private setter:

public string Test { get; private set; }

Can someone please tell me the shortest way to achieve this in VB.Net?

Stormenet
  • 25,926
  • 9
  • 53
  • 65
Alex Hope O'Connor
  • 9,354
  • 22
  • 69
  • 112

3 Answers3

5

Sorry, this is not possible in VB.NET:

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:

  • ...
  • Create properties that are WriteOnly or ReadOnly.
  • ...
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

Unfortunately, you can't use different accesibilities for auto property accessors in VB.NET. You have to manually write the property code.

Maximilian Mayerl
  • 11,253
  • 2
  • 33
  • 40
1

Like this:

Private _test As String

Public Property Test() As String

Get
    Return _test
End Get

Private Set(ByVal Value As String)
    _test = Value
End Set

End Property

No alternative.

Ken D
  • 5,880
  • 2
  • 36
  • 58