473,395 Members | 1,797 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.

Fields and Properties

Can someone please explain to me when you would use a Property instead of a
field and wy? Thanks in advance.
May 18 '07 #1
2 1189
RSH
Encapsulation.
"Claude Grecea" <cg*****@shionogi-usa.comwrote in message
news:u7**************@TK2MSFTNGP04.phx.gbl...
Can someone please explain to me when you would use a Property instead of
a field and wy? Thanks in advance.

May 18 '07 #2
On Fri, 18 May 2007 18:06:13 +0200, Claude Grecea <cg*****@shionogi-usa.comwrote:
Can someone please explain to me when you would use a Property instead of a
field and wy? Thanks in advance.
Hi Claude,

A few things that springs to mind

1) DataBinding requires a Property
2) Smart fields. Processing indata before storing it, or not storing data at all but generating the value when asked.
3) Better control over who can write to the property. You can have public getters and private setters.
4) Easier to change logic. You can rewrite the getter and setter without touching outside code.

I don't think I have exposed a class field for a long time, and rarely even use the fields other than as property storage. With C# 3.0 even property storage isn't needed in many cases.

--
Happy coding!
Morten Wennevik [C# MVP]
May 18 '07 #3

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

Similar topics

7
by: Koda | last post by:
What is the difference between class fields and class properties? Thanks Mike
2
by: Dave | last post by:
Hi I'm creating a fairly simple Staff database using Access 97. There is a table, which stores all of the staff details (initials, firstname, surname, tel. no. etc.) and I want to design a...
3
by: sparks | last post by:
I was copying fields from one table to another. IF the var name starts with milk I change it to egg and create it in the destination table. It works fine but I want to copy the description as...
1
by: Dixie | last post by:
I wish to add some fields to an existing table in code. I am using the following code from rkc. CurrentDb.Execute ("ALTER TABLE MyTable ADD MyNewField Text 25") This works , but I need to also set...
26
by: julien | last post by:
Hello, I don't know when to use fields and when to used properties. It looks to me that using properties is always better. But I guess fields must be better in some cases, otherwise they wouldn't...
3
by: Jordan | last post by:
Suppose I have a system that keeps track of 5 different types of "People". My intent is to have a base Person class, then 5 derived classes for each of the specific person types (e.g., Patient,...
0
by: JDMils | last post by:
I am having trouble finding the AutoNumber field of my database with this code. The code is used to replicate a specific table, reproducing all columns including indexes and Primary Keys (there is...
7
by: =?Utf-8?B?SmVmZiBCZWVt?= | last post by:
The default paging behavior of the gridview doesn't work well with very large sets of data which means we have to implement some sort of custom paging. The examples I have seen (4guysfromrolla,...
0
by: oh4real | last post by:
I recently developed a compact function to efficiently allow users to change info in a form (like account info, contact info, etc.) and then the function automatically identifies what's changed and...
4
by: =?Utf-8?B?RGFuIFNoZXBoZXJk?= | last post by:
Is there a way to disable a number of fields (50+) using Visual Basic 2005? I have a window that used an imported control in vb 6 but now relies on .Net control.. The old logic was: Dim...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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
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...
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...
0
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,...

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.