VB.Net Properties - Public Get, Private Set

RiddlerDev picture RiddlerDev · Sep 22, 2009 · Viewed 121.3k times · Source

I figured I would ask... but is there a way to have the Get part of a property available as public, but keep the set as private?

Otherwise I am thinking I need two properties or a property and a method, just figured this would be cleaner.

Answer

JDunkerley picture JDunkerley · Sep 22, 2009

Yes, quite straight forward:

Private _name As String

Public Property Name() As String
    Get
        Return _name
    End Get
    Private Set(ByVal value As String)
        _name = value
    End Set
End Property