- A property is a member of a class, used to write the data in the data field and read the data from the data field of a class
- A property can never store the data, just used to transfer the data
- Properties are members that provide a flexible mechanism to read, write, or compute the implementation or verification code
- To perform read and write operations, property can contain two assessors / methods
- Properties provide the convenience of public data members without the risks that come with unprotected, uncontrolled, and unverified access to an object’s data
- This is accomplished through accessors : special methods that assign and retrieve values from the underlying data member
Accessors within the property
Accessors
enable data to be accessed easily while still providing the safety and
flexibility of methods
1)
Set Accessor 2) Get Accessor
1)set Accessor
Set
Accessor is used to write the data into the data field
This
will contain a default and fixed variable named as “value”
Whenever
we call the property to write the data, any data we supply will come and store
in value variable by default
Syntax :-
set
{
Data Filed Name=value;
}
2)get Accessor
Get
Accessor is used to read the data from the data field, using this accessor we
can’t write the data
Syntax :-
get
{
return Data Field Name;
}
No comments:
Post a Comment