473,395 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need definition of Field vs Property

What is the definition of a field in VB.net (other than database functions)?
How does one distinguish between a "field" and a "property"?
Or are fields and properties related to each other in some way?

Thanks in advance.

Apr 5 '07 #1
4 2242
Internet User,

A field is a public variable in a class. As such it can be directly accessed
from an object created from the class.

A property is a set of accessor methods (Get/Set) that mediate access to
data stored in a private variable in a class. As such, the data cannot be
directly access from an object created from the class.

Kerry Moorman
"Internet User" wrote:
What is the definition of a field in VB.net (other than database functions)?
How does one distinguish between a "field" and a "property"?
Or are fields and properties related to each other in some way?

Thanks in advance.

Apr 5 '07 #2
On Apr 5, 1:52 pm, Kerry Moorman
<KerryMoor...@discussions.microsoft.comwrote:
Internet User,

A field is a public variable in a class. As such it can be directly accessed
from an object created from the class.
A field is any class level variable whether public, private, or
internal.

Apr 5 '07 #3
You can search google for a whole host of answers and suppositions.

I think of fields as state and data of the object, while properties are
controlled interaction with the object's state and data.

example: (from here you surmize your own thoughts)

'State and data for our person object
private pstrPersonName as string
private pdteDateOfBirth as date
private pblnIsDirty as boolean

Public Event StateChanged(sender as object, e as system.eventargs)

'Provide information about the object's data with this state flag (Is Dirty)
' we assign it as readonly in this property because we do not
' want consumers to inadvertantly mess it all up.
public readonly property IsDirty as boolean
get
return pblnIsDirty
end get
end property

'Provide controlled access to Date of Birth
' the control is that our person must be within driving age
' (16-71), reject the update if the person is not in that range.
public property DateOfBirth as Date
get
return pdteDateOfBirth
end get
set (value as date)

dim iTemp as integer = datediff("yyyy",value, now)

if itemp >=72 or itemp < 16 then 'Cannot have a driver's license
'throw an exception DateOfBirth is invalid
end if

pdteDateOfBirth = value
pblnIsdirty = true
raiseevent StateChanged(me,new systemeventargs)
end set
end property

'Instruct the object to save it's data and update its state
public sub Save()
if not me.IsDirty then exit sub
'perform save logic
pblnIsDirty = false
raiseevent StateChanged(me,new systemeventargs)
end sub
"Brian Gideon" <br*********@yahoo.comwrote in message
news:11*********************@d57g2000hsg.googlegro ups.com...
On Apr 5, 1:52 pm, Kerry Moorman
<KerryMoor...@discussions.microsoft.comwrote:
>Internet User,

A field is a public variable in a class. As such it can be directly
accessed
from an object created from the class.

A field is any class level variable whether public, private, or
internal.

Apr 5 '07 #4
Hello Internet User,

In addition to Amdrit's comment:
I think of fields as state and data of the object, while properties are
controlled interaction with the object's state and data.
A property is a Function (Get) /Sub (Set) combination which usually has
a variable behind.

The advantage of the property to a plain (public) variable is that you
can react on changes of that variable. That might be to send an error if
a value is OK with the variable, but you don't want to allow it (e.g.
transparent for a color) or if you need to recalculate something in your
class after the variable has been changed.

Best regards,

Martin
Apr 6 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Daniele Varrazzo | last post by:
Hi everybody, I am writing a base class for <<entity>> stereotype classes, to implement controlled access to the state and expose some of the access logic (in order to dinamically build...
9
by: Dave H | last post by:
Hello, I have a query regarding definition lists. Is it good practice semantically to use the dt and dd elements to mark up questions and answers in a frequently asked questions list, or FAQ? ...
5
by: Charles Harrison Caudill | last post by:
I've been going through tutorials, APIs, posts on this newsgroup, this newsgroup's faq, etc... I have a function that describes the fields that an object claims to have and I have found what...
3
by: CAD Fiend | last post by:
Hello, I have a land development project that has a many-to-many relationship. I have ONE question regarding table structures, and ONE question on how to make a Form with two Subforms, below. ...
11
by: my-wings | last post by:
I think I've painted myself into a corner, and I'm hoping someone can help me out. I have a table of books (tblBooks), which includes a field (strPubName) for Publisher Name and another field...
5
by: tsnyder | last post by:
I need to have an option button that allows editing to a field only when it is checked.
1
by: roveagh1 | last post by:
Hi I've been using the 2 year old link below to repeat values from previous record field into current corresponding field. It's worked fine for text but the last piece of advice was to use the same...
7
by: Rnykster | last post by:
I know a little about Access and have made several single table databases. Been struggling for about a month to do a multiple table database with no success. Help! There are two tables. First...
25
by: vikram Bhuskute | last post by:
I have plans to train some students for C in coming weeks. I am badly looking for C programming assignments fot them. Need 1) lots of them per topiic 2) Should be doable for beginners thanks...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.