No it is not. If your field data type is a string, you must pass a
string into your property because your property will also be a string type.
This is not necessarily true. The data type of the field is not always the
same as the property. Consider a field variable that is a byte. Suppose
this byte is to be stored in a file as a value of 1 or 0, indicating True
or False. But you want the user of your class to access a boolean to make
it easier for him. In this example, for whatever reason, the true or false
value must be stored in a file as 1 or 0 (perhaps to work with some legacy
code or some language that does not natively support booleans). You might
wish to have a Boolean property to make it easy for the user of the class.
Private m_BoolAsByte As Byte
Public Property BoolAsByte() As Boolean
Get
Return (m_BoolAsByte = 1)
End Get
Set(ByVal Value As Boolean)
If Value Then
m_BoolAsByte = 1
Else
m_BoolAsByte = 0
End If
End Set
End Property
Quite possibly. I agree that an integer field with a string property
doesn't make much sense, but there is the distinct possiblity that the
field variable is not the same type as the property, like my contrived
example above.
Another example is where you might have an integer field variable, but you
want to present the user with only a few possibilities for that value by
using an enum:
Public Enum Possibilities As Integer
FirstPossibility
SecondPossibility
ThirdPossibility
FourthPossibility
End Enum
'Field variable defined as integer
Private m_iPossibleValue As Integer
'Property defined as enum
Public Property PossibleValue() As Possibility
Get
Return CType(m_iPossibleValue, Possibility)
End Get
Set(ByVal Value As Possibility)
m_iPossibleValue = CInt(Value)
End Set
End Property
Now, I don't know how often this type of thing is needed, but my point is
that there may be legitimate reasons for the field to be a different data
type than the property. To my view, this is an endorsement of property
use.
--
Chris
dunawayc[AT]sbcglobal_lunchmeat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.