VB.Net Properties - Public Get, Private Set

后端 未结 6 1817
借酒劲吻你
借酒劲吻你 2021-01-31 13:32

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 prope

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-31 14:04

    One additional tweak worth mentioning: I'm not sure if this is a .NET 4.0 or Visual Studio 2010 feature, but if you're using both you don't need to declare the value parameter for the setter/mutator block of code:

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

提交回复
热议问题