Fields and attributes in C #

Source: Internet
Author: User

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! ");

}
}
}
}
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.