If the variable is only used internally, you wouldn't have a property in the first place, would you? And then you access the field directly, I thought that much was obvious. A property exists (in most cases) to have a single point of access for a class-level field. For a field which is never accessed externally, you don't ever create a property (unless, of course, getting / setting this property encapsulates more than a simple get/set, in which case a property might be appropriate)
If the variable is to be accessed internally AND externally, then you use the property both internally and externally. The property may encapsulate lazy loading, validation, value checking etc, so why would you bypass this logic? If the property is read-only, then there is a reason for this (i.e. logic already exists internally to set the value of the underlying field), again common sense rules here and you access the field directly when SETTING, but use the property when GETTING. Finally - if you have any more pathetic comments about my level of ability, kindly keep them to yourself. Insulting other members of the group simply serves to highlight your own inadequacy. On Thu, Dec 17, 2009 at 10:00 AM, Processor Devil <[email protected] > wrote: > Dear Jamie... > and what about you don't need any variable to be accessible from the > outside of the class, how would you access the value? Would you make one > useless property? And what about if you want the property to be read only, > how would you change the value? > > Sorry to tell you, but the guy who taught you programming should return you > money for the lessons... > > 2009/12/17 Jamie Fraser <[email protected]> > > Inside the class, you should use the property. Outside of the class, you >> should also use the property. >> >> >> On Wed, Dec 16, 2009 at 9:18 AM, Processor Devil < >> [email protected]> wrote: >> >>> inside the same class use i = me._intID :) >>> class properties are used to set or get the variable content out of the >>> current class scope, but yes, either works >>> >>> 2009/12/16 hanks2000 <[email protected]> >>> >>> oops sorry posted by accident, here's the complete example >>>> >>>> Public Property ID() As Integer >>>> Get >>>> Return _intID >>>> End Get >>>> Set(ByVal value As Integer) >>>> If Not _intID = value Then >>>> _intID = value >>>> End If >>>> End Set >>>> End Property >>>> >>>> >>>> Private Sub SomeMethod() >>>> Dim i As Integer = 0 >>>> >>>> 'use this >>>> i = me._intID >>>> >>>> 'or this >>>> i = me.ID >>>> End Sub >>>> >>>> >>>> Thanks >>>> >>> >>> >> >
