locked
Difference between Property and Member Variable RRS feed

  • Question

  • Hi,

     Difference between Property and Member Variable

     

    Regards

    Janet

    Friday, May 28, 2010 3:36 AM

Answers

  • Point of difference

    Variable

    Property

    Declaration

    Single declaration statement

    Series of statements in a code block

    Implementation

    Single storage location

    Executable code (property procedures)

    Storage

    Directly associated with variable's value

    Typically has internal storage not available outside the property's containing class or module

    Property's value might or might not exist as a stored element

    Executable code

    None

    Must have at least one procedure

    Read and write access

    Read/write or read-only

    Read/write, read-only, or write-only

    Custom actions (in addition to accepting or returning value)

    Not possible

    Can be performed as part of setting or retrieving property value

     source: http://msdn.microsoft.com/en-us/library/sk5e8eth(VS.80).aspx


    Manish Sati
    • Marked as answer by Harry Zhu Wednesday, June 2, 2010 7:50 AM
    Friday, May 28, 2010 8:54 AM
  •  

    Hi,

    In property we can put some validations or can do any operation on the field before set or get of value, but in case of member variable it is not there.

    Thanks

    • Marked as answer by Harry Zhu Wednesday, June 2, 2010 7:50 AM
    Friday, May 28, 2010 8:17 AM
  • Hi Janets,

    In property we can validate the input values before assigning to variable.

    For example,

        The property named Age can be check, the given value is between 0 and 120.

    if not we can throw an exception.

    we can also create Readonly and Writeonly property.

    Thank You


    Enjoy Each and every scond in your life
    • Proposed as answer by Suba lakshmi Friday, May 28, 2010 12:46 PM
    • Marked as answer by Harry Zhu Wednesday, June 2, 2010 7:50 AM
    Friday, May 28, 2010 8:28 AM
    • Marked as answer by Harry Zhu Wednesday, June 2, 2010 7:50 AM
    Friday, May 28, 2010 9:13 AM

All replies

  •  

    Hi,

    In property we can put some validations or can do any operation on the field before set or get of value, but in case of member variable it is not there.

    Thanks

    • Marked as answer by Harry Zhu Wednesday, June 2, 2010 7:50 AM
    Friday, May 28, 2010 8:17 AM
  • Hi Janets,

    In property we can validate the input values before assigning to variable.

    For example,

        The property named Age can be check, the given value is between 0 and 120.

    if not we can throw an exception.

    we can also create Readonly and Writeonly property.

    Thank You


    Enjoy Each and every scond in your life
    • Proposed as answer by Suba lakshmi Friday, May 28, 2010 12:46 PM
    • Marked as answer by Harry Zhu Wednesday, June 2, 2010 7:50 AM
    Friday, May 28, 2010 8:28 AM
  • Point of difference

    Variable

    Property

    Declaration

    Single declaration statement

    Series of statements in a code block

    Implementation

    Single storage location

    Executable code (property procedures)

    Storage

    Directly associated with variable's value

    Typically has internal storage not available outside the property's containing class or module

    Property's value might or might not exist as a stored element

    Executable code

    None

    Must have at least one procedure

    Read and write access

    Read/write or read-only

    Read/write, read-only, or write-only

    Custom actions (in addition to accepting or returning value)

    Not possible

    Can be performed as part of setting or retrieving property value

     source: http://msdn.microsoft.com/en-us/library/sk5e8eth(VS.80).aspx


    Manish Sati
    • Marked as answer by Harry Zhu Wednesday, June 2, 2010 7:50 AM
    Friday, May 28, 2010 8:54 AM
    • Marked as answer by Harry Zhu Wednesday, June 2, 2010 7:50 AM
    Friday, May 28, 2010 9:13 AM