Information Technology Reference
In-Depth Information
Example of Properties and Databases
Another example in which a property is not associated with a field is when the property is asso-
ciated with a value in a database. In that case, the get accessor makes the appropriate database
calls to get the value from the database. The set accessor makes the corresponding calls to the
database to set the new value in the database.
For example, the following property is associated with a particular value in some database.
The code assumes that there are two other methods in the class to handle the details of the
database transactions:
￿ SetValueInDatabase takes an integer parameter and uses it to set a particular field in a
record in some database.
￿ GetValueFromDatabase retrieves and returns a particular integer field value from a partic-
ular record in some database.
int MyDatabaseValue
{
set // Sets integer value in the database
{
SetValueInDatabase(value);
}
get // Gets integer value from the database
{
return GetValueFromDatabase();
}
}
Search WWH ::




Custom Search