Re: Public variable VS property ?
- From: "Phill. W" <P.A.Ward@xxxxxxxxxxxxxxxxxxx>
- Date: Tue, 26 Apr 2005 14:43:18 +0100
"Agnes" <agnes@xxxxxxxxxxxxxxxxxx> wrote in message
news:O8$tr3hRFHA.1236@xxxxxxxxxxxxxxxxxxxxxxx
> In a single form , I can delcare a public vairable or property.
> So. What is the difference between it ??
There are no Stupid Questions - just the occasional Silly Answer
(of which this /isn't/ one, I hope) ...
A Property can be controlled, because you get to see every value
coming in or going out.
Compare these two.
Public ValueThatMUSTBeBetweenOneAndThree as Integer
If this value is used within your class to, say, index into a three-element
array and something in the Outside World does ...
YourObject.ValueThatMUSTBeBetweenOneAndThree = 7
.... your class is in trouble!
Contrast that with
Public Property VTMBBOneAndThree() as Integer
Get
Return m_iIndex
End Get
Set( ByVal Value as Integer )
Select Case Value
Case 0 to 2
m_iIndex = Value
Case Else
Throw New ArgumentException( ...
End Select
End Set
End Property
Private m_iIndex as Integer = 0
Now if something in the Outside World tries to do ...
YourObject.VTMBBOneAndThree = 7
.... /they're/ in for a nasty surprise, but /your/ object will remain
quite happy.
HTH,
Phill W.
.
- References:
- Public variable VS property ?
- From: Agnes
- Public variable VS property ?
- Prev by Date: Re: How are things done where you work?
- Next by Date: Re: How are things done where you work?
- Previous by thread: Re: Public variable VS property ?
- Next by thread: jfinch@group10.net
- Index(es):