1. Properties: Improve security
(1) Composition: Access modifier return Type property name
{
get{statement Collection;} Read properties, which can only be retrieved when they exist alone
set{statement Collection;} Write attributes, which can only be assigned when they exist alone
}
(2) static property: Access modifier static return type property name
{
get{statement Collection;} Read properties, which can only be retrieved when they exist alone
set{statement Collection;} Write attributes, which can only be assigned when they exist alone
}
Static properties can only access static members of a class and apply to an entire class rather than to another instance
(3) Adding a checksum code during a retrieval or assignment can delay instantiation
public static Double
{
Get
{
return age;
}
Set
{
Validating data
if (value< 0)
{
Console.WriteLine ("Age cannot be negative");
Return
}
Else
{
Age= value;
}
}
}
Public double Balance
{
Get
{
if (_balance < 0)
Console.WriteLine ("No Available Balance");
return _balance;
}
}
C # Fundamentals (iii), properties