473,404 Members | 2,178 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,404 software developers and data experts.

Property VS Variable ??

Hi all...

What is the different between using property and variable?
Their all functionality is same (for store a value). I get this issue when I
want find the best way to passing a parameter between form (Windows
application).
And, what is the best way to passing value to other form?
Thanks all..
Nov 16 '05 #1
3 6711
A property encapsulates a private variable. So the property itself controls
access to the variable and invoke business rules if needed.

Example:
int m_inning ;

If m_inning is public, it could be assigned any valid int value. But what if
you meant m_inning to hold only 1 thru 9?
The following property would enforce that business rule.

public int Inning()
{
set
{
if (value < 1 || value > 9) throw new InvalidArgumentException();
m_inning = value;
}
}

kevin aubuchon
"Bobby" <bo***********@epselindo.com> wrote in message
news:uT*************@TK2MSFTNGP12.phx.gbl...
Hi all...

What is the different between using property and variable?
Their all functionality is same (for store a value). I get this issue when I want find the best way to passing a parameter between form (Windows
application).
And, what is the best way to passing value to other form?
Thanks all..

Nov 16 '05 #2
Think of properties as an extension of a field (or variable). But
properties don't denote storage space like a field but have accessors that
allow you to execute code when their values or written or read. You can
also add modifiers to properties such as virtual, abstract, or override that
apply to the accessors of the property.

One other thing to remember is that the variable name used in a public field
in a class is the name that will appear in Intellisense. Personally...
seeing something like m_AccountNumber in intellisense drives me nuts.

--
C Addison Ritchie, MCSD.NET
Ritch Consulting, Inc.

"Bobby" <bo***********@epselindo.com> wrote in message
news:uT*************@TK2MSFTNGP12.phx.gbl...
Hi all...

What is the different between using property and variable?
Their all functionality is same (for store a value). I get this issue when I want find the best way to passing a parameter between form (Windows
application).
And, what is the best way to passing value to other form?
Thanks all..

Nov 16 '05 #3

"C Addison Ritchie" <cr******@ritchconsulting.com> wrote in message
news:uI**************@TK2MSFTNGP12.phx.gbl...

One other thing to remember is that the variable name used in a public field in a class is the name that will appear in Intellisense. Personally...
seeing something like m_AccountNumber in intellisense drives me nuts.


And would violate current Microsoft guidelines, for whatever that's worth.
Nov 16 '05 #4

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

Similar topics

4
by: D Witherspoon | last post by:
I have a Structure I have created and am using it as a Public Property of a class. Here is the property. ------------------------------------------------------ Dim _MyID As SInteger Public...
5
by: Alex Stevens | last post by:
Hi All, In the absence of any predefined standards, I was wondering how to name and implement my enum in a class. My dilema is: When I (for example) have an integer property in my class...
3
by: Alex Stevens | last post by:
Hi. I have a class and it exposes a property, which accepts a parameter collection object. I want the class to use the parameter object and update it. However I don't want to use a copy of the...
62
by: djake | last post by:
Someone can explain me why to use property get and property set to access a value in a class, insted of access the value directly? What's the usefulness of property statements in VB.NET? Thanks
9
by: Stefan De Schepper | last post by:
Should I use: Private m_Name As String Public Property Name() As String Get Return m_Name End Get Set(ByVal Value As String) m_Name = Value
2
by: miben | last post by:
I need to set a variable returned by a readonly property in a class by another class. So the only way to set that value is from a specific class and function. Public Sub Main Dim setter As New...
37
by: Joergen Bech | last post by:
(Slightly religious question): Suppose I have the following class: ---snip--- Public Class MyClass Private _MyVariable As Integer Public Property MyVariable() As Integer Get
6
by: David Hearn | last post by:
I have a property in a user control that I am setting: Private strPageName as String Public Property PageName() as String Get Return strPageName End Get Set(byVal Value as String)...
10
by: Franky | last post by:
I think I misread a post and understood that if I do: System.Windows.Forms.Cursor.Current = Cursors.WaitCursor there is no need to reset the cursor to Default. So I made all the reset...
11
by: dgk | last post by:
If I have a class with a public variable, isn't this the same as a private variable with a property? ie, isn't this: Public Class MyTest Public MyVar as String End Class the same as this: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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
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...
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
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...

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.