473,790 Members | 3,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2256
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...@d iscussions.micr osoft.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(se nder as object, e as system.eventarg s)

'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*********@ya hoo.comwrote in message
news:11******** *************@d 57g2000hsg.goog legroups.com...
On Apr 5, 1:52 pm, Kerry Moorman
<KerryMoor...@d iscussions.micr osoft.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
1099
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 javascript code for client-side checks, for example). Currently the idiom needed to subclass it is something like: class Group(Entity): _interface = Entity._extend_interface(
9
3752
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? Here is an example of just such a usage: <dl class="faq"> <di>
5
1352
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 that function reports to often be contradictory to what it will actually respond to. I have seen objects whose toString method returns "" (which Google is unaware of practically btw) return a correct value when I request the "name" field, but even...
3
1973
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. TABLE STRUCTURE QUESTION: There are two parts to this preface.
11
2807
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 (strPubCity) for Publisher City. These two fields have a many-to-one relationship with tables, (tlkpPubName and tlkpPubCity) respectively. The lookup tables only have one field (strPubName and strPubCity), which is their primary key. I also have...
5
2670
by: tsnyder | last post by:
I need to have an option button that allows editing to a field only when it is checked.
1
4342
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 logic for a date field. i.e. theValue.defaultvalue = "#" & theValue.value & "#" I can't get this to work for some reason and I can't figure out why. Can anyone out there help? Thanks Repeat value of previous record field into current...
7
2037
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 has about 30 fields. Every entry in this table will be unique. Second table has about 7 fields and is for reference - strictly a look up type table. I want to use one field, say FAMILY in the first table to look up any one of the 400 items in the...
25
2096
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 in advance Vikram
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10419
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10201
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10147
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9023
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6770
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.