Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual Basic
 Property Procedures vs. Fields

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Visual Basic Language Concepts 
Property Procedures vs. Fields 

Properties and fields both store and retrieve information in an object. Their similarity can make it difficult to determine which is a better programming choice in a given case.

Use property procedures when:

  • You need to control when and how a value is set or retrieved.

  • The property has a well-defined set of values that need to be validated.

  • Setting the value causes some perceptible change in the object's state, such as an IsVisible property.

  • Setting the property causes changes to other internal variables or to the values of other properties.

  • A set of steps must be performed before the property can be set or retrieved.

Use fields when:

  • The value is of a self-validating type. For example, an error or automatic data conversion occurs if a value other than True or False is assigned to a Boolean variable.

  • Any value in the range supported by the data type is valid. This is true of many properties of type Single or Double.

  • The property is a String data type, and there is no constraint on the size or value of the string.

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker