How do I write private set auto-properties in VB 10?

Shimmy Weitzhandler picture Shimmy Weitzhandler · Jun 9, 2009 · Viewed 7.4k times · Source

in C#:

public string Property { get; private set; }

in VB?

Please vote or/and share your ideas!

Answer

albertjan picture albertjan · Jun 9, 2009

Like this:

Private Thingy As Integer
Property Thing() As Integer
    Get
        Return Thingy
    End Get
    Private Set(ByVal value As Integer)
        Thingy = value
    End Set
End Property

Auto property in VB10

Property PartNo As Integer = 44302

But with a private set still can't be done in vb not even in VB10 see here:

From MSDN (as john said):

Property Definitions That Require Standard Syntax :

  • Specify different accessibility for the Get and Set procedure. For example, you might want to make the Set procedure Private and the Get procedure Public.