Public Get/Private Set

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    Public Get/Private Set

    When did this get added to .NET?

    Code:
    Class Contact 
    
        Private _Name As String 
        Private _Address As String 
    
        'Public Get/Private Set
        Public Property Name() As String 
            Get 
                Return _Name 
            End Get 
            Private Set(ByVal value As String) 
                _Name = value 
            End Set 
        End Property
    
        'Public Get/Private Set
        Public Property Address() As String 
            Get 
                Return _Address 
            End Get 
            Private Set(ByVal value As String) 
                _Address = value 
            End Set 
        End Property 
    
    End Class
    A property that's writeable from inside but readonly from outside! How did this manage to get past me before now?
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    I didn't know you could use modifiers on the get/set clauses of the properties...th at's nice.

    Good find.

    Comment

    • balabaster
      Recognized Expert Contributor
      • Mar 2007
      • 798

      #3
      Originally posted by insertAlias
      I didn't know you could use modifiers on the get/set clauses of the properties...th at's nice.

      Good find.
      I didn't either - I found some obscure code pattern on the net that I for sure thought was wrong and translated it to VB using DeveloperFusion 's tool thinking it would crash because if that existed in VB I'd have found it before now - but it didn't.

      So I pasted into a console app thinking that DeveloperFusion had just translated it wrong, and it works...

      Comment

      • PRR
        Recognized Expert Contributor
        • Dec 2007
        • 750

        #4
        Originally posted by balabaster
        When did this get added to .NET?

        Code:
        Class Contact 
        
            Private _Name As String 
            Private _Address As String 
        
            'Public Get/Private Set
            Public Property Name() As String 
                Get 
                    Return _Name 
                End Get 
                Private Set(ByVal value As String) 
                    _Name = value 
                End Set 
            End Property
        
            'Public Get/Private Set
            Public Property Address() As String 
                Get 
                    Return _Address 
                End Get 
                Private Set(ByVal value As String) 
                    _Address = value 
                End Set 
            End Property 
        
        End Class
        A property that's writeable from inside but readonly from outside! How did this manage to get past me before now?
        amazing ... tip of week...

        Comment

        Working...