Using system;
Using system. Collections. Generic;
Using system. text;
Namespace example11_1 {
Class program {
Static void main (string [] ARGs ){
Farmer farmer = new farmer ();
Farmer. Name = "Liu ";
Farmer. Age = 226;
Console. writeline (farmer. Age );
Console. Readline ();
}
}
Class farmer {
/// <Summary>
/// No-parameter constructor of the farmer class
/// </Summary>
Public farmer (){
}
/// <Summary>
/// Constructor of the farmer class
/// </Summary>
/// <Param name = "m_name"> farmer name parameter </param>
Public farmer (string m_name ){
Name = m_name;
}
/// <Summary>
/// Name field
/// </Summary>
String name = string. empty;
/// <Summary>
/// Max Field
/// </Summary>
Const int max = 150;
/// <Summary>
/// Min Field
/// </Summary>
Const int min = 0;
/// <Summary>
/// Age Field
/// </Summary>
Int age = 0;
/// <Summary>
/// Max attributes
/// </Summary>
Public int max {
Get {
Return Max;
}
}
//
// min attribute
///
Public int min
{
get
{< br> return min;
}< BR >}
/// <Summary>
/// Name attribute
/// </Summary>
Public string name {
Set {
Name = value;
}
}
/// <Summary>
/// Age attributes
/// </Summary>
Public int age {
Get {
Return age;
}
Set {
If (value> min) & (value <max ))
{
Age = value;
}
Else
{
Try
{
Exception EX = new exception ("the value is out of the preset range! ");
Throw (Ex );
}
Catch
{
Console. writeline ("the value is out of the preset range! ");
}
}
}
}
}
}